blob: 186230d65398fd9d1554b6b954b4f538ab2903f6 [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
Brad Ebinger4df7e242021-02-17 23:23:21 +000024import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080026import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070027import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
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;
Rambo Wang0f050d82021-02-12 11:43:36 -080055import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080068import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebingerd4c5bde2021-02-12 06:18:28 +0000113import android.telephony.ims.RcsContactUceCapability;
Brad Ebinger774ba362019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800162import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800163import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700164import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700165import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800167import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800168import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800169import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700170import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800171import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700172import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800173import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700174import com.android.internal.telephony.imsphone.ImsPhone;
175import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800176import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900177import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800179import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700182import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800183import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000186import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800187import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700188import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700189import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800190import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700191import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800193import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700194import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700195import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800196import com.android.services.telephony.TelecomAccountRegistry;
197import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800198import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800199
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700200import java.io.FileDescriptor;
201import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800204import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800206import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100207import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700209import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800210import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800211import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800212import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800213import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214
215/**
216 * Implementation of the ITelephony interface.
217 */
Santos Cordon117fee72014-05-16 17:56:12 -0700218public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 private static final String LOG_TAG = "PhoneInterfaceManager";
220 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
221 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223
224 // Message codes used with mMainThreadHandler
225 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700226 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
227 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228 private static final int CMD_OPEN_CHANNEL = 9;
229 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
230 private static final int CMD_CLOSE_CHANNEL = 11;
231 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800232 private static final int CMD_NV_READ_ITEM = 13;
233 private static final int EVENT_NV_READ_ITEM_DONE = 14;
234 private static final int CMD_NV_WRITE_ITEM = 15;
235 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
236 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
237 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700238 private static final int CMD_RESET_MODEM_CONFIG = 19;
239 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800240 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
241 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800242 private static final int CMD_SEND_ENVELOPE = 25;
243 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000244 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
245 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700246 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
247 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
248 private static final int CMD_EXCHANGE_SIM_IO = 31;
249 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800250 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
251 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700252 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
253 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700254 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
255 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700256 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
257 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
258 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
259 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700260 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
261 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
262 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
263 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700264 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800265 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
266 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000267 private static final int CMD_SWITCH_SLOTS = 50;
268 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700269 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
270 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
271 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
272 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
273 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
274 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
275 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
276 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700277 private static final int CMD_GET_ALL_CELL_INFO = 60;
278 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
279 private static final int CMD_GET_CELL_LOCATION = 62;
280 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700281 private static final int CMD_MODEM_REBOOT = 64;
282 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700283 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
284 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800285 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
286 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700287 private static final int CMD_GET_MODEM_STATUS = 70;
288 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700289 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
290 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700291 private static final int CMD_ERASE_MODEM_CONFIG = 74;
292 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800293 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
294 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
295 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
296 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800297 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
298 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800299 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800300 private static final int CMD_GET_CALL_FORWARDING = 83;
301 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
302 private static final int CMD_SET_CALL_FORWARDING = 85;
303 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
304 private static final int CMD_GET_CALL_WAITING = 87;
305 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
306 private static final int CMD_SET_CALL_WAITING = 89;
307 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700308 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
309 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
310 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
311 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700312 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
313 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800314 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
315 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800316 private static final int CMD_SET_DATA_THROTTLING = 99;
317 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800318 private static final int CMD_SET_SIM_POWER = 101;
319 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800320 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
321 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
322 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
323 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800324 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
325 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000326 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800328 // Parameters of select command.
329 private static final int SELECT_COMMAND = 0xA4;
330 private static final int SELECT_P1 = 0x04;
331 private static final int SELECT_P2 = 0;
332 private static final int SELECT_P3 = 0x10;
333
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 /** The singleton instance. */
335 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800336 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800340 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700341 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private AppOpsManager mAppOps;
343 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800344 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800345 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700346 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800347 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Peter Wangdafb9ac2020-01-15 14:13:38 -0800349 /** User Activity */
350 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
352
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700353 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
354
Derek Tan97ebb422014-09-05 16:55:38 -0700355 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
356 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800357 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800358 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700359
Michelecea4cf22018-12-21 15:00:11 -0800360 // String to store multi SIM allowed
361 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
362
Derek Tan740e1672017-06-27 14:56:27 -0700363 // The AID of ISD-R.
364 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
365
yinxub1bed742017-04-17 11:45:04 -0700366 private NetworkScanRequestTracker mNetworkScanRequestTracker;
367
David Kelly5e06a7f2018-03-12 14:10:59 +0000368 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
369 private static final int MANUFACTURER_CODE_LENGTH = 8;
370
Jack Nudelman24d51a52020-11-24 12:08:04 -0800371 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800372 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800373
Derek Tan89e89d42014-07-08 17:00:10 -0700374 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700375 * Experiment flag to enable erase modem config on reset network, default value is false
376 */
377 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
378 "reset_network_erase_modem_config_enabled";
379
Rambo Wang0f050d82021-02-12 11:43:36 -0800380 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
381
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700382 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700383 * A request object to use for transmitting data to an ICC.
384 */
385 private static final class IccAPDUArgument {
386 public int channel, cla, command, p1, p2, p3;
387 public String data;
388
389 public IccAPDUArgument(int channel, int cla, int command,
390 int p1, int p2, int p3, String data) {
391 this.channel = channel;
392 this.cla = cla;
393 this.command = command;
394 this.p1 = p1;
395 this.p2 = p2;
396 this.p3 = p3;
397 this.data = data;
398 }
399 }
400
401 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700402 * A request object to use for transmitting data to an ICC.
403 */
404 private static final class ManualNetworkSelectionArgument {
405 public OperatorInfo operatorInfo;
406 public boolean persistSelection;
407
408 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
409 this.operatorInfo = operatorInfo;
410 this.persistSelection = persistSelection;
411 }
412 }
413
414 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
416 * request after sending. The main thread will notify the request when it is complete.
417 */
418 private static final class MainThreadRequest {
419 /** The argument to use for the request */
420 public Object argument;
421 /** The result of the request that is run on the main thread */
422 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800423 // The subscriber id that this request applies to. Defaults to
424 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
425 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426
Nathan Harold92bed182018-10-12 18:16:49 -0700427 // In cases where subId is unavailable, the caller needs to specify the phone.
428 public Phone phone;
429
vagdeviaf9a5b92018-08-15 16:01:53 -0700430 public WorkSource workSource;
431
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 public MainThreadRequest(Object argument) {
433 this.argument = argument;
434 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800435
Nathan Harold92bed182018-10-12 18:16:49 -0700436 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
437 this.argument = argument;
438 if (phone != null) {
439 this.phone = phone;
440 }
441 this.workSource = workSource;
442 }
443
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800445 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800446 if (subId != null) {
447 this.subId = subId;
448 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700449 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 }
452
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800453 private static final class IncomingThirdPartyCallArgs {
454 public final ComponentName component;
455 public final String callId;
456 public final String callerDisplayName;
457
458 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
459 String callerDisplayName) {
460 this.component = component;
461 this.callId = callId;
462 this.callerDisplayName = callerDisplayName;
463 }
464 }
465
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 /**
467 * A handler that processes messages on the main thread in the phone process. Since many
468 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
469 * inbound binder threads to the main thread in the phone process. The Binder thread
470 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
471 * on, which will be notified when the operation completes and will contain the result of the
472 * request.
473 *
474 * <p>If a MainThreadRequest object is provided in the msg.obj field,
475 * note that request.result must be set to something non-null for the calling thread to
476 * unblock.
477 */
478 private final class MainThreadHandler extends Handler {
479 @Override
480 public void handleMessage(Message msg) {
481 MainThreadRequest request;
482 Message onCompleted;
483 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800486 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487
488 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 case CMD_HANDLE_USSD_REQUEST: {
490 request = (MainThreadRequest) msg.obj;
491 final Phone phone = getPhoneFromRequest(request);
492 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
493 String ussdRequest = ussdObject.first;
494 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700495
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 if (!isUssdApiAllowed(request.subId)) {
497 // Carrier does not support use of this API, return failure.
498 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
499 UssdResponse response = new UssdResponse(ussdRequest, null);
500 Bundle returnData = new Bundle();
501 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
502 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 request.result = true;
505 notifyRequester(request);
506 return;
507 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700508
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 try {
510 request.result = phone != null
511 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
512 } catch (CallStateException cse) {
513 request.result = false;
514 }
515 // Wake up the requesting thread
516 notifyRequester(request);
517 break;
pkanwar32d516d2016-10-14 19:37:38 -0700518 }
519
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700522 final Phone phone = getPhoneFromRequest(request);
523 request.result = phone != null ?
524 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
525 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700532 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 if (uiccCard == null) {
536 loge("iccTransmitApduLogicalChannel: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
541 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 iccArgument.channel, iccArgument.cla, iccArgument.command,
544 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 break;
548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
556 if (ar.result == null) {
557 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800558 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800560 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 } else {
562 loge("iccTransmitApduLogicalChannel: Unknown exception");
563 }
564 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
569 request = (MainThreadRequest) msg.obj;
570 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800571 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 if (uiccCard == null) {
573 loge("iccTransmitApduBasicChannel: No UICC");
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 } else {
577 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
578 request);
579 uiccCard.iccTransmitApduBasicChannel(
580 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
581 iccArgument.p3, iccArgument.data, onCompleted);
582 }
583 break;
584
585 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
586 ar = (AsyncResult) msg.obj;
587 request = (MainThreadRequest) ar.userObj;
588 if (ar.exception == null && ar.result != null) {
589 request.result = ar.result;
590 } else {
591 request.result = new IccIoResult(0x6F, 0, (byte[])null);
592 if (ar.result == null) {
593 loge("iccTransmitApduBasicChannel: Empty response");
594 } else if (ar.exception instanceof CommandException) {
595 loge("iccTransmitApduBasicChannel: CommandException: " +
596 ar.exception);
597 } else {
598 loge("iccTransmitApduBasicChannel: Unknown exception");
599 }
600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 break;
603
604 case CMD_EXCHANGE_SIM_IO:
605 request = (MainThreadRequest) msg.obj;
606 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800607 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 if (uiccCard == null) {
609 loge("iccExchangeSimIO: No UICC");
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 } else {
613 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
614 request);
615 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
616 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
617 iccArgument.data, onCompleted);
618 }
619 break;
620
621 case EVENT_EXCHANGE_SIM_IO_DONE:
622 ar = (AsyncResult) msg.obj;
623 request = (MainThreadRequest) ar.userObj;
624 if (ar.exception == null && ar.result != null) {
625 request.result = ar.result;
626 } else {
627 request.result = new IccIoResult(0x6f, 0, (byte[])null);
628 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 break;
631
Derek Tan4d5e5c12014-02-04 11:54:58 -0800632 case CMD_SEND_ENVELOPE:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("sendEnvelopeWithStatus: No UICC");
637 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 } else {
640 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
641 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
642 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 break;
644
645 case EVENT_SEND_ENVELOPE_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
652 if (ar.result == null) {
653 loge("sendEnvelopeWithStatus: Empty response");
654 } else if (ar.exception instanceof CommandException) {
655 loge("sendEnvelopeWithStatus: CommandException: " +
656 ar.exception);
657 } else {
658 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
659 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800662 break;
663
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 case CMD_OPEN_CHANNEL:
665 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800666 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800667 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 if (uiccCard == null) {
669 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800670 request.result = new IccOpenLogicalChannelResponse(-1,
671 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 } else {
674 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800675 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
676 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
680 case EVENT_OPEN_CHANNEL_DONE:
681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 int[] result = (int[]) ar.result;
686 int channelId = result[0];
687 byte[] selectResponse = null;
688 if (result.length > 1) {
689 selectResponse = new byte[result.length - 1];
690 for (int i = 1; i < result.length; ++i) {
691 selectResponse[i - 1] = (byte) result[i];
692 }
693 }
694 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 if (ar.result == null) {
698 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 if (ar.exception != null) {
701 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
702 }
703
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700705 if (ar.exception instanceof CommandException) {
706 CommandException.Error error =
707 ((CommandException) (ar.exception)).getCommandError();
708 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700710 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700711 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 }
713 }
714 openChannelResp = new IccOpenLogicalChannelResponse(
715 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700717 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
721 case CMD_CLOSE_CHANNEL:
722 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800723 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 if (uiccCard == null) {
725 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900726 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 } else {
729 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
730 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
731 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 break;
733
734 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800735 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
736 break;
737
738 case CMD_NV_READ_ITEM:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800741 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
742 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800743 break;
744
745 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 ar = (AsyncResult) msg.obj;
747 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800748 if (ar.exception == null && ar.result != null) {
749 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800751 request.result = "";
752 if (ar.result == null) {
753 loge("nvReadItem: Empty response");
754 } else if (ar.exception instanceof CommandException) {
755 loge("nvReadItem: CommandException: " +
756 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800758 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
760 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 break;
763
Jake Hambye994d462014-02-03 13:10:13 -0800764 case CMD_NV_WRITE_ITEM:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
767 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800768 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700769 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800770 break;
771
772 case EVENT_NV_WRITE_ITEM_DONE:
773 handleNullReturnEvent(msg, "nvWriteItem");
774 break;
775
776 case CMD_NV_WRITE_CDMA_PRL:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800779 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800780 break;
781
782 case EVENT_NV_WRITE_CDMA_PRL_DONE:
783 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
784 break;
785
chen xu6dac5ab2018-10-26 17:39:23 -0700786 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800787 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700788 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800789 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800790 break;
791
chen xu6dac5ab2018-10-26 17:39:23 -0700792 case EVENT_RESET_MODEM_CONFIG_DONE:
793 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700796 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
799 request);
800 Phone phone = getPhoneFromRequest(request);
801 if (phone != null) {
802 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
803 } else {
804 loge("isNRDualConnectivityEnabled: No phone object");
805 request.result = false;
806 notifyRequester(request);
807 }
808 break;
809 }
810
811 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
812 ar = (AsyncResult) msg.obj;
813 request = (MainThreadRequest) ar.userObj;
814 if (ar.exception == null && ar.result != null) {
815 request.result = ar.result;
816 } else {
817 // request.result must be set to something non-null
818 // for the calling thread to unblock
819 if (request.result != null) {
820 request.result = ar.result;
821 } else {
822 request.result = false;
823 }
824 if (ar.result == null) {
825 loge("isNRDualConnectivityEnabled: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("isNRDualConnectivityEnabled: CommandException: "
828 + ar.exception);
829 } else {
830 loge("isNRDualConnectivityEnabled: Unknown exception");
831 }
832 }
833 notifyRequester(request);
834 break;
835
836 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
839 Phone phone = getPhoneFromRequest(request);
840 if (phone != null) {
841 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
842 request.workSource);
843 } else {
844 loge("enableNrDualConnectivity: No phone object");
845 request.result =
846 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
847 notifyRequester(request);
848 }
849 break;
850 }
851
852 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null) {
856 request.result =
857 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
858 } else {
859 request.result =
860 TelephonyManager
861 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
862 if (ar.exception instanceof CommandException) {
863 CommandException.Error error =
864 ((CommandException) (ar.exception)).getCommandError();
865 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
866 request.result =
867 TelephonyManager
868 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000869 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
870 request.result =
871 TelephonyManager
872 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700873 }
874 loge("enableNrDualConnectivity" + ": CommandException: "
875 + ar.exception);
876 } else {
877 loge("enableNrDualConnectivity" + ": Unknown exception");
878 }
879 }
880 notifyRequester(request);
881 break;
882 }
883
SongFerngWang9e060372020-12-21 16:41:52 +0800884 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800885 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800886 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
887 request);
888 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 break;
890
SongFerngWang9e060372020-12-21 16:41:52 +0800891 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result; // Integer
896 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530897 // request.result must be set to something non-null
898 // for the calling thread to unblock
899 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800901 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800903 loge("getAllowedNetworkTypesBitmask: CommandException: "
904 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800906 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 }
908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700909 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 break;
911
SongFerngWang9e060372020-12-21 16:41:52 +0800912 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800913 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800914 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
915 request);
916 Pair<Integer, Long> reasonWithNetworkTypes =
917 (Pair<Integer, Long>) request.argument;
918 getPhoneFromRequest(request).setAllowedNetworkTypes(
919 reasonWithNetworkTypes.first,
920 reasonWithNetworkTypes.second,
921 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 break;
923
SongFerngWang9e060372020-12-21 16:41:52 +0800924 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
925 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 break;
927
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000928 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
929 request = (MainThreadRequest)msg.obj;
930 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800931 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000932 break;
933
934 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
935 ar = (AsyncResult)msg.obj;
936 request = (MainThreadRequest)ar.userObj;
937 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000939 break;
940
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800941 case CMD_SET_VOICEMAIL_NUMBER:
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
944 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800945 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
946 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800947 break;
948
949 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
950 handleNullReturnEvent(msg, "setVoicemailNumber");
951 break;
952
Stuart Scott54788802015-03-30 13:18:01 -0700953 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
956 request);
957 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
958 break;
959
960 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
961 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
962 break;
963
Shishir Agrawal302c8692015-06-19 13:49:39 -0700964 case CMD_PERFORM_NETWORK_SCAN:
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
967 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
968 break;
969
Hall Liua1acea22020-09-18 19:04:59 -0700970 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700973 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
974 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
975 request.argument;
976 int callForwardingReason = args.first;
977 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800978 break;
Hall Liua1acea22020-09-18 19:04:59 -0700979 }
980 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700983 TelephonyManager.CallForwardingInfoCallback callback =
984 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
985 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800986 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700987 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800988 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
989 for (CallForwardInfo callForwardInfo : callForwardInfos) {
990 // Service Class is a bit mask per 3gpp 27.007. Search for
991 // any service for voice call.
992 if ((callForwardInfo.serviceClass
993 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700994 callForwardingInfo = new CallForwardingInfo(true,
995 callForwardInfo.reason,
996 callForwardInfo.number,
997 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800998 break;
999 }
1000 }
1001 // Didn't find a call forward info for voice call.
1002 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001003 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1004 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001005 }
Hall Liua1acea22020-09-18 19:04:59 -07001006 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001007 } else {
1008 if (ar.result == null) {
1009 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1010 }
1011 if (ar.exception != null) {
1012 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1013 }
Hall Liuae527aa2020-09-29 17:10:18 -07001014 int errorCode = TelephonyManager
1015 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001016 if (ar.exception instanceof CommandException) {
1017 CommandException.Error error =
1018 ((CommandException) (ar.exception)).getCommandError();
1019 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001020 errorCode = TelephonyManager
1021 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001022 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001023 errorCode = TelephonyManager
1024 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001025 }
1026 }
Hall Liua1acea22020-09-18 19:04:59 -07001027 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001028 }
sqian80370722020-01-29 15:02:51 -08001029 break;
Hall Liua1acea22020-09-18 19:04:59 -07001030 }
sqian80370722020-01-29 15:02:51 -08001031
Hall Liua1acea22020-09-18 19:04:59 -07001032 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001033 request = (MainThreadRequest) msg.obj;
1034 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001035 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001036 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001037 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1038 request.argument).first;
1039 request.phone.setCallForwardingOption(
1040 callForwardingInfoToSet.isEnabled()
1041 ? CommandsInterface.CF_ACTION_ENABLE
1042 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001043 callForwardingInfoToSet.getReason(),
1044 callForwardingInfoToSet.getNumber(),
1045 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1046 break;
Hall Liua1acea22020-09-18 19:04:59 -07001047 }
sqian80370722020-01-29 15:02:51 -08001048
Hall Liua1acea22020-09-18 19:04:59 -07001049 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001050 ar = (AsyncResult) msg.obj;
1051 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001052 Consumer<Integer> callback =
1053 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1054 request.argument).second;
1055 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001056 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001057 int errorCode = TelephonyManager.CallForwardingInfoCallback
1058 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001059 if (ar.exception instanceof CommandException) {
1060 CommandException.Error error =
1061 ((CommandException) (ar.exception)).getCommandError();
1062 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001063 errorCode = TelephonyManager.CallForwardingInfoCallback
1064 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001065 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001066 errorCode = TelephonyManager.CallForwardingInfoCallback
1067 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001068 }
1069 }
1070 callback.accept(errorCode);
1071 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001072 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001073 }
sqian80370722020-01-29 15:02:51 -08001074 break;
Hall Liua1acea22020-09-18 19:04:59 -07001075 }
sqian80370722020-01-29 15:02:51 -08001076
Hall Liua1acea22020-09-18 19:04:59 -07001077 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1080 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1081 break;
Hall Liua1acea22020-09-18 19:04:59 -07001082 }
sqian80370722020-01-29 15:02:51 -08001083
Hall Liua1acea22020-09-18 19:04:59 -07001084 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001087 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001088 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1089 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001090 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001091 // Service Class is a bit mask per 3gpp 27.007.
1092 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001093 if (callForwardResults.length > 1
1094 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001095 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001096 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001097 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1098 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001099 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001100 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001101 }
1102 } else {
1103 if (ar.result == null) {
1104 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1105 }
1106 if (ar.exception != null) {
1107 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1108 }
1109 if (ar.exception instanceof CommandException) {
1110 CommandException.Error error =
1111 ((CommandException) (ar.exception)).getCommandError();
1112 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1113 callForwardingStatus =
1114 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1115 }
1116 }
1117 }
Hall Liua1acea22020-09-18 19:04:59 -07001118 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001119 break;
Hall Liua1acea22020-09-18 19:04:59 -07001120 }
sqian80370722020-01-29 15:02:51 -08001121
Hall Liua1acea22020-09-18 19:04:59 -07001122 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001125 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1126 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001127 break;
Hall Liua1acea22020-09-18 19:04:59 -07001128 }
sqian80370722020-01-29 15:02:51 -08001129
Hall Liua1acea22020-09-18 19:04:59 -07001130 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001133 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1134 Consumer<Integer> callback =
1135 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1136 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001137 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001138 if (ar.exception instanceof CommandException) {
1139 CommandException.Error error =
1140 ((CommandException) (ar.exception)).getCommandError();
1141 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1142 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1143 } else {
1144 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1145 }
1146 } else {
1147 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1148 }
1149 } else {
1150 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1151 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001152 }
sqian80370722020-01-29 15:02:51 -08001153 break;
Hall Liua1acea22020-09-18 19:04:59 -07001154 }
sqian80370722020-01-29 15:02:51 -08001155
Shishir Agrawal302c8692015-06-19 13:49:39 -07001156 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1157 ar = (AsyncResult) msg.obj;
1158 request = (MainThreadRequest) ar.userObj;
1159 CellNetworkScanResult cellScanResult;
1160 if (ar.exception == null && ar.result != null) {
1161 cellScanResult = new CellNetworkScanResult(
1162 CellNetworkScanResult.STATUS_SUCCESS,
1163 (List<OperatorInfo>) ar.result);
1164 } else {
1165 if (ar.result == null) {
1166 loge("getCellNetworkScanResults: Empty response");
1167 }
1168 if (ar.exception != null) {
1169 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1170 }
1171 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1172 if (ar.exception instanceof CommandException) {
1173 CommandException.Error error =
1174 ((CommandException) (ar.exception)).getCommandError();
1175 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1176 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1177 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1178 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1179 }
1180 }
1181 cellScanResult = new CellNetworkScanResult(errorCode, null);
1182 }
1183 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001184 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001185 break;
1186
1187 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1188 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001189 ManualNetworkSelectionArgument selArg =
1190 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001191 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1192 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001193 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1194 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 break;
1196
1197 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
1200 if (ar.exception == null) {
1201 request.result = true;
1202 } else {
1203 request.result = false;
1204 loge("setNetworkSelectionModeManual " + ar.exception);
1205 }
1206 notifyRequester(request);
1207 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 break;
1209
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001210 case CMD_GET_MODEM_ACTIVITY_INFO:
1211 request = (MainThreadRequest) msg.obj;
1212 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001213 if (defaultPhone != null) {
1214 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001215 } else {
1216 ResultReceiver result = (ResultReceiver) request.argument;
1217 Bundle bundle = new Bundle();
1218 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1219 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1220 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001221 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 break;
1223
1224 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001227 ResultReceiver result = (ResultReceiver) request.argument;
1228
1229 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001230 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001231 // Update the last modem activity info and the result of the request.
1232 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1233 if (isModemActivityInfoValid(info)) {
1234 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1235 int[] txTimeMs = info.getTransmitTimeMillis();
1236 int[] lastModemTxTimeMs = mLastModemActivityInfo
1237 .getTransmitTimeMillis();
1238 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1239 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1240 }
1241 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1242 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1243 + mLastModemActivityInfo.getSleepTimeMillis());
1244 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1245 + mLastModemActivityInfo.getIdleTimeMillis());
1246 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1247 mLastModemActivityInfo.setReceiveTimeMillis(
1248 info.getReceiveTimeMillis()
1249 + mLastModemActivityInfo.getReceiveTimeMillis());
1250 }
1251 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1252 mLastModemActivityInfo.getSleepTimeMillis(),
1253 mLastModemActivityInfo.getIdleTimeMillis(),
1254 mLastModemActivityInfo.getTransmitTimeMillis(),
1255 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001256 } else {
1257 if (ar.result == null) {
1258 loge("queryModemActivityInfo: Empty response");
1259 } else if (ar.exception instanceof CommandException) {
1260 loge("queryModemActivityInfo: CommandException: " +
1261 ar.exception);
1262 } else {
1263 loge("queryModemActivityInfo: Unknown exception");
1264 }
1265 }
sqian1a1be542020-03-05 11:37:28 -08001266 Bundle bundle = new Bundle();
1267 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1268 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001269 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001270 break;
1271
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 case CMD_SET_ALLOWED_CARRIERS:
1273 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001274 CarrierRestrictionRules argument =
1275 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001277 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001278 break;
1279
1280 case EVENT_SET_ALLOWED_CARRIERS_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 {
Michele Berionne482f8202018-11-27 18:57:59 -08001286 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1287 if (ar.exception instanceof CommandException) {
1288 loge("setAllowedCarriers: CommandException: " + ar.exception);
1289 CommandException.Error error =
1290 ((CommandException) (ar.exception)).getCommandError();
1291 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1292 request.result =
1293 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1294 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 } else {
1296 loge("setAllowedCarriers: Unknown exception");
1297 }
1298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001299 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 break;
1301
1302 case CMD_GET_ALLOWED_CARRIERS:
1303 request = (MainThreadRequest) msg.obj;
1304 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001305 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 break;
1307
1308 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null && ar.result != null) {
1312 request.result = ar.result;
1313 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001314 request.result = new IllegalStateException(
1315 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001316 if (ar.result == null) {
1317 loge("getAllowedCarriers: Empty response");
1318 } else if (ar.exception instanceof CommandException) {
1319 loge("getAllowedCarriers: CommandException: " +
1320 ar.exception);
1321 } else {
1322 loge("getAllowedCarriers: Unknown exception");
1323 }
1324 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001325 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001326 break;
1327
Nathan Haroldb3014052017-01-25 15:57:32 -08001328 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 if (ar.exception == null && ar.result != null) {
1332 request.result = ar.result;
1333 } else {
1334 request.result = new IllegalArgumentException(
1335 "Failed to retrieve Forbidden Plmns");
1336 if (ar.result == null) {
1337 loge("getForbiddenPlmns: Empty response");
1338 } else {
1339 loge("getForbiddenPlmns: Unknown exception");
1340 }
1341 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001342 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001343 break;
1344
1345 case CMD_GET_FORBIDDEN_PLMNS:
1346 request = (MainThreadRequest) msg.obj;
1347 uiccCard = getUiccCardFromRequest(request);
1348 if (uiccCard == null) {
1349 loge("getForbiddenPlmns() UiccCard is null");
1350 request.result = new IllegalArgumentException(
1351 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001353 break;
1354 }
1355 Integer appType = (Integer) request.argument;
1356 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1357 if (uiccApp == null) {
1358 loge("getForbiddenPlmns() no app with specified type -- "
1359 + appType);
1360 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001361 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001362 break;
1363 } else {
1364 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1365 + " specified type -- " + appType);
1366 }
1367 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1368 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1369 onCompleted);
1370 break;
1371
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001372 case CMD_SWITCH_SLOTS:
1373 request = (MainThreadRequest) msg.obj;
1374 int[] physicalSlots = (int[]) request.argument;
1375 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1376 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1377 break;
1378
1379 case EVENT_SWITCH_SLOTS_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001383 notifyRequester(request);
1384 break;
1385 case CMD_GET_NETWORK_SELECTION_MODE:
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1388 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1389 break;
1390
1391 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 if (ar.exception != null) {
1395 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1396 } else {
1397 int mode = ((int[]) ar.result)[0];
1398 if (mode == 0) {
1399 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1400 } else {
1401 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1402 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001403 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001404 notifyRequester(request);
1405 break;
1406 case CMD_GET_CDMA_ROAMING_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1409 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1410 break;
1411 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 if (ar.exception != null) {
1415 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1416 } else {
1417 request.result = ((int[]) ar.result)[0];
1418 }
1419 notifyRequester(request);
1420 break;
1421 case CMD_SET_CDMA_ROAMING_MODE:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1424 int mode = (int) request.argument;
1425 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1426 break;
1427 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 request.result = ar.exception == null;
1431 notifyRequester(request);
1432 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001433 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1436 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1437 break;
1438 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception != null) {
1442 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1443 } else {
1444 request.result = ((int[]) ar.result)[0];
1445 }
1446 notifyRequester(request);
1447 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001448 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1451 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001452 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1453 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 break;
1455 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 request.result = ar.exception == null;
1459 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001460 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 case CMD_GET_ALL_CELL_INFO:
1462 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001464 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 case EVENT_GET_ALL_CELL_INFO_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001469 // If a timeout occurs, the response will be null
1470 request.result = (ar.exception == null && ar.result != null)
1471 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001472 synchronized (request) {
1473 request.notifyAll();
1474 }
1475 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 case CMD_REQUEST_CELL_INFO_UPDATE:
1477 request = (MainThreadRequest) msg.obj;
1478 request.phone.requestCellInfoUpdate(request.workSource,
1479 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1480 break;
1481 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
1484 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1485 try {
1486 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001487 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001488 cb.onError(
1489 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1490 ar.exception.getClass().getName(),
1491 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001492 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001494 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001495 } else {
1496 // use the result as returned
1497 cb.onCellInfo((List<CellInfo>) ar.result);
1498 }
1499 } catch (RemoteException re) {
1500 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1501 }
1502 break;
Sarah Chincc055732020-11-18 13:39:35 -08001503 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 request = (MainThreadRequest) msg.obj;
1505 WorkSource ws = (WorkSource) request.argument;
1506 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001507 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 break;
Sarah Chincc055732020-11-18 13:39:35 -08001509 }
1510 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception == null) {
1514 request.result = ar.result;
1515 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001516 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001517 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001518 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001519 }
1520
1521 synchronized (request) {
1522 request.notifyAll();
1523 }
1524 break;
Sarah Chincc055732020-11-18 13:39:35 -08001525 }
chen xu6dac5ab2018-10-26 17:39:23 -07001526 case CMD_MODEM_REBOOT:
1527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001529 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001530 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001531 case EVENT_CMD_MODEM_REBOOT_DONE:
1532 handleNullReturnEvent(msg, "rebootModem");
1533 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001534 case CMD_REQUEST_ENABLE_MODEM:
1535 request = (MainThreadRequest) msg.obj;
1536 boolean enable = (boolean) request.argument;
1537 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001538 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001539 PhoneConfigurationManager.getInstance()
1540 .enablePhone(request.phone, enable, onCompleted);
1541 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001542 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001546 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001547 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001548 if ((boolean) request.result) {
1549 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1550 updateModemStateMetrics();
1551 } else {
1552 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1553 + ar.exception);
1554 }
1555 notifyRequester(request);
1556 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001557 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001558 case CMD_GET_MODEM_STATUS:
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1561 PhoneConfigurationManager.getInstance()
1562 .getPhoneStatusFromModem(request.phone, onCompleted);
1563 break;
1564 case EVENT_GET_MODEM_STATUS_DONE:
1565 ar = (AsyncResult) msg.obj;
1566 request = (MainThreadRequest) ar.userObj;
1567 int id = request.phone.getPhoneId();
1568 if (ar.exception == null && ar.result != null) {
1569 request.result = ar.result;
1570 //update the cache as modem status has changed
1571 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1572 (boolean) request.result);
1573 } else {
1574 // Return true if modem status cannot be retrieved. For most cases,
1575 // modem status is on. And for older version modems, GET_MODEM_STATUS
1576 // and disable modem are not supported. Modem is always on.
1577 // TODO: this should be fixed in R to support a third
1578 // status UNKNOWN b/131631629
1579 request.result = true;
1580 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1581 + ar.exception);
1582 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001583 notifyRequester(request);
1584 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001585 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1588 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1589 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1590 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1591 break;
1592 }
1593 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1597 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1598 args.second.accept(ar.exception == null);
1599 notifyRequester(request);
1600 break;
1601 }
Sarah Chincc055732020-11-18 13:39:35 -08001602 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1603 request = (MainThreadRequest) msg.obj;
1604 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1605 Phone phone = getPhoneFromRequest(request);
1606 if (phone != null) {
1607 phone.getSystemSelectionChannels(onCompleted);
1608 } else {
1609 loge("getSystemSelectionChannels: No phone object");
1610 request.result = new ArrayList<RadioAccessSpecifier>();
1611 notifyRequester(request);
1612 }
1613 break;
1614 }
1615 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception == null && ar.result != null) {
1619 request.result = ar.result;
1620 } else {
1621 request.result = new IllegalArgumentException(
1622 "Failed to retrieve system selection channels");
1623 if (ar.result == null) {
1624 loge("getSystemSelectionChannels: Empty response");
1625 } else {
1626 loge("getSystemSelectionChannels: Unknown exception");
1627 }
1628 }
1629 notifyRequester(request);
1630 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001631 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception == null && ar.result != null) {
1635 request.result = ar.result;
1636 } else {
1637 request.result = -1;
1638 loge("Failed to set Forbidden Plmns");
1639 if (ar.result == null) {
1640 loge("setForbidenPlmns: Empty response");
1641 } else if (ar.exception != null) {
1642 loge("setForbiddenPlmns: Exception: " + ar.exception);
1643 request.result = -1;
1644 } else {
1645 loge("setForbiddenPlmns: Unknown exception");
1646 }
1647 }
1648 notifyRequester(request);
1649 break;
1650 case CMD_SET_FORBIDDEN_PLMNS:
1651 request = (MainThreadRequest) msg.obj;
1652 uiccCard = getUiccCardFromRequest(request);
1653 if (uiccCard == null) {
1654 loge("setForbiddenPlmns: UiccCard is null");
1655 request.result = -1;
1656 notifyRequester(request);
1657 break;
1658 }
1659 Pair<Integer, List<String>> setFplmnsArgs =
1660 (Pair<Integer, List<String>>) request.argument;
1661 appType = setFplmnsArgs.first;
1662 List<String> fplmns = setFplmnsArgs.second;
1663 uiccApp = uiccCard.getApplicationByType(appType);
1664 if (uiccApp == null) {
1665 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1666 request.result = -1;
1667 loge("Failed to get UICC App");
1668 notifyRequester(request);
1669 } else {
1670 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1671 ((SIMRecords) uiccApp.getIccRecords())
1672 .setForbiddenPlmns(onCompleted, fplmns);
1673 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001674 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001675 case CMD_ERASE_MODEM_CONFIG:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1678 defaultPhone.eraseModemConfig(onCompleted);
1679 break;
1680 case EVENT_ERASE_MODEM_CONFIG_DONE:
1681 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001682 break;
zoey chenf95ca592019-12-30 16:11:23 +08001683
1684 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1685 request = (MainThreadRequest) msg.obj;
1686 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1687 Pair<String, String> changed = (Pair<String, String>) request.argument;
1688 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1689 changed.first, changed.second, onCompleted);
1690 break;
1691 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1692 ar = (AsyncResult) msg.obj;
1693 request = (MainThreadRequest) ar.userObj;
1694 if (ar.exception == null) {
1695 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001696 // If the operation is successful, update the PIN storage
1697 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1698 int phoneId = getPhoneFromRequest(request).getPhoneId();
1699 UiccController.getInstance().getPinStorage()
1700 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001701 } else {
1702 request.result = msg.arg1;
1703 }
1704 notifyRequester(request);
1705 break;
1706
Michele Berionned9fbae52020-11-13 02:36:59 +00001707 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1710 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1711 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1712 enabled.first, enabled.second, onCompleted);
1713 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001714 }
zoey chenf95ca592019-12-30 16:11:23 +08001715 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 if (ar.exception == null) {
1719 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001720 // If the operation is successful, update the PIN storage
1721 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1722 int phoneId = getPhoneFromRequest(request).getPhoneId();
1723 if (enabled.first) {
1724 UiccController.getInstance().getPinStorage()
1725 .storePin(enabled.second, phoneId);
1726 } else {
1727 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1728 }
zoey chenf95ca592019-12-30 16:11:23 +08001729 } else {
1730 request.result = msg.arg1;
1731 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001732
1733
zoey chenf95ca592019-12-30 16:11:23 +08001734 notifyRequester(request);
1735 break;
1736
Peter Wangdafb9ac2020-01-15 14:13:38 -08001737 case MSG_NOTIFY_USER_ACTIVITY:
1738 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001739 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001740 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1741 getDefaultPhone().getContext().sendBroadcastAsUser(
1742 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1743 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001744
1745 case CMD_SET_DATA_THROTTLING: {
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1748 DataThrottlingRequest dataThrottlingRequest =
1749 (DataThrottlingRequest) request.argument;
1750 Phone phone = getPhoneFromRequest(request);
1751 if (phone != null) {
1752 phone.setDataThrottling(onCompleted,
1753 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1754 dataThrottlingRequest.getCompletionDurationMillis());
1755 } else {
1756 loge("setDataThrottling: No phone object");
1757 request.result =
1758 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1759 notifyRequester(request);
1760 }
1761
1762 break;
1763 }
1764 case EVENT_SET_DATA_THROTTLING_DONE:
1765 ar = (AsyncResult) msg.obj;
1766 request = (MainThreadRequest) ar.userObj;
1767
1768 if (ar.exception == null) {
1769 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1770 } else if (ar.exception instanceof CommandException) {
1771 loge("setDataThrottling: CommandException: " + ar.exception);
1772 CommandException.Error error =
1773 ((CommandException) (ar.exception)).getCommandError();
1774
1775 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1776 request.result = TelephonyManager
1777 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1778 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1779 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001780 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1781 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001782 } else {
1783 request.result =
1784 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1785 }
1786 } else {
1787 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1788 }
1789 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1790 notifyRequester(request);
1791 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001792
1793 case CMD_SET_SIM_POWER: {
1794 request = (MainThreadRequest) msg.obj;
1795 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1796 request = (MainThreadRequest) msg.obj;
1797 int stateToSet =
1798 ((Pair<Integer, IIntegerConsumer>)
1799 request.argument).first;
1800 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1801 break;
1802 }
1803 case EVENT_SET_SIM_POWER_DONE: {
1804 ar = (AsyncResult) msg.obj;
1805 request = (MainThreadRequest) ar.userObj;
1806 IIntegerConsumer callback =
1807 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1808 if (ar.exception != null) {
1809 loge("setSimPower exception: " + ar.exception);
1810 int errorCode = TelephonyManager.CallForwardingInfoCallback
1811 .RESULT_ERROR_UNKNOWN;
1812 if (ar.exception instanceof CommandException) {
1813 CommandException.Error error =
1814 ((CommandException) (ar.exception)).getCommandError();
1815 if (error == CommandException.Error.SIM_ERR) {
1816 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1817 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1818 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1819 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1820 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1821 } else {
1822 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1823 }
1824 }
1825 try {
1826 callback.accept(errorCode);
1827 } catch (RemoteException e) {
1828 // Ignore if the remote process is no longer available to call back.
1829 Log.w(LOG_TAG, "setSimPower: callback not available.");
1830 }
1831 } else {
1832 try {
1833 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1834 } catch (RemoteException e) {
1835 // Ignore if the remote process is no longer available to call back.
1836 Log.w(LOG_TAG, "setSimPower: callback not available.");
1837 }
1838 }
1839 break;
1840 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001841 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1842 request = (MainThreadRequest) msg.obj;
1843
1844 final Phone phone = getPhoneFromRequest(request);
1845 if (phone == null || phone.getServiceStateTracker() == null) {
1846 request.result = new IllegalStateException("Phone or SST is null");
1847 notifyRequester(request);
1848 break;
1849 }
1850
1851 Pair<Integer, SignalStrengthUpdateRequest> pair =
1852 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1853 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1854 request);
1855 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1856 request.subId, pair.first /*callingUid*/,
1857 pair.second /*request*/, onCompleted);
1858 break;
1859 }
1860 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1861 ar = (AsyncResult) msg.obj;
1862 request = (MainThreadRequest) ar.userObj;
1863 // request.result will be the exception of ar if present, true otherwise.
1864 // Be cautious not to leave result null which will wait() forever
1865 request.result = ar.exception != null ? ar.exception : true;
1866 notifyRequester(request);
1867 break;
1868 }
1869 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1870 request = (MainThreadRequest) msg.obj;
1871
1872 Phone phone = getPhoneFromRequest(request);
1873 if (phone == null || phone.getServiceStateTracker() == null) {
1874 request.result = new IllegalStateException("Phone or SST is null");
1875 notifyRequester(request);
1876 break;
1877 }
1878
1879 Pair<Integer, SignalStrengthUpdateRequest> pair =
1880 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1881 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1882 request);
1883 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1884 request.subId, pair.first /*callingUid*/,
1885 pair.second /*request*/, onCompleted);
1886 break;
1887 }
1888 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 request.result = ar.exception != null ? ar.exception : true;
1892 notifyRequester(request);
1893 break;
1894 }
Jordan Liud5366d92020-11-24 14:50:34 -08001895
Michele Berionned9fbae52020-11-13 02:36:59 +00001896 case CMD_PREPARE_UNATTENDED_REBOOT:
1897 request = (MainThreadRequest) msg.obj;
1898 request.result =
1899 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1900 notifyRequester(request);
1901 break;
1902
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 default:
1904 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1905 break;
1906 }
1907 }
Jake Hambye994d462014-02-03 13:10:13 -08001908
Pengquan Menga1bb6272018-09-06 09:59:22 -07001909 private void notifyRequester(MainThreadRequest request) {
1910 synchronized (request) {
1911 request.notifyAll();
1912 }
1913 }
1914
Jake Hambye994d462014-02-03 13:10:13 -08001915 private void handleNullReturnEvent(Message msg, String command) {
1916 AsyncResult ar = (AsyncResult) msg.obj;
1917 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1918 if (ar.exception == null) {
1919 request.result = true;
1920 } else {
1921 request.result = false;
1922 if (ar.exception instanceof CommandException) {
1923 loge(command + ": CommandException: " + ar.exception);
1924 } else {
1925 loge(command + ": Unknown exception");
1926 }
1927 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001928 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 }
1931
1932 /**
1933 * Posts the specified command to be executed on the main thread,
1934 * waits for the request to complete, and returns the result.
1935 * @see #sendRequestAsync
1936 */
1937 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001938 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1939 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001940 }
1941
1942 /**
1943 * Posts the specified command to be executed on the main thread,
1944 * waits for the request to complete, and returns the result.
1945 * @see #sendRequestAsync
1946 */
1947 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1948 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001949 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001950 }
1951
1952 /**
1953 * Posts the specified command to be executed on the main thread,
1954 * waits for the request to complete, and returns the result.
1955 * @see #sendRequestAsync
1956 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001957 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001958 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1959 }
1960
1961 /**
1962 * Posts the specified command to be executed on the main thread,
1963 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1964 * if not timeout or null otherwise.
1965 * @see #sendRequestAsync
1966 */
1967 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1968 long timeoutInMs) {
1969 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001970 }
1971
1972 /**
1973 * Posts the specified command to be executed on the main thread,
1974 * waits for the request to complete, and returns the result.
1975 * @see #sendRequestAsync
1976 */
Nathan Harold92bed182018-10-12 18:16:49 -07001977 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001978 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001979 }
1980
1981 /**
1982 * Posts the specified command to be executed on the main thread,
1983 * waits for the request to complete, and returns the result.
1984 * @see #sendRequestAsync
1985 */
1986 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001987 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1988 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001989 }
1990
1991 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001992 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1993 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1994 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001995 * @see #sendRequestAsync
1996 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001997 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1998 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2000 throw new RuntimeException("This method will deadlock if called from the main thread.");
2001 }
2002
Nathan Harold92bed182018-10-12 18:16:49 -07002003 MainThreadRequest request = null;
2004 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2005 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2006 } else if (phone != null) {
2007 request = new MainThreadRequest(argument, phone, workSource);
2008 } else {
2009 request = new MainThreadRequest(argument, subId, workSource);
2010 }
2011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 Message msg = mMainThreadHandler.obtainMessage(command, request);
2013 msg.sendToTarget();
2014
Rambo Wang0f050d82021-02-12 11:43:36 -08002015
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002017 if (timeoutInMs >= 0) {
2018 // Wait for at least timeoutInMs before returning null request result
2019 long now = SystemClock.elapsedRealtime();
2020 long deadline = now + timeoutInMs;
2021 while (request == null && now < deadline) {
2022 try {
2023 request.wait(deadline - now);
2024 } catch (InterruptedException e) {
2025 // Do nothing, go back and check if request is completed or timeout
2026 } finally {
2027 now = SystemClock.elapsedRealtime();
2028 }
2029 }
2030 } else {
2031 // Wait for the request to complete
2032 while (request.result == null) {
2033 try {
2034 request.wait();
2035 } catch (InterruptedException e) {
2036 // Do nothing, go back and wait until the request is complete
2037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 }
2039 }
2040 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002041 if (request.result == null) {
2042 Log.wtf(LOG_TAG,
2043 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 return request.result;
2046 }
2047
2048 /**
2049 * Asynchronous ("fire and forget") version of sendRequest():
2050 * Posts the specified command to be executed on the main thread, and
2051 * returns immediately.
2052 * @see #sendRequest
2053 */
2054 private void sendRequestAsync(int command) {
2055 mMainThreadHandler.sendEmptyMessage(command);
2056 }
2057
2058 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002059 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002060 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002061 */
2062 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002063 sendRequestAsync(command, argument, null, null);
2064 }
2065
2066 /**
2067 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2068 * @see {@link #sendRequest(int,Object)}
2069 */
2070 private void sendRequestAsync(
2071 int command, Object argument, Phone phone, WorkSource workSource) {
2072 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002073 Message msg = mMainThreadHandler.obtainMessage(command, request);
2074 msg.sendToTarget();
2075 }
2076
2077 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 * Initialize the singleton PhoneInterfaceManager instance.
2079 * This is only done once, at startup, from PhoneApp.onCreate().
2080 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002081 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 synchronized (PhoneInterfaceManager.class) {
2083 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002084 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 } else {
2086 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2087 }
2088 return sInstance;
2089 }
2090 }
2091
2092 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002093 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002096 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002097 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2099 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002100 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002101 mTelephonySharedPreferences =
2102 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002103 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002104 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002105 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002106 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002107
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 publish();
2109 }
2110
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002111 private Phone getDefaultPhone() {
2112 Phone thePhone = getPhone(getDefaultSubscription());
2113 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2114 }
2115
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 private void publish() {
2117 if (DBG) log("publish: " + this);
2118
Peter Wangc035ce42020-01-08 21:00:22 -08002119 TelephonyFrameworkInitializer
2120 .getTelephonyServiceManager()
2121 .getTelephonyServiceRegisterer()
2122 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 }
2124
Stuart Scott584921c2015-01-15 17:10:34 -08002125 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002126 if (request.phone != null) {
2127 return request.phone;
2128 } else {
2129 return getPhoneFromSubId(request.subId);
2130 }
2131 }
2132
2133 private Phone getPhoneFromSubId(int subId) {
2134 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2135 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002136 }
2137
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002138 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2139 Phone phone = getPhoneFromRequest(request);
2140 return phone == null ? null :
2141 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2142 }
2143
Wink Saville36469e72014-06-11 15:17:00 -07002144 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002145 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002146 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002149 private void sendEraseModemConfig(Phone phone) {
2150 if (phone != null) {
2151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2152 mApp, phone.getSubId(), "eraseModemConfig");
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2156 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2157 } finally {
2158 Binder.restoreCallingIdentity(identity);
2159 }
2160 }
2161 }
2162
Peter Wang050bb052020-01-13 23:33:09 -08002163 private boolean isImsAvailableOnDevice() {
2164 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2165 if (pm == null) {
2166 // For some reason package manger is not available.. This will fail internally anyway,
2167 // so do not throw error and allow.
2168 return true;
2169 }
2170 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2171 }
2172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002174 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002175 }
2176
Wink Savilleb564aae2014-10-23 10:18:09 -07002177 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 if (DBG) log("dial: " + number);
2179 // No permission check needed here: This is just a wrapper around the
2180 // ACTION_DIAL intent, which is available to any app since it puts up
2181 // the UI before it does anything.
2182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 String url = createTelUrl(number);
2186 if (url == null) {
2187 return;
2188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 // PENDING: should we just silently fail if phone is offhook or ringing?
2191 PhoneConstants.State state = mCM.getState(subId);
2192 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2193 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2194 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2195 mApp.startActivity(intent);
2196 }
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200 }
2201
2202 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002203 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002204 }
2205
Wink Savilleb564aae2014-10-23 10:18:09 -07002206 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 if (DBG) log("call: " + number);
2208
2209 // This is just a wrapper around the ACTION_CALL intent, but we still
2210 // need to do a permission check since we're calling startActivity()
2211 // from the context of the phone app.
2212 enforceCallPermission();
2213
Jordan Liu1617b712019-07-10 15:06:26 -07002214 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 != AppOpsManager.MODE_ALLOWED) {
2216 return;
2217 }
2218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 String url = createTelUrl(number);
2222 if (url == null) {
2223 return;
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 boolean isValid = false;
2227 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2228 if (slist != null) {
2229 for (SubscriptionInfo subInfoRecord : slist) {
2230 if (subInfoRecord.getSubscriptionId() == subId) {
2231 isValid = true;
2232 break;
2233 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002234 }
Wink Saville08874612014-08-31 19:19:58 -07002235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 if (!isValid) {
2237 return;
2238 }
Wink Saville08874612014-08-31 19:19:58 -07002239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2241 intent.putExtra(SUBSCRIPTION_KEY, subId);
2242 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2243 mApp.startActivity(intent);
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
2246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
Wink Savilleb564aae2014-10-23 10:18:09 -07002249 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002250 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002251 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2252 }
2253
Wink Savilleb564aae2014-10-23 10:18:09 -07002254 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002255 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002256 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2257 }
2258
Wink Savilleb564aae2014-10-23 10:18:09 -07002259 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002264 Phone phone = getPhone(subId);
2265 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266 checkSimPin.start();
2267 return checkSimPin.unlockSim(null, pin);
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
Wink Savilleb564aae2014-10-23 10:18:09 -07002273 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002278 Phone phone = getPhone(subId);
2279 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280 checkSimPuk.start();
2281 return checkSimPuk.unlockSim(puk, pin);
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
2287 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002288 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 * a synchronous one.
2290 */
2291 private static class UnlockSim extends Thread {
2292
2293 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002294 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295
2296 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002297 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2298 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299
2300 // For replies from SimCard interface
2301 private Handler mHandler;
2302
2303 // For async handler to identify request type
2304 private static final int SUPPLY_PIN_COMPLETE = 100;
2305
Michele Berionned9fbae52020-11-13 02:36:59 +00002306 UnlockSim(int phoneId, IccCard simCard) {
2307 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 mSimCard = simCard;
2309 }
2310
2311 @Override
2312 public void run() {
2313 Looper.prepare();
2314 synchronized (UnlockSim.this) {
2315 mHandler = new Handler() {
2316 @Override
2317 public void handleMessage(Message msg) {
2318 AsyncResult ar = (AsyncResult) msg.obj;
2319 switch (msg.what) {
2320 case SUPPLY_PIN_COMPLETE:
2321 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2322 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002323 mRetryCount = msg.arg1;
2324 if (ar.exception != null) {
2325 if (ar.exception instanceof CommandException &&
2326 ((CommandException)(ar.exception)).getCommandError()
2327 == CommandException.Error.PASSWORD_INCORRECT) {
2328 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002329 } //When UiccCardApp dispose,handle message and return exception
2330 else if (ar.exception instanceof CommandException &&
2331 ((CommandException) (ar.exception)).getCommandError()
2332 == CommandException.Error.ABORTED) {
2333 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002334 } else {
2335 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2336 }
2337 } else {
2338 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mDone = true;
2341 UnlockSim.this.notifyAll();
2342 }
2343 break;
2344 }
2345 }
2346 };
2347 UnlockSim.this.notifyAll();
2348 }
2349 Looper.loop();
2350 }
2351
2352 /*
2353 * Use PIN or PUK to unlock SIM card
2354 *
2355 * If PUK is null, unlock SIM card with PIN
2356 *
2357 * If PUK is not null, unlock SIM card with PUK and set PIN code
2358 */
Wink Saville9de0f752013-10-22 19:04:03 -07002359 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360
2361 while (mHandler == null) {
2362 try {
2363 wait();
2364 } catch (InterruptedException e) {
2365 Thread.currentThread().interrupt();
2366 }
2367 }
2368 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2369
2370 if (puk == null) {
2371 mSimCard.supplyPin(pin, callback);
2372 } else {
2373 mSimCard.supplyPuk(puk, pin, callback);
2374 }
2375
2376 while (!mDone) {
2377 try {
2378 Log.d(LOG_TAG, "wait for done");
2379 wait();
2380 } catch (InterruptedException e) {
2381 // Restore the interrupted status
2382 Thread.currentThread().interrupt();
2383 }
2384 }
2385 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002386 int[] resultArray = new int[2];
2387 resultArray[0] = mResult;
2388 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002389
2390 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2391 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2392 }
2393
Wink Saville9de0f752013-10-22 19:04:03 -07002394 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 }
2396 }
2397
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002398 /**
2399 * This method has been removed due to privacy and stability concerns.
2400 */
2401 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002403 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2404 return;
Wink Saville36469e72014-06-11 15:17:00 -07002405 }
2406
Nathan Harold1f889d82020-06-04 17:05:26 -07002407 @Override
2408 public void updateServiceLocationWithPackageName(String callingPackage) {
2409 mApp.getSystemService(AppOpsManager.class)
2410 .checkPackage(Binder.getCallingUid(), callingPackage);
2411
Nathan Haroldf096d982020-11-18 17:18:06 -08002412 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002413 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2414 // Callers targeting S have no business invoking this method.
2415 return;
2416 }
2417
2418 LocationAccessPolicy.LocationPermissionResult locationResult =
2419 LocationAccessPolicy.checkLocationPermission(mApp,
2420 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2421 .setCallingPackage(callingPackage)
2422 .setCallingFeatureId(null)
2423 .setCallingPid(Binder.getCallingPid())
2424 .setCallingUid(Binder.getCallingUid())
2425 .setMethod("updateServiceLocation")
2426 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2427 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2428 .build());
2429 // Apps that lack location permission have no business calling this method;
2430 // however, because no permission was declared in the public API, denials must
2431 // all be "soft".
2432 switch (locationResult) {
2433 case DENIED_HARD: /* fall through */
2434 case DENIED_SOFT:
2435 return;
2436 }
2437
2438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439 final long identity = Binder.clearCallingIdentity();
2440 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002441 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002443 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 }
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002450 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002451 @Override
2452 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002453 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002454 }
2455
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002456
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002457 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002458 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2459 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2460 callingFeatureId);
2461 }
2462
2463 @Deprecated
2464 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002466 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2467 }
2468
2469 @Override
2470 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2471 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002473 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002474 return false;
2475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 return isRadioOnForSubscriber(subId);
2480 } finally {
2481 Binder.restoreCallingIdentity(identity);
2482 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002483 }
2484
2485 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 final Phone phone = getPhone(subId);
2489 if (phone != null) {
2490 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2491 } else {
2492 return false;
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002500 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
Wink Saville36469e72014-06-11 15:17:00 -07002502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
2510 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
2516
2517 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002518 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
Wink Savilleb564aae2014-10-23 10:18:09 -07002521 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 final Phone phone = getPhone(subId);
2527 if (phone == null) {
2528 return false;
2529 }
2530 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2531 toggleRadioOnOffForSubscriber(subId);
2532 }
2533 return true;
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
Wink Saville36469e72014-06-11 15:17:00 -07002538
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002539 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002540 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002541 /*
2542 * If any of the Radios are available, it will need to be
2543 * shutdown. So return true if any Radio is available.
2544 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2548 Phone phone = PhoneFactory.getPhone(i);
2549 if (phone != null && phone.isRadioAvailable()) return true;
2550 }
2551 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2552 return false;
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002555 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002556 }
2557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002559 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 enforceModifyPermission();
2561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2565 logv("Shutting down Phone " + i);
2566 shutdownRadioUsingPhoneId(i);
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002570 }
2571 }
2572
2573 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002574 Phone phone = PhoneFactory.getPhone(phoneId);
2575 if (phone != null && phone.isRadioAvailable()) {
2576 phone.shutdownRadio();
2577 }
2578 }
2579
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2586 if (defaultPhone != null) {
2587 defaultPhone.setRadioPower(turnOn);
2588 return true;
2589 } else {
2590 loge("There's no default phone.");
2591 return false;
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002595 }
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
Wink Savilleb564aae2014-10-23 10:18:09 -07002598 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 phone.setRadioPower(turnOn);
2606 return true;
2607 } else {
2608 return false;
2609 }
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 }
2614
Wink Saville36469e72014-06-11 15:17:00 -07002615 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 public boolean enableDataConnectivity() {
2618 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619
2620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 int subId = mSubscriptionController.getDefaultDataSubId();
2623 final Phone phone = getPhone(subId);
2624 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002625 phone.getDataEnabledSettings().setDataEnabled(
2626 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 return true;
2628 } else {
2629 return false;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
Wink Saville36469e72014-06-11 15:17:00 -07002636 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 public boolean disableDataConnectivity() {
2639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 int subId = mSubscriptionController.getDefaultDataSubId();
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002646 phone.getDataEnabledSettings().setDataEnabled(
2647 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 return true;
2649 } else {
2650 return false;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002658 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002663 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 } else {
2665 return false;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002673 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002674 }
2675
pkanwarae03a6b2016-11-06 20:37:09 -08002676 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 enforceCallPermission();
2678
2679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2682 return;
2683 }
2684 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2685 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
pkanwar32d516d2016-10-14 19:37:38 -07002689 };
2690
Wink Savilleb564aae2014-10-23 10:18:09 -07002691 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2697 return false;
2698 }
2699 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002706 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002709 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 Phone phone = PhoneFactory.getPhone(slotIndex);
2713 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2714 PhoneConstantConversions.convertCallState(phone.getState());
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
2717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
Sanket Padawe356d7632015-06-22 14:03:32 -07002720 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002721 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002722 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2723 }
2724
2725 @Override
2726 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002729 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 if (phone != null) {
2731 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2732 } else {
2733 return PhoneConstantConversions.convertDataState(
2734 PhoneConstants.DataState.DISCONNECTED);
2735 }
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002742 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002743 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2744 }
2745
2746 @Override
2747 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 final long identity = Binder.clearCallingIdentity();
2749 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002750 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 if (phone != null) {
2752 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2753 } else {
2754 return TelephonyManager.DATA_ACTIVITY_NONE;
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 }
2760
2761 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002762 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002763 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002764 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002765
2766 LocationAccessPolicy.LocationPermissionResult locationResult =
2767 LocationAccessPolicy.checkLocationPermission(mApp,
2768 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2769 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002770 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002771 .setCallingPid(Binder.getCallingPid())
2772 .setCallingUid(Binder.getCallingUid())
2773 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002774 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002775 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2776 .build());
2777 switch (locationResult) {
2778 case DENIED_HARD:
2779 throw new SecurityException("Not allowed to access cell location");
2780 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002781 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2782 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002789 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002790 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 } finally {
2792 Binder.restoreCallingIdentity(identity);
2793 }
Svetoslav64fad262015-04-14 14:35:21 -07002794 }
2795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 @Override
Jack Yu01425032020-02-22 19:38:58 -08002797 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002798 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2799 // registered cell info, so return a NULL country instead.
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002802 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2803 // Get default phone in this case.
2804 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2805 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002806 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002808 if (phone == null) return "";
2809 ServiceStateTracker sst = phone.getServiceStateTracker();
2810 if (sst == null) return "";
2811 LocaleTracker lt = sst.getLocaleTracker();
2812 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002813 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002817 }
2818
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002819 /**
2820 * This method was removed due to potential issues caused by performing partial
2821 * updates of service state, and lack of a credible use case.
2822 *
2823 * This has the ability to break the telephony implementation by disabling notification of
2824 * changes in device connectivity. DO NOT USE THIS!
2825 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 public void enableLocationUpdates() {
2828 mApp.enforceCallingOrSelfPermission(
2829 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002832 /**
2833 * This method was removed due to potential issues caused by performing partial
2834 * updates of service state, and lack of a credible use case.
2835 *
2836 * This has the ability to break the telephony implementation by disabling notification of
2837 * changes in device connectivity. DO NOT USE THIS!
2838 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 @Override
2840 public void disableLocationUpdates() {
2841 mApp.enforceCallingOrSelfPermission(
2842 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 }
2844
2845 @Override
2846 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002847 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2848 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002849 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002850 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2851 throw new SecurityException(
2852 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2853 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002854
Jordan Liu1617b712019-07-10 15:06:26 -07002855 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2857 return null;
2858 }
Svetoslav64fad262015-04-14 14:35:21 -07002859
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002860 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002862 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002863 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864
Nathan Haroldf180aac2018-06-01 18:43:55 -07002865 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2866 for (CellInfo ci : info) {
2867 if (ci instanceof CellInfoGsm) {
2868 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2869 } else if (ci instanceof CellInfoWcdma) {
2870 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002873 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 }
2875
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002876 private List<CellInfo> getCachedCellInfo() {
2877 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2878 for (Phone phone : PhoneFactory.getPhones()) {
2879 List<CellInfo> info = phone.getAllCellInfo();
2880 if (info != null) cellInfos.addAll(info);
2881 }
2882 return cellInfos;
2883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884
2885 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002886 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002887 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002888 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002889
2890 LocationAccessPolicy.LocationPermissionResult locationResult =
2891 LocationAccessPolicy.checkLocationPermission(mApp,
2892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2893 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002895 .setCallingPid(Binder.getCallingPid())
2896 .setCallingUid(Binder.getCallingUid())
2897 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002899 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2900 .build());
2901 switch (locationResult) {
2902 case DENIED_HARD:
2903 throw new SecurityException("Not allowed to access cell info");
2904 case DENIED_SOFT:
2905 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
Nathan Haroldf096d982020-11-18 17:18:06 -08002908 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002909 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2910 return getCachedCellInfo();
2911 }
2912
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002913 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2918 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002919 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002920 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 if (info != null) cellInfos.addAll(info);
2922 }
2923 return cellInfos;
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
2927 }
2928
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002930 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2931 String callingFeatureId) {
2932 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2933 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002934 }
2935
2936 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002937 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2938 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002939 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002940 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002941 }
2942
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002943 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2944 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002945 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002946 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002947
2948 LocationAccessPolicy.LocationPermissionResult locationResult =
2949 LocationAccessPolicy.checkLocationPermission(mApp,
2950 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2951 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002952 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002953 .setCallingPid(Binder.getCallingPid())
2954 .setCallingUid(Binder.getCallingUid())
2955 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002956 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2957 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002958 .build());
2959 switch (locationResult) {
2960 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002961 if (TelephonyPermissions
2962 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002963 // Safetynet logging for b/154934934
2964 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2965 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 throw new SecurityException("Not allowed to access cell info");
2967 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002968 if (TelephonyPermissions
2969 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002970 // Safetynet logging for b/154934934
2971 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2972 }
Nathan Harold5320c422019-05-09 10:26:08 -07002973 try {
2974 cb.onCellInfo(new ArrayList<CellInfo>());
2975 } catch (RemoteException re) {
2976 // Drop without consequences
2977 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002978 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002979 }
2980
Nathan Harolda939a962019-05-09 10:13:47 -07002981
2982 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002983 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2984
2985 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2986 }
2987
2988 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002990 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002991 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002999 }
3000
Shishir Agrawala9f32182016-04-12 12:00:16 -07003001 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003002 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003003 Phone phone = PhoneFactory.getPhone(slotIndex);
3004 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003005 return null;
3006 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003007 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003008 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003009 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003010 return null;
3011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 return phone.getImei();
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003019 }
3020
3021 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003022 public String getTypeAllocationCodeForSlot(int slotIndex) {
3023 Phone phone = PhoneFactory.getPhone(slotIndex);
3024 String tac = null;
3025 if (phone != null) {
3026 String imei = phone.getImei();
3027 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3028 }
3029 return tac;
3030 }
3031
3032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003033 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003034 Phone phone = PhoneFactory.getPhone(slotIndex);
3035 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003036 return null;
3037 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003038
Jeff Davidson913390f2018-02-23 17:11:49 -08003039 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003040 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003041 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003042 return null;
3043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 return phone.getMeid();
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
Jack Yu2af8d712017-03-15 17:14:14 -07003051 }
3052
3053 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003054 public String getManufacturerCodeForSlot(int slotIndex) {
3055 Phone phone = PhoneFactory.getPhone(slotIndex);
3056 String manufacturerCode = null;
3057 if (phone != null) {
3058 String meid = phone.getMeid();
3059 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3060 }
3061 return manufacturerCode;
3062 }
3063
3064 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003065 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3066 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003067 Phone phone = PhoneFactory.getPhone(slotIndex);
3068 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003069 return null;
3070 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003071 int subId = phone.getSubId();
3072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003073 mApp, subId, callingPackage, callingFeatureId,
3074 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003075 return null;
3076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 return phone.getDeviceSvn();
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003084 }
3085
fionaxu43304da2017-11-27 22:51:16 -08003086 @Override
3087 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 final Phone phone = getPhone(subId);
3091 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
fionaxu43304da2017-11-27 22:51:16 -08003095 }
3096
3097 @Override
3098 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 final Phone phone = getPhone(subId);
3102 return phone == null ? null : phone.getCarrierName();
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
fionaxu43304da2017-11-27 22:51:16 -08003106 }
3107
calvinpanffe225e2018-11-01 19:43:06 +08003108 @Override
chen xu0026ca62019-03-06 15:28:50 -08003109 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 final Phone phone = getPhone(subId);
3113 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003114 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
3120 @Override
chen xu0026ca62019-03-06 15:28:50 -08003121 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003125 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003126 } finally {
3127 Binder.restoreCallingIdentity(identity);
3128 }
3129 }
3130
chen xu651eec72018-11-11 19:03:44 -08003131 @Override
chen xu864e11c2018-12-06 22:10:03 -08003132 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3133 if (!isSubscriptionMccMnc) {
3134 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3135 }
chen xu651eec72018-11-11 19:03:44 -08003136 final Phone phone = PhoneFactory.getPhone(slotIndex);
3137 if (phone == null) {
3138 return TelephonyManager.UNKNOWN_CARRIER_ID;
3139 }
3140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 //
3149 // Internal helper methods.
3150 //
3151
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003152 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3154 *
3155 * @throws SecurityException if the caller does not have the required permission
3156 */
3157 private void enforceModifyPermission() {
3158 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3159 }
3160
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003161 /**
3162 * Make sure the caller is system.
3163 *
3164 * @throws SecurityException if the caller is not system.
3165 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003166 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003167 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3168 throw new SecurityException("Caller must be system");
3169 }
3170 }
3171
Shuo Qianf2b2df42019-11-13 17:43:31 -08003172 private void enforceActiveEmergencySessionPermission() {
3173 mApp.enforceCallingOrSelfPermission(
3174 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3175 }
3176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 /**
3178 * Make sure the caller has the CALL_PHONE permission.
3179 *
3180 * @throws SecurityException if the caller does not have the required permission
3181 */
3182 private void enforceCallPermission() {
3183 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3184 }
3185
paulhu423b5f22019-08-23 19:17:33 +08003186 private void enforceSettingsPermission() {
3187 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003188 }
3189
Michele Berionned9fbae52020-11-13 02:36:59 +00003190 private void enforceRebootPermission() {
3191 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3192 }
3193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 private String createTelUrl(String number) {
3195 if (TextUtils.isEmpty(number)) {
3196 return null;
3197 }
3198
Jake Hambye994d462014-02-03 13:10:13 -08003199 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
Ihab Awadf9e92732013-12-05 18:02:52 -08003202 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3204 }
3205
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003206 private static void logv(String msg) {
3207 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3208 }
3209
Ihab Awadf9e92732013-12-05 18:02:52 -08003210 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3212 }
3213
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003214 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003216 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003217 }
3218
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003220 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = PhoneFactory.getPhone(slotIndex);
3224 if (phone == null) {
3225 return PhoneConstants.PHONE_TYPE_NONE;
3226 } else {
3227 return phone.getPhoneType();
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 }
3233
3234 /**
3235 * Returns the CDMA ERI icon index to display
3236 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003237 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003238 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3239 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3240 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003241 }
3242
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003244 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003247 mApp, subId, callingPackage, callingFeatureId,
3248 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003249 return -1;
3250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 final Phone phone = getPhone(subId);
3255 if (phone != null) {
3256 return phone.getCdmaEriIconIndex();
3257 } else {
3258 return -1;
3259 }
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
3265 /**
3266 * Returns the CDMA ERI icon mode,
3267 * 0 - ON
3268 * 1 - FLASHING
3269 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003270 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003271 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3272 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3273 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003274 }
3275
Sanket Padawe356d7632015-06-22 14:03:32 -07003276 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003277 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3278 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003280 mApp, subId, callingPackage, callingFeatureId,
3281 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003282 return -1;
3283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 final Phone phone = getPhone(subId);
3288 if (phone != null) {
3289 return phone.getCdmaEriIconMode();
3290 } else {
3291 return -1;
3292 }
3293 } finally {
3294 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
3298 /**
3299 * Returns the CDMA ERI text,
3300 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003301 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003302 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3303 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3304 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003305 }
3306
Sanket Padawe356d7632015-06-22 14:03:32 -07003307 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003308 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3309 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003311 mApp, subId, callingPackage, callingFeatureId,
3312 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003313 return null;
3314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315
3316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 final Phone phone = getPhone(subId);
3319 if (phone != null) {
3320 return phone.getCdmaEriText();
3321 } else {
3322 return null;
3323 }
3324 } finally {
3325 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003327 }
3328
3329 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003330 * Returns the CDMA MDN.
3331 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003332 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003333 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3335 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336
3337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003340 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 return phone.getLine1Number();
3342 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003343 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344 return null;
3345 }
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003348 }
3349 }
3350
3351 /**
3352 * Returns the CDMA MIN.
3353 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003355 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3357 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 final Phone phone = getPhone(subId);
3362 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3363 return phone.getCdmaMin();
3364 } else {
3365 return null;
3366 }
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003369 }
3370 }
3371
Hall Liud892bec2018-11-30 14:51:45 -08003372 @Override
3373 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3374 INumberVerificationCallback callback, String callingPackage) {
3375 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3376 != PERMISSION_GRANTED) {
3377 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3378 }
3379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3380
3381 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3382 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003383 throw new SecurityException("Calling package must be configured in the device config: "
3384 + "calling package: " + callingPackage
3385 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003386 }
3387
3388 if (range == null) {
3389 throw new NullPointerException("Range must be non-null");
3390 }
3391
3392 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003393 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003394
3395 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3396 }
3397
Junda Liuca05d5d2014-08-14 22:36:34 -07003398 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 * Returns true if CDMA provisioning needs to run.
3400 */
3401 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 final long identity = Binder.clearCallingIdentity();
3403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 }
3409
3410 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003411 * Sets the voice mail number of a given subId.
3412 */
3413 @Override
3414 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003415 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3416 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3421 new Pair<String, String>(alphaTag, number), new Integer(subId));
3422 return success;
3423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003426 }
3427
Ta-wei Yen87c49842016-05-13 21:19:52 -07003428 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003429 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003431 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3432 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003433 if (!TextUtils.equals(callingPackage, systemDialer)) {
3434 throw new SecurityException("caller must be system dialer");
3435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3440 if (phoneAccountHandle == null) {
3441 return null;
3442 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003443 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 } finally {
3445 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003446 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003447 }
3448
3449 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003450 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3451 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003454 mApp, subId, callingPackage, callingFeatureId,
3455 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003456 return null;
3457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003459 final long identity = Binder.clearCallingIdentity();
3460 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003465 }
3466
3467 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003468 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3469 VisualVoicemailSmsFilterSettings settings) {
3470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471
3472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003475 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003479 }
3480
3481 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003482 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3483 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003488 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003492 }
3493
3494 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003495 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3496 String callingPackage, int subId) {
3497 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003506 }
3507
3508 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003509 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003515 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003519 }
3520
3521 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003522 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3523 String callingAttributionTag, int subId, String number, int port, String text,
3524 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003526 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003527 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003528 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003529 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3530 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003531 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003532
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003533 /**
fionaxu0152e512016-11-14 13:36:14 -08003534 * Sets the voice activation state of a given subId.
3535 */
3536 @Override
3537 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3539 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 final Phone phone = getPhone(subId);
3544 if (phone != null) {
3545 phone.setVoiceActivationState(activationState);
3546 } else {
3547 loge("setVoiceActivationState fails with invalid subId: " + subId);
3548 }
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003551 }
3552 }
3553
3554 /**
3555 * Sets the data activation state of a given subId.
3556 */
3557 @Override
3558 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3560 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 phone.setDataActivationState(activationState);
3567 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003568 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003572 }
3573 }
3574
3575 /**
3576 * Returns the voice activation state of a given subId.
3577 */
3578 @Override
3579 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
fionaxu0152e512016-11-14 13:36:14 -08003582 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 if (phone != null) {
3586 return phone.getVoiceActivationState();
3587 } else {
3588 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3589 }
3590 } finally {
3591 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003592 }
3593 }
3594
3595 /**
3596 * Returns the data activation state of a given subId.
3597 */
3598 @Override
3599 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601
fionaxu0152e512016-11-14 13:36:14 -08003602 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 if (phone != null) {
3606 return phone.getDataActivationState();
3607 } else {
3608 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3609 }
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003612 }
3613 }
3614
3615 /**
Wink Saville36469e72014-06-11 15:17:00 -07003616 * Returns the unread count of voicemails for a subId
3617 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003618 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003619 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3620 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003622 mApp, subId, callingPackage, callingFeatureId,
3623 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003624 return 0;
3625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 final Phone phone = getPhone(subId);
3629 if (phone != null) {
3630 return phone.getVoiceMessageCount();
3631 } else {
3632 return 0;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
3639 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003640 * returns true, if the device is in a state where both voice and data
3641 * are supported simultaneously. This can change based on location or network condition.
3642 */
3643 @Override
3644 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 final Phone phone = getPhone(subId);
3648 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003652 }
3653
3654 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003655 * Send the dialer code if called from the current default dialer or the caller has
3656 * carrier privilege.
3657 * @param inputCode The dialer code to send
3658 */
3659 @Override
3660 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003663 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3664 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003665 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003666 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003667 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
fionaxu235cc5e2017-03-06 22:25:57 -08003676 }
3677
Pengquan Menga1bb6272018-09-06 09:59:22 -07003678 @Override
3679 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003680 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003681 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003682 mApp, subId, "getNetworkSelectionMode");
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 if (!isActiveSubscription(subId)) {
3686 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3687 }
3688 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003692 }
3693
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003695 public boolean isInEmergencySmsMode() {
3696 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 for (Phone phone : PhoneFactory.getPhones()) {
3700 if (phone.isInEmergencySmsMode()) {
3701 return true;
3702 }
3703 }
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
3707 return false;
3708 }
3709
shilu366312e2019-12-17 09:28:10 -08003710 /**
3711 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3712 * @param subId The subscription to use to check the configuration.
3713 * @param c The callback that will be used to send the result.
3714 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003715 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003716 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3717 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003718 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003719 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003720
Brad Ebinger77b832e2019-10-17 17:03:22 -07003721 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3722 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3723 "IMS not available on device.");
3724 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 final long token = Binder.clearCallingIdentity();
3726 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003730 } catch (ImsException e) {
3731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 } finally {
3733 Binder.restoreCallingIdentity(token);
3734 }
3735 }
3736
shilu366312e2019-12-17 09:28:10 -08003737 /**
3738 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3739 * @param subId The subscription to use to check the configuration.
3740 * @param c The callback that will be used to send the result.
3741 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003743 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003744 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003745 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3747 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3748 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003749 final long token = Binder.clearCallingIdentity();
3750 try {
3751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3752 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3753 .removeRegistrationCallbackForSubscription(c, subId);
3754 } catch (ImsException e) {
3755 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3756 + "is inactive, ignoring unregister.");
3757 // If the subscription is no longer active, just return, since the callback
3758 // will already have been removed internally.
3759 } finally {
3760 Binder.restoreCallingIdentity(token);
3761 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 }
3763
Brad Ebinger774ba362019-10-22 17:36:18 -07003764 /**
3765 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3766 */
3767 @Override
3768 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3769 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3770 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3771 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3772 "IMS not available on device.");
3773 }
3774 final long token = Binder.clearCallingIdentity();
3775 try {
3776 Phone phone = getPhone(subId);
3777 if (phone == null) {
3778 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3779 + subId + "'");
3780 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3781 }
3782 phone.getImsRegistrationState(regState -> {
3783 try {
3784 consumer.accept((regState == null)
3785 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3786 } catch (RemoteException e) {
3787 // Ignore if the remote process is no longer available to call back.
3788 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3789 }
3790 });
3791 } finally {
3792 Binder.restoreCallingIdentity(token);
3793 }
3794 }
3795
3796 /**
3797 * Get the transport type for the IMS service registration state.
3798 */
3799 @Override
3800 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003801 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003802 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003803 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3804 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3805 "IMS not available on device.");
3806 }
3807 final long token = Binder.clearCallingIdentity();
3808 try {
3809 Phone phone = getPhone(subId);
3810 if (phone == null) {
3811 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3812 + subId + "'");
3813 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3814 }
3815 phone.getImsRegistrationTech(regTech -> {
3816 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3817 int regTechConverted = (regTech == null)
3818 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3819 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3820 regTechConverted);
3821 try {
3822 consumer.accept(regTechConverted);
3823 } catch (RemoteException e) {
3824 // Ignore if the remote process is no longer available to call back.
3825 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3826 }
3827 });
3828 } finally {
3829 Binder.restoreCallingIdentity(token);
3830 }
3831 }
3832
shilu366312e2019-12-17 09:28:10 -08003833 /**
3834 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3835 * @param subId The subscription to use to check the configuration.
3836 * @param c The callback that will be used to send the result.
3837 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003839 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3840 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003841 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003842 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003843 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3844 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3845 "IMS not available on device.");
3846 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3848 final long token = Binder.clearCallingIdentity();
3849 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003850 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003852 } catch (ImsException e) {
3853 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 } finally {
3855 Binder.restoreCallingIdentity(token);
3856 }
3857 }
3858
shilu366312e2019-12-17 09:28:10 -08003859 /**
3860 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3861 * @param subId The subscription to use to check the configuration.
3862 * @param c The callback that will be used to send the result.
3863 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003865 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003866 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003867 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3869 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3870 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003871
3872 final long token = Binder.clearCallingIdentity();
3873 try {
3874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003876 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003877 } catch (ImsException e) {
3878 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3879 + "is inactive, ignoring unregister.");
3880 // If the subscription is no longer active, just return, since the callback
3881 // will already have been removed internally.
3882 } finally {
3883 Binder.restoreCallingIdentity(token);
3884 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 }
3886
3887 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003888 public boolean isCapable(int subId, int capability, int regTech) {
3889 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3891 final long token = Binder.clearCallingIdentity();
3892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003893 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003895 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3897 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003898 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003899 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3900 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 } finally {
3902 Binder.restoreCallingIdentity(token);
3903 }
3904 }
3905
3906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003907 public boolean isAvailable(int subId, int capability, int regTech) {
3908 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 final long token = Binder.clearCallingIdentity();
3910 try {
3911 Phone phone = getPhone(subId);
3912 if (phone == null) return false;
3913 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003914 } catch (com.android.ims.ImsException e) {
3915 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3916 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 } finally {
3918 Binder.restoreCallingIdentity(token);
3919 }
3920 }
3921
Brad Ebinger77b832e2019-10-17 17:03:22 -07003922 /**
3923 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3924 * subscription.
3925 * @param subId The subscription to use to check the configuration.
3926 * @param callback The callback that will be used to send the result.
3927 * @param capability The MmTelFeature capability that will be used to send the result.
3928 * @param transportType The transport type of the MmTelFeature capability.
3929 */
3930 @Override
3931 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3932 int transportType) {
3933 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3934 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3935 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3936 "IMS not available on device.");
3937 }
3938 final long token = Binder.clearCallingIdentity();
3939 try {
3940 int slotId = getSlotIndex(subId);
3941 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3942 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3943 + subId + "'");
3944 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3945 }
3946 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3947 transportType, aBoolean -> {
3948 try {
3949 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3950 } catch (RemoteException e) {
3951 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3952 + "running. Ignore");
3953 }
3954 });
3955 } finally {
3956 Binder.restoreCallingIdentity(token);
3957 }
3958 }
3959
shilu366312e2019-12-17 09:28:10 -08003960 /**
3961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3962 * @param subId The subscription to use to check the configuration.
3963 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 @Override
3965 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003967 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003968
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3970 final long token = Binder.clearCallingIdentity();
3971 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003974 } catch (ImsException e) {
3975 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 } finally {
3977 Binder.restoreCallingIdentity(token);
3978 }
3979 }
3980
3981 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003982 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003984 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 } catch (ImsException e) {
3991 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 }
3996
shilu366312e2019-12-17 09:28:10 -08003997 /**
3998 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3999 * @param subId The subscription to use to check the configuration.
4000 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004002 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004003 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004004 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004008 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4009 } catch (ImsException e) {
4010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
4016 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004017 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004019 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004023 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004024 } catch (ImsException e) {
4025 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
shilu366312e2019-12-17 09:28:10 -08004031 /**
4032 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4033 * @param subId The subscription to use to check the configuration.
4034 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 @Override
4036 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004037 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004038 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004042 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004044 } catch (ImsException e) {
4045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
4049 }
4050
4051 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004052 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004054 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004058 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004059 } catch (ImsException e) {
4060 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
4064 }
4065
shilu366312e2019-12-17 09:28:10 -08004066 /**
4067 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4068 * @param subId The subscription to use to check the configuration.
4069 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 @Override
4071 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004072 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004073 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004077 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004079 } catch (ImsException e) {
4080 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
4084 }
4085
4086 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004087 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004089 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004093 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004095 } catch (ImsException e) {
4096 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
4100 }
4101
4102 @Override
4103 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4105 "setVoWiFiNonPersistent");
4106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004109 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004110 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004111 } catch (ImsException e) {
4112 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
4116 }
4117
shilu366312e2019-12-17 09:28:10 -08004118 /**
4119 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4120 * @param subId The subscription to use to check the configuration.
4121 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 @Override
4123 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004124 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004125 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004129 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 } catch (ImsException e) {
4132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
4138 @Override
4139 public void setVoWiFiModeSetting(int subId, int mode) {
4140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4141 "setVoWiFiModeSetting");
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004145 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004147 } catch (ImsException e) {
4148 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
4152 }
4153
4154 @Override
4155 public int getVoWiFiRoamingModeSetting(int subId) {
4156 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004160 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
4169 @Override
4170 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4172 "setVoWiFiRoamingModeSetting");
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004176 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004178 } catch (ImsException e) {
4179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184
4185 @Override
4186 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4188 "setRttCapabilityEnabled");
4189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004192 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4193 } catch (ImsException e) {
4194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
4198 }
4199
shilu366312e2019-12-17 09:28:10 -08004200 /**
4201 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4202 * @param subId The subscription to use to check the configuration.
4203 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 @Override
4205 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004206 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004207 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004211 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004213 } catch (ImsException e) {
4214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
4218 }
4219
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004220 @Override
4221 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4222 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004225 if (!isImsAvailableOnDevice()) {
4226 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4227 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004228 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004230 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004231 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004232 } catch (ImsException e) {
4233 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
4237 }
4238
4239 @Override
4240 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4241 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4242 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004243 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4244 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4245 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004246 try {
4247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004248 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004249 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004250 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004251 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4252 + "is inactive, ignoring unregister.");
4253 // If the subscription is no longer active, just return, since the callback will already
4254 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
allenwtsu99c623b2020-01-03 18:24:23 +08004260
4261 private void checkModifyPhoneStatePermission(int subId, String message) {
4262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4263 message);
4264 }
4265
4266 private boolean isImsProvisioningRequired(int subId, int capability,
4267 boolean isMmtelCapability) {
4268 Phone phone = getPhone(subId);
4269 if (phone == null) {
4270 loge("phone instance null for subid " + subId);
4271 return false;
4272 }
4273 if (isMmtelCapability) {
4274 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4275 return false;
4276 }
4277 } else {
4278 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4279 return false;
4280 }
4281 }
4282 return true;
4283 }
4284
4285 @Override
4286 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4287 boolean isProvisioned) {
4288 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4289
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4293 if (!isImsProvisioningRequired(subId, capability, false)) {
4294 return;
4295 }
4296
4297 // this capability requires provisioning, route to the correct API.
4298 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4299 switch (capability) {
4300 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4301 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4302 ims.setEabProvisioned(isProvisioned);
4303 break;
4304 default: {
4305 throw new IllegalArgumentException("Tried to set provisioning for "
4306 + "rcs capability '" + capability + "', which does not require "
4307 + "provisioning.");
4308 }
4309 }
4310 } finally {
4311 Binder.restoreCallingIdentity(identity);
4312 }
4313
4314 }
4315
4316
4317 @Override
4318 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4319 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4323 if (!isImsProvisioningRequired(subId, capability, false)) {
4324 return true;
4325 }
4326
4327 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4328 switch (capability) {
4329 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4330 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4331 return ims.isEabProvisionedOnDevice();
4332
4333 default: {
4334 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4335 + "capability '" + capability + "', which does not require "
4336 + "provisioning.");
4337 }
4338 }
4339
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004345 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004346 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4347 boolean isProvisioned) {
4348 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4349 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4350 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4351 }
allenwtsu99c623b2020-01-03 18:24:23 +08004352 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004356 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004357 return;
4358 }
4359
4360 // this capability requires provisioning, route to the correct API.
4361 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4362 switch (capability) {
4363 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4364 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4365 ims.setVolteProvisioned(isProvisioned);
4366 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4367 ims.setWfcProvisioned(isProvisioned);
4368 }
4369 break;
4370 }
4371 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4372 // There is currently no difference in VT provisioning type.
4373 ims.setVtProvisioned(isProvisioned);
4374 break;
4375 }
4376 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4377 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4378 // change the capability of the feature instead if needed.
4379 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4380 == isProvisioned) {
4381 // No change in provisioning.
4382 return;
4383 }
4384 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4385 try {
4386 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004387 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004388 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4389 + ", Exception" + e.getMessage());
4390 }
4391 break;
4392 }
4393 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004394 throw new IllegalArgumentException("Tried to set provisioning for "
4395 + "MmTel capability '" + capability + "', which does not require "
4396 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004397 }
4398 }
4399
4400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
4405 @Override
4406 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4407 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4408 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4409 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4410 }
4411 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004415 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004416 return true;
4417 }
4418
4419 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4420 switch (capability) {
4421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4422 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4423 return ims.isVolteProvisionedOnDevice();
4424 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4425 return ims.isWfcProvisionedOnDevice();
4426 }
4427 // This should never happen, since we are checking tech above to make sure it
4428 // is either LTE or IWLAN.
4429 throw new IllegalArgumentException("Invalid radio technology for voice "
4430 + "capability.");
4431 }
4432 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4433 // There is currently no difference in VT provisioning type.
4434 return ims.isVtProvisionedOnDevice();
4435 }
4436 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4437 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4438 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4439 }
4440 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004441 throw new IllegalArgumentException(
4442 "Tried to get provisioning for MmTel capability '" + capability
4443 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004444 }
4445 }
4446
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
4452 @Override
4453 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4454 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4455 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4456 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4457 }
4458 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4459 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4460 return (provisionedBits & capability) > 0;
4461 }
4462
4463 @Override
4464 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4465 boolean isProvisioned) {
4466 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4467 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4468 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4469 }
4470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4471 "setProvisioningStatusForCapability");
4472 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4473 // If the current provisioning status for capability already matches isProvisioned,
4474 // do nothing.
4475 if (((provisionedBits & capability) > 0) == isProvisioned) {
4476 return;
4477 }
4478 if (isProvisioned) {
4479 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4480 } else {
4481 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4482 }
4483 }
4484
4485 /**
4486 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4487 * technology. The bitfield should mirror the bitfield defined by
4488 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4489 */
4490 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4491 String key = getMmTelProvisioningKey(subId, tech);
4492 // Default is no capabilities are provisioned.
4493 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4494 }
4495
4496 /**
4497 * Sets the MmTel capability provisioning bitfield (defined by
4498 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4499 * technology specified.
4500 *
4501 * Note: This is a synchronous command and should not be called on UI thread.
4502 */
4503 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4504 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4505 String key = getMmTelProvisioningKey(subId, tech);
4506 editor.putInt(key, newField);
4507 editor.commit();
4508 }
4509
4510 private static String getMmTelProvisioningKey(int subId, int tech) {
4511 // resulting key is provision_ims_mmtel_{subId}_{tech}
4512 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4513 }
4514
4515 /**
4516 * Query CarrierConfig to see if the specified capability requires provisioning for the
4517 * carrier associated with the subscription id.
4518 */
4519 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4520 int capability) {
4521 CarrierConfigManager configManager = new CarrierConfigManager(context);
4522 PersistableBundle c = configManager.getConfigForSubId(subId);
4523 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004524 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004525 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4526 false);
4527 boolean requireVoiceVtProvisioning = c.getBoolean(
4528 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4529
4530 // First check to make sure that the capability requires provisioning.
4531 switch (capability) {
4532 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4533 // intentional fallthrough
4534 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4535 if (requireVoiceVtProvisioning) {
4536 // Voice and Video requires provisioning
4537 return true;
4538 }
4539 break;
4540 }
4541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4542 if (requireUtProvisioning) {
4543 // UT requires provisioning
4544 return true;
4545 }
4546 break;
4547 }
4548 }
4549 return false;
4550 }
4551
allenwtsu99c623b2020-01-03 18:24:23 +08004552 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4553 int capability) {
4554 CarrierConfigManager configManager = new CarrierConfigManager(context);
4555 PersistableBundle c = configManager.getConfigForSubId(subId);
4556
4557 boolean requireRcsProvisioning = c.getBoolean(
4558 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4559
4560 // First check to make sure that the capability requires provisioning.
4561 switch (capability) {
4562 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4563 // intentional fallthrough
4564 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4565 if (requireRcsProvisioning) {
4566 // OPTION or PRESENCE requires provisioning
4567 return true;
4568 }
4569 break;
4570 }
4571 }
4572 return false;
4573 }
4574
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004575 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004576 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004577 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4578 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4579 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004580 enforceReadPrivilegedPermission("getImsProvisioningInt");
4581 final long identity = Binder.clearCallingIdentity();
4582 try {
4583 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004584 int slotId = getSlotIndex(subId);
4585 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4586 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4587 + subId + "' for key:" + key);
4588 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4589 }
4590 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004591 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004592 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4593 + subId + "' for key:" + key);
4594 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
4598 }
4599
4600 @Override
4601 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4603 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4604 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004605 enforceReadPrivilegedPermission("getImsProvisioningString");
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004609 int slotId = getSlotIndex(subId);
4610 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4611 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4612 + subId + "' for key:" + key);
4613 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4614 }
4615 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004616 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004617 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4618 + subId + "' for key:" + key);
4619 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
4625 @Override
4626 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4628 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4629 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4631 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004632 final long identity = Binder.clearCallingIdentity();
4633 try {
4634 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004635 int slotId = getSlotIndex(subId);
4636 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4637 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4638 + subId + "' for key:" + key);
4639 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4640 }
4641 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004642 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004643 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4644 + "' for key:" + key);
4645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
4649 }
4650
4651 @Override
4652 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4654 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4655 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4657 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 int slotId = getSlotIndex(subId);
4662 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4663 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4664 + subId + "' for key:" + key);
4665 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4666 }
4667 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004668 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4670 + "' for key:" + key);
4671 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
4675 }
4676
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004677 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004678 int slotId = SubscriptionManager.getSlotIndex(subId);
4679 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004680 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4681 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004682 }
4683 return slotId;
4684 }
4685
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004686 private int getSlotIndex(int subId) {
4687 int slotId = SubscriptionManager.getSlotIndex(subId);
4688 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4689 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4690 }
4691 return slotId;
4692 }
4693
Wink Saville36469e72014-06-11 15:17:00 -07004694 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004695 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004696 */
4697 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004698 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4699 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004700 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004701 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004702 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004703 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004704 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004705 mApp, subId, callingPackage, callingFeatureId,
4706 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004707 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4708 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 final long identity = Binder.clearCallingIdentity();
4711 try {
4712 final Phone phone = getPhone(subId);
4713 if (phone != null) {
4714 return phone.getServiceState().getDataNetworkType();
4715 } else {
4716 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4717 }
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004721 }
4722
4723 /**
4724 * Returns the data network type
4725 */
4726 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004727 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4728 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4729 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004730 }
4731
4732 /**
4733 * Returns the data network type for a subId
4734 */
4735 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004736 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4737 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004739 mApp, subId, callingPackage, callingFeatureId,
4740 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004741 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4742 }
4743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 final Phone phone = getPhone(subId);
4747 if (phone != null) {
4748 return phone.getServiceState().getDataNetworkType();
4749 } else {
4750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004755 }
4756
4757 /**
Wink Saville36469e72014-06-11 15:17:00 -07004758 * Returns the Voice network type for a subId
4759 */
4760 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004761 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4762 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004764 mApp, subId, callingPackage, callingFeatureId,
4765 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004766 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4767 }
4768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 final Phone phone = getPhone(subId);
4772 if (phone != null) {
4773 return phone.getServiceState().getVoiceNetworkType();
4774 } else {
4775 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4776 }
4777 } finally {
4778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004780 }
4781
4782 /**
4783 * @return true if a ICC card is present
4784 */
4785 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004786 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004787 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4788 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004789 }
4790
4791 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004792 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004793 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004794 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004795 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 final Phone phone = PhoneFactory.getPhone(slotIndex);
4799 if (phone != null) {
4800 return phone.getIccCard().hasIccCard();
4801 } else {
4802 return false;
4803 }
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004807 }
4808
4809 /**
4810 * Return if the current radio is LTE on CDMA. This
4811 * is a tri-state return value as for a period of time
4812 * the mode may be unknown.
4813 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004814 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004815 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004816 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004817 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004818 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004819 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4820 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4821 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004822 }
4823
Sanket Padawe356d7632015-06-22 14:03:32 -07004824 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004825 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4826 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004827 try {
4828 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4829 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004830 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4831 }
4832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
4835 final Phone phone = getPhone(subId);
4836 if (phone == null) {
4837 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4838 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004839 return TelephonyProperties.lte_on_cdma_device()
4840 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 }
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004844 }
Wink Saville36469e72014-06-11 15:17:00 -07004845 }
4846
Wink Saville36469e72014-06-11 15:17:00 -07004847 /**
4848 * {@hide}
4849 * Returns Default subId, 0 in the case of single standby.
4850 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004851 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004852 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004853 }
4854
Shishir Agrawala9f32182016-04-12 12:00:16 -07004855 private int getSlotForDefaultSubscription() {
4856 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4857 }
4858
Wink Savilleb564aae2014-10-23 10:18:09 -07004859 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004860 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004861 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004862
Pengquan Menge92a50d2018-09-21 15:54:48 -07004863 private boolean isActiveSubscription(int subId) {
4864 return mSubscriptionController.isActiveSubId(subId);
4865 }
4866
Ihab Awadf2177b72013-11-25 13:33:23 -08004867 /**
4868 * @see android.telephony.TelephonyManager.WifiCallingChoices
4869 */
4870 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 final long identity = Binder.clearCallingIdentity();
4872 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4875 getWhenToMakeWifiCallsDefaultPreference());
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004879 }
4880
4881 /**
4882 * @see android.telephony.TelephonyManager.WifiCallingChoices
4883 */
4884 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885 final long identity = Binder.clearCallingIdentity();
4886 try {
4887 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004888 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4890 } finally {
4891 Binder.restoreCallingIdentity(identity);
4892 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004893 }
4894
Sailesh Nepald1e68152013-12-12 19:08:02 -08004895 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004896 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004897 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004898 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004899
Jordan Liu4c733742019-02-28 12:03:40 -08004900 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4901 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4902 if (phoneId == -1) {
4903 throw new IllegalArgumentException("Given slot index: " + slotIndex
4904 + " does not correspond to an active phone");
4905 }
4906 return PhoneFactory.getPhone(phoneId);
4907 }
4908
Shishir Agrawal566b7612013-10-28 14:41:00 -07004909 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004910 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4911 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4913 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004915 if (DBG) {
4916 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4917 }
4918 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4919 p2);
4920 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004921
Jordan Liu4c733742019-02-28 12:03:40 -08004922
4923 @Override
4924 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4925 int slotIndex, String callingPackage, String aid, int p2) {
4926 enforceModifyPermission();
4927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4928 if (DBG) {
4929 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4930 }
4931 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4932 callingPackage, aid, p2);
4933 }
4934
4935 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4936 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 final long identity = Binder.clearCallingIdentity();
4938 try {
4939 if (TextUtils.equals(ISDR_AID, aid)) {
4940 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004941 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4942 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 if (bestComponent == null
4944 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4945 loge("The calling package is not allowed to access ISD-R.");
4946 throw new SecurityException(
4947 "The calling package is not allowed to access ISD-R.");
4948 }
Derek Tan740e1672017-06-27 14:56:27 -07004949 }
Derek Tan740e1672017-06-27 14:56:27 -07004950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004952 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4953 null /* workSource */);
4954 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 return response;
4956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004959 }
4960
4961 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004962 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4964 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004965 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4966 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4967 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004968
Jordan Liu4c733742019-02-28 12:03:40 -08004969 @Override
4970 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4971 enforceModifyPermission();
4972 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4973 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4974 channel);
4975 }
4976
4977 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 final long identity = Binder.clearCallingIdentity();
4979 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 if (channel < 0) {
4981 return false;
4982 }
Jordan Liu4c733742019-02-28 12:03:40 -08004983 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4984 null /* workSource */);
4985 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 return success;
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004989 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004990 }
4991
4992 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004993 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004994 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4996 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004997 if (DBG) {
4998 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4999 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5000 + p3 + " data=" + data);
5001 }
5002 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5003 command, p1, p2, p3, data);
5004 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005005
Jordan Liu4c733742019-02-28 12:03:40 -08005006 @Override
5007 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5008 int command, int p1, int p2, int p3, String data) {
5009 enforceModifyPermission();
5010 if (DBG) {
5011 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5012 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5013 + p3 + " data=" + data);
5014 }
5015 return iccTransmitApduLogicalChannelWithPermission(
5016 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5017 data);
5018 }
5019
5020 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5021 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 final long identity = Binder.clearCallingIdentity();
5023 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005024 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 return "";
5026 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005029 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5030 null /* workSource */);
5031 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 // Append the returned status code to the end of the response payload.
5034 String s = Integer.toHexString(
5035 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5036 if (response.payload != null) {
5037 s = IccUtils.bytesToHexString(response.payload) + s;
5038 }
5039 return s;
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005042 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005043 }
Jake Hambye994d462014-02-03 13:10:13 -08005044
Evan Charltonc66da362014-05-16 14:06:40 -07005045 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005046 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5047 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5049 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005051 if (DBG) {
5052 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5053 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5054 }
5055 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5056 cla, command, p1, p2, p3, data);
5057 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005058
Jordan Liu4c733742019-02-28 12:03:40 -08005059 @Override
5060 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5061 int command, int p1, int p2, int p3, String data) {
5062 enforceModifyPermission();
5063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5064 if (DBG) {
5065 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5066 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5067 + " data=" + data);
5068 }
5069
5070 return iccTransmitApduBasicChannelWithPermission(
5071 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5072 p2, p3, data);
5073 }
5074
5075 // open APDU basic channel assuming the caller has sufficient permissions
5076 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5077 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5081 && TextUtils.equals(ISDR_AID, data)) {
5082 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005083 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5084 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 if (bestComponent == null
5086 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5087 loge("The calling package is not allowed to select ISD-R.");
5088 throw new SecurityException(
5089 "The calling package is not allowed to select ISD-R.");
5090 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005091 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005094 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5095 null /* workSource */);
5096 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 // Append the returned status code to the end of the response payload.
5099 String s = Integer.toHexString(
5100 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5101 if (response.payload != null) {
5102 s = IccUtils.bytesToHexString(response.payload) + s;
5103 }
5104 return s;
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005107 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005108 }
5109
5110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005111 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005112 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5114 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 if (DBG) {
5119 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5120 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5121 }
5122
5123 IccIoResult response =
5124 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5125 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5126 subId);
5127
5128 if (DBG) {
5129 log("Exchange SIM_IO [R]" + response);
5130 }
5131
5132 byte[] result = null;
5133 int length = 2;
5134 if (response.payload != null) {
5135 length = 2 + response.payload.length;
5136 result = new byte[length];
5137 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5138 } else {
5139 result = new byte[length];
5140 }
5141
5142 result[length - 1] = (byte) response.sw2;
5143 result[length - 2] = (byte) response.sw1;
5144 return result;
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005147 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005148 }
5149
Nathan Haroldb3014052017-01-25 15:57:32 -08005150 /**
5151 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5152 * on a particular subscription
5153 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005154 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5155 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005157 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005158 return null;
5159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 if (appType != TelephonyManager.APPTYPE_USIM
5164 && appType != TelephonyManager.APPTYPE_SIM) {
5165 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5166 return null;
5167 }
5168 Object response = sendRequest(
5169 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5170 if (response instanceof String[]) {
5171 return (String[]) response;
5172 }
yincheng zhaod698b842019-09-06 17:06:54 -07005173 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005175 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005178 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005179 }
5180
yincheng zhaod698b842019-09-06 17:06:54 -07005181 /**
5182 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5183 * subscription.
5184 *
5185 * @param subId the id of the subscription.
5186 * @param appType the uicc app type, must be USIM or SIM.
5187 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5188 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005189 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005190 * @return number of fplmns that is successfully written to the SIM.
5191 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005192 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5193 String callingFeatureId) {
5194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5195 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005196 if (DBG) logv("no permissions for setForbiddenplmns");
5197 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5198 }
5199 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5200 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5201 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5202 }
5203 if (fplmns == null) {
5204 throw new IllegalArgumentException("Fplmn List provided is null");
5205 }
5206 for (String fplmn : fplmns) {
5207 if (!CellIdentity.isValidPlmn(fplmn)) {
5208 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5209 }
5210 }
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 Object response = sendRequest(
5214 CMD_SET_FORBIDDEN_PLMNS,
5215 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5216 subId);
5217 return (int) response;
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005223 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005224 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5226 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5231 if (response.payload == null) {
5232 return "";
5233 }
Evan Charltonc66da362014-05-16 14:06:40 -07005234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 // Append the returned status code to the end of the response payload.
5236 String s = Integer.toHexString(
5237 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5238 s = IccUtils.bytesToHexString(response.payload) + s;
5239 return s;
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Evan Charltonc66da362014-05-16 14:06:40 -07005243 }
5244
Jake Hambye994d462014-02-03 13:10:13 -08005245 /**
5246 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5247 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5248 *
5249 * @param itemID the ID of the item to read
5250 * @return the NV item as a String, or null on error.
5251 */
5252 @Override
5253 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5256 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257
5258 final long identity = Binder.clearCallingIdentity();
5259 try {
5260 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005261 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5263 return value;
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
Jake Hambye994d462014-02-03 13:10:13 -08005267 }
5268
5269 /**
5270 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5271 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5272 *
5273 * @param itemID the ID of the item to read
5274 * @param itemValue the value to write, as a String
5275 * @return true on success; false on any failure
5276 */
5277 @Override
5278 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5281 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282
5283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5286 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005287 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5289 return success;
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
Jake Hambye994d462014-02-03 13:10:13 -08005293 }
5294
5295 /**
5296 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5297 * Used for device configuration by some CDMA operators.
5298 *
5299 * @param preferredRoamingList byte array containing the new PRL
5300 * @return true on success; false on any failure
5301 */
5302 @Override
5303 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5305 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306
5307 final long identity = Binder.clearCallingIdentity();
5308 try {
5309 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5310 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5311 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5312 return success;
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Jake Hambye994d462014-02-03 13:10:13 -08005316 }
5317
5318 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005319 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005320 * Used for device configuration by some CDMA operators.
5321 *
chen xu6dac5ab2018-10-26 17:39:23 -07005322 * @param slotIndex - device slot.
5323 *
Jake Hambye994d462014-02-03 13:10:13 -08005324 * @return true on success; false on any failure
5325 */
5326 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005327 public boolean resetModemConfig(int slotIndex) {
5328 Phone phone = PhoneFactory.getPhone(slotIndex);
5329 if (phone != null) {
5330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5331 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332
chen xu6dac5ab2018-10-26 17:39:23 -07005333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5336 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5337 return success;
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 }
chen xu6dac5ab2018-10-26 17:39:23 -07005342 return false;
5343 }
5344
5345 /**
5346 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5347 *
5348 * @param slotIndex - device slot.
5349 *
5350 * @return true on success; false on any failure
5351 */
5352 @Override
5353 public boolean rebootModem(int slotIndex) {
5354 Phone phone = PhoneFactory.getPhone(slotIndex);
5355 if (phone != null) {
5356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, phone.getSubId(), "rebootModem");
5358
5359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5362 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5363 return success;
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
5367 }
5368 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005369 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005370
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005371 public String[] getPcscfAddress(String apnType, String callingPackage,
5372 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005373 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5375 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005376 return new String[0];
5377 }
5378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005381 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
Wink Saville36469e72014-06-11 15:17:00 -07005385 }
5386
Brad Ebinger51f743a2017-01-23 13:50:20 -08005387 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005388 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5389 * {@link #disableIms(int)}.
5390 * @param slotIndex device slot.
5391 */
5392 public void resetIms(int slotIndex) {
5393 enforceModifyPermission();
5394
5395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 if (mImsResolver == null) {
5398 // may happen if the does not support IMS.
5399 return;
5400 }
5401 mImsResolver.disableIms(slotIndex);
5402 mImsResolver.enableIms(slotIndex);
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
5406 }
5407
5408 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005409 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5410 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005411 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005412 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005413 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414
5415 final long identity = Binder.clearCallingIdentity();
5416 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005417 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005418 // may happen if the device does not support IMS.
5419 return;
5420 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005421 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005425 }
5426
5427 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5429 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005430 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005431 public void disableIms(int slotId) {
5432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433
5434 final long identity = Binder.clearCallingIdentity();
5435 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005436 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005437 // may happen if the device does not support IMS.
5438 return;
5439 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005444 }
5445
5446 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005447 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5448 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005449 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005450 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005451 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453
5454 final long identity = Binder.clearCallingIdentity();
5455 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005456 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005457 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5458 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005459 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005460 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005464 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005465 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005466 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5467 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005468 @Override
5469 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005470 enforceModifyPermission();
5471
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005475 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005476 } finally {
5477 Binder.restoreCallingIdentity(identity);
5478 }
5479 }
5480
5481 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005482 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005483 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005484 */
5485 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005491 // may happen if the device does not support IMS.
5492 return null;
5493 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005494 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005498 }
5499
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005500 /**
5501 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005502 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005503 */
5504 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005510 // may happen if the device does not support IMS.
5511 return null;
5512 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005513 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005517 }
5518
Brad Ebinger884c07b2018-02-15 16:17:40 -08005519 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005520 * Sets the ImsService Package Name that Telephony will bind to.
5521 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005522 * @param slotIndex the slot ID that the ImsService should bind for.
5523 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005524 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 * @param featureTypes An integer array of feature types associated with a packageName.
5526 * @param packageName The name of the package that the current configuration will be replaced
5527 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005528 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005529 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005530 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5531 int[] featureTypes, String packageName) {
5532 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5533 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5535 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005536 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 final long identity = Binder.clearCallingIdentity();
5539 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005540 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005541 // may happen if the device does not support IMS.
5542 return false;
5543 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005544 Map<Integer, String> featureConfig = new HashMap<>();
5545 for (int featureType : featureTypes) {
5546 featureConfig.put(featureType, packageName);
5547 }
5548 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5549 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005553 }
5554
5555 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005556 * Clears any carrier ImsService overrides for the slot index specified that were previously
5557 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5558 *
5559 * This should only be used for testing.
5560 *
5561 * @param slotIndex the slot ID that the ImsService should bind for.
5562 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5563 */
5564 @Override
5565 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5566 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5568 "clearCarrierImsServiceOverride");
5569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5570 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5571 "clearCarrierImsServiceOverride");
5572
5573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 if (mImsResolver == null) {
5576 // may happen if the device does not support IMS.
5577 return false;
5578 }
5579 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5580 } finally {
5581 Binder.restoreCallingIdentity(identity);
5582 }
5583 }
5584
5585 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005586 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005587 *
5588 * @param slotId The slot that the ImsService is associated with.
5589 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5590 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005591 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005592 * @return the package name of the ImsService configuration.
5593 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005594 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5595 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005596 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005597 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005598 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5600 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 final long identity = Binder.clearCallingIdentity();
5603 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005604 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005605 // may happen if the device does not support IMS.
5606 return "";
5607 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005608 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005609 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5610 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005614 }
5615
Brad Ebinger77b832e2019-10-17 17:03:22 -07005616 /**
5617 * Get the MmTelFeature state associated with the requested subscription id.
5618 * @param subId The subscription that the MmTelFeature is associated with.
5619 * @param callback A callback with an integer containing the
5620 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5621 */
5622 @Override
5623 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5624 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5625 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5626 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5627 "IMS not available on device.");
5628 }
5629 final long token = Binder.clearCallingIdentity();
5630 try {
5631 int slotId = getSlotIndex(subId);
5632 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5633 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5634 + subId + "'");
5635 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5636 }
5637 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5638 try {
5639 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5640 } catch (RemoteException e) {
5641 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5642 + "Ignore");
5643 }
5644 });
5645 } finally {
5646 Binder.restoreCallingIdentity(token);
5647 }
5648 }
5649
Daniel Brightbb5840b2021-01-12 15:48:18 -08005650 /**
5651 * Sets the ims registration state on all valid {@link Phone}s.
5652 */
5653 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005658 // NOTE: Before S, this method only set the default phone.
5659 for (final Phone phone : PhoneFactory.getPhones()) {
5660 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5661 phone.setImsRegistrationState(registered);
5662 }
5663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Wink Saville36469e72014-06-11 15:17:00 -07005667 }
5668
5669 /**
Stuart Scott54788802015-03-30 13:18:01 -07005670 * Set the network selection mode to automatic.
5671 *
5672 */
5673 @Override
5674 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5676 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
shilufc958392020-01-20 11:36:01 -08005680 if (!isActiveSubscription(subId)) {
5681 return;
5682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005684 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5685 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
Stuart Scott54788802015-03-30 13:18:01 -07005689 }
5690
Jack Yud10cdd42020-09-28 20:28:01 -07005691 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005692 * Ask the radio to connect to the input network and change selection mode to manual.
5693 *
5694 * @param subId the id of the subscription.
5695 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5696 * the operator to attach to.
5697 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5698 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5699 * normal network selection next time.
5700 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005701 */
5702 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005703 public boolean setNetworkSelectionModeManual(
5704 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5706 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005707
5708 if (!isActiveSubscription(subId)) {
5709 return false;
5710 }
5711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005714 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005716 if (DBG) {
5717 log("setNetworkSelectionModeManual: subId: " + subId
5718 + " operator: " + operatorInfo);
5719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005724 }
shilu84f6e8b2019-12-19 13:58:01 -08005725 /**
5726 * Get the manual network selection
5727 *
5728 * @param subId the id of the subscription.
5729 *
5730 * @return the previously saved user selected PLMN
5731 */
5732 @Override
5733 public String getManualNetworkSelectionPlmn(int subId) {
5734 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005735 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005736 mApp, subId, "getManualNetworkSelectionPlmn");
5737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 if (!isActiveSubscription(subId)) {
5741 return "";
5742 }
5743
5744 final Phone phone = getPhone(subId);
5745 if (phone == null) {
5746 return "";
5747 }
5748 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5749 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5750 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
5754 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005755
5756 /**
5757 * Scans for available networks.
5758 */
5759 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005760 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5761 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5763 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005764 LocationAccessPolicy.LocationPermissionResult locationResult =
5765 LocationAccessPolicy.checkLocationPermission(mApp,
5766 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5767 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005768 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005769 .setCallingPid(Binder.getCallingPid())
5770 .setCallingUid(Binder.getCallingUid())
5771 .setMethod("getCellNetworkScanResults")
5772 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5773 .build());
5774 switch (locationResult) {
5775 case DENIED_HARD:
5776 throw new SecurityException("Not allowed to access scan results -- location");
5777 case DENIED_SOFT:
5778 return null;
5779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
Pengquan Menga1bb6272018-09-06 09:59:22 -07005781 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 try {
5783 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005784 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005789 }
5790
5791 /**
sqian80370722020-01-29 15:02:51 -08005792 * Get the call forwarding info, given the call forwarding reason.
5793 */
5794 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005795 public void getCallForwarding(int subId, int callForwardingReason,
5796 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005797 enforceReadPrivilegedPermission("getCallForwarding");
5798 long identity = Binder.clearCallingIdentity();
5799 try {
5800 if (DBG) {
5801 log("getCallForwarding: subId " + subId
5802 + " callForwardingReason" + callForwardingReason);
5803 }
Hall Liua1acea22020-09-18 19:04:59 -07005804
5805 Phone phone = getPhone(subId);
5806 if (phone == null) {
5807 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005808 callback.onError(
5809 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005810 } catch (RemoteException e) {
5811 // ignore
5812 }
5813 return;
5814 }
5815
5816 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5817 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5818 @Override
5819 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5820 try {
5821 callback.onCallForwardingInfoAvailable(info);
5822 } catch (RemoteException e) {
5823 // ignore
5824 }
5825 }
5826
5827 @Override
5828 public void onError(int error) {
5829 try {
5830 callback.onError(error);
5831 } catch (RemoteException e) {
5832 // ignore
5833 }
5834 }
5835 });
5836 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
5840 }
5841
5842 /**
5843 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5844 * reason, the number to forward, and the timeout before the forwarding is attempted.
5845 */
5846 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005847 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5848 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005849 enforceModifyPermission();
5850 long identity = Binder.clearCallingIdentity();
5851 try {
5852 if (DBG) {
5853 log("setCallForwarding: subId " + subId
5854 + " callForwardingInfo" + callForwardingInfo);
5855 }
Hall Liua1acea22020-09-18 19:04:59 -07005856
5857 Phone phone = getPhone(subId);
5858 if (phone == null) {
5859 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005860 callback.accept(
5861 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005862 } catch (RemoteException e) {
5863 // ignore
5864 }
5865 return;
5866 }
5867
5868 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5869 FunctionalUtils.ignoreRemoteException(callback::accept));
5870
5871 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
5875 }
5876
5877 /**
Hall Liua1acea22020-09-18 19:04:59 -07005878 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005879 */
5880 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005881 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005882 enforceReadPrivilegedPermission("getCallForwarding");
5883 long identity = Binder.clearCallingIdentity();
5884 try {
Hall Liua1acea22020-09-18 19:04:59 -07005885
5886 Phone phone = getPhone(subId);
5887 if (phone == null) {
5888 try {
5889 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5890 } catch (RemoteException e) {
5891 // ignore
5892 }
5893 return;
5894 }
5895
5896 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5897
sqian80370722020-01-29 15:02:51 -08005898 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005899 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
5903 }
5904
5905 /**
Hall Liua1acea22020-09-18 19:04:59 -07005906 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005907 */
5908 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005909 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005910 enforceModifyPermission();
5911 long identity = Binder.clearCallingIdentity();
5912 try {
Hall Liua1acea22020-09-18 19:04:59 -07005913 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5914
5915 Phone phone = getPhone(subId);
5916 if (phone == null) {
5917 try {
5918 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5919 } catch (RemoteException e) {
5920 // ignore
5921 }
5922 return;
5923 }
5924
5925 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5926 FunctionalUtils.ignoreRemoteException(callback::accept));
5927
5928 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
5932 }
5933
5934 /**
yinxub1bed742017-04-17 11:45:04 -07005935 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005936 *
yinxub1bed742017-04-17 11:45:04 -07005937 * @param subId id of the subscription
5938 * @param request contains the radio access networks with bands/channels to scan
5939 * @param messenger callback messenger for scan results or errors
5940 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005941 * @return the id of the requested scan which can be used to stop the scan.
5942 */
5943 @Override
5944 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005945 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5947 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005948 LocationAccessPolicy.LocationPermissionResult locationResult =
5949 LocationAccessPolicy.checkLocationPermission(mApp,
5950 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5951 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005952 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005953 .setCallingPid(Binder.getCallingPid())
5954 .setCallingUid(Binder.getCallingUid())
5955 .setMethod("requestNetworkScan")
5956 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5957 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005958 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005959 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5960 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005961 if (e != null) {
5962 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5963 throw e;
5964 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005965 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005966 return TelephonyScanManager.INVALID_SCAN_ID;
5967 }
5968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 }
Hall Liu912dfd32019-04-25 14:02:26 -07005970 int callingUid = Binder.getCallingUid();
5971 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005972 final long identity = Binder.clearCallingIdentity();
5973 try {
5974 return mNetworkScanRequestTracker.startNetworkScan(
5975 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005976 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
yinxu504e1392017-04-12 16:03:22 -07005980 }
5981
Hall Liub2ac8ef2019-02-28 15:56:23 -08005982 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005983 NetworkScanRequest request, int subId, String callingPackage) {
5984 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005985 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5986 boolean hasNetworkScanPermission =
5987 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5988 == PERMISSION_GRANTED;
5989
5990 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5991 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5992 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005993 }
5994
5995 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5996 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005997 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5998 return new SecurityException("Specific channels must not be"
5999 + " scanned without location access.");
6000 }
6001 }
6002 }
6003
Hall Liub2ac8ef2019-02-28 15:56:23 -08006004 return null;
6005 }
6006
yinxu504e1392017-04-12 16:03:22 -07006007 /**
6008 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006009 *
6010 * @param subId id of the subscription
6011 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006012 */
6013 @Override
6014 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6016 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017
Hall Liu912dfd32019-04-25 14:02:26 -07006018 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006021 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
yinxu504e1392017-04-12 16:03:22 -07006025 }
6026
6027 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006028 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006029 *
SongFerngWang9e060372020-12-21 16:41:52 +08006030 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006031 */
6032 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006033 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006034 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006035 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006036 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037
6038 final long identity = Binder.clearCallingIdentity();
6039 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006040 if (DBG) log("getAllowedNetworkTypesBitmask");
6041 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6042 int networkTypesBitmask = (result != null ? result[0] : -1);
6043 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6044 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006048 }
6049
6050 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006051 * Get the allowed network types for certain reason.
6052 *
6053 * @param subId the id of the subscription.
6054 * @param reason the reason the allowed network type change is taking place
6055 * @return the allowed network types.
6056 */
6057 @Override
6058 public long getAllowedNetworkTypesForReason(int subId,
6059 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006060 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006061 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006062 final long identity = Binder.clearCallingIdentity();
6063 try {
6064 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6065 } finally {
6066 Binder.restoreCallingIdentity(identity);
6067 }
6068 }
6069
6070 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006071 * Enable/Disable E-UTRA-NR Dual Connectivity
6072 * @param subId subscription id of the sim card
6073 * @param nrDualConnectivityState expected NR dual connectivity state
6074 * This can be passed following states
6075 * <ol>
6076 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6077 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6078 * <li>Disable NR dual connectivity and force secondary cell to be released
6079 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6080 * </ol>
6081 * @return operation result.
6082 */
6083 @Override
6084 public int setNrDualConnectivityState(int subId,
6085 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006088 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006089 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6090 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6091 }
6092
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6094 final long identity = Binder.clearCallingIdentity();
6095 try {
6096 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6097 nrDualConnectivityState, subId,
6098 workSource);
6099 if (DBG) log("enableNRDualConnectivity result: " + result);
6100 return result;
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
6107 * Is E-UTRA-NR Dual Connectivity enabled
6108 * @return true if dual connectivity is enabled else false
6109 */
6110 @Override
6111 public boolean isNrDualConnectivityEnabled(int subId) {
6112 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006113 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006114 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006115 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006116 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6117 return false;
6118 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006119 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6120 final long identity = Binder.clearCallingIdentity();
6121 try {
6122 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6123 null, subId, workSource);
6124 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6125 return isEnabled;
6126 } finally {
6127 Binder.restoreCallingIdentity(identity);
6128 }
6129 }
6130
6131 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006132 * Set the allowed network types of the device and
6133 * provide the reason triggering the allowed network change.
6134 *
6135 * @param subId the id of the subscription.
6136 * @param reason the reason the allowed network type change is taking place
6137 * @param allowedNetworkTypes the allowed network types.
6138 * @return true on success; false on any failure.
6139 */
6140 @Override
6141 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006142 @TelephonyManager.AllowedNetworkTypesReason int reason,
6143 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6145 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006146 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6147 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6148 return false;
6149 }
6150
SongFerngWang522637d2021-03-02 22:09:29 +08006151 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6152 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6153
6154
6155 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6156 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6157 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006158 }
SongFerngWang522637d2021-03-02 22:09:29 +08006159
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006160 final long identity = Binder.clearCallingIdentity();
6161 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006162 Boolean success = (Boolean) sendRequest(
6163 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6164 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6165
6166 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6167 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
6171 }
6172
6173 /**
Miaoa84611c2019-03-15 09:21:10 +08006174 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006175 *
Miaoa84611c2019-03-15 09:21:10 +08006176 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006177 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006178 * @hide
6179 */
6180 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006181 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006184 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 try {
Miaoa84611c2019-03-15 09:21:10 +08006186 if (phone != null) {
6187 return phone.hasMatchedTetherApnSetting();
6188 } else {
6189 return false;
6190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 } finally {
6192 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006193 }
Junda Liu475951f2014-11-07 16:45:03 -08006194 }
6195
6196 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006197 * Enable or disable always reporting signal strength changes from radio.
6198 *
6199 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6200 */
6201 @Override
6202 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6203 enforceModifyPermission();
6204 enforceSystemCaller();
6205
6206 final long identity = Binder.clearCallingIdentity();
6207 final Phone phone = getPhone(subId);
6208 try {
6209 if (phone != null) {
6210 if (DBG) {
6211 log("setAlwaysReportSignalStrength: subId=" + subId
6212 + " isEnable=" + isEnable);
6213 }
6214 phone.setAlwaysReportSignalStrength(isEnable);
6215 } else {
6216 loge("setAlwaysReportSignalStrength: no phone found for subId="
6217 + subId);
6218 }
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
6221 }
6222 }
6223
6224 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006225 * Get the user enabled state of Mobile Data.
6226 *
6227 * TODO: remove and use isUserDataEnabled.
6228 * This can't be removed now because some vendor codes
6229 * calls through ITelephony directly while they should
6230 * use TelephonyManager.
6231 *
6232 * @return true on enabled
6233 */
6234 @Override
6235 public boolean getDataEnabled(int subId) {
6236 return isUserDataEnabled(subId);
6237 }
6238
6239 /**
6240 * Get whether mobile data is enabled per user setting.
6241 *
6242 * There are other factors deciding whether mobile data is actually enabled, but they are
6243 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006244 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006245 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006246 *
6247 * @return {@code true} if data is enabled else {@code false}
6248 */
6249 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006250 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006251 try {
6252 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6253 null);
6254 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6256 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 int phoneId = mSubscriptionController.getPhoneId(subId);
6262 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6263 Phone phone = PhoneFactory.getPhone(phoneId);
6264 if (phone != null) {
6265 boolean retVal = phone.isUserDataEnabled();
6266 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6267 return retVal;
6268 } else {
6269 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6270 return false;
6271 }
6272 } finally {
6273 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006274 }
6275 }
6276
6277 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006278 * Checks if the device is capable of mobile data by considering whether whether the
6279 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6280 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006281 *
Shuo Qian985d1232020-01-08 14:30:06 -08006282 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006283 */
6284 @Override
6285 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006286 try {
6287 try {
6288 mApp.enforceCallingOrSelfPermission(
6289 android.Manifest.permission.ACCESS_NETWORK_STATE,
6290 null);
6291 } catch (Exception e) {
6292 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6293 "isDataEnabled");
6294 }
6295 } catch (Exception e) {
6296 enforceReadPrivilegedPermission("isDataEnabled");
6297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298
6299 final long identity = Binder.clearCallingIdentity();
6300 try {
6301 int phoneId = mSubscriptionController.getPhoneId(subId);
6302 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6303 Phone phone = PhoneFactory.getPhone(phoneId);
6304 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006305 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6307 return retVal;
6308 } else {
6309 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6310 return false;
6311 }
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006314 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006315 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006316
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006317 /**
6318 * Check if data is enabled for a specific reason
6319 * @param subId Subscription index
6320 * @param reason the reason the data enable change is taking place
6321 * @return {@code true} if the overall data is enabled; {@code false} if not.
6322 */
6323 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006324 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006325 @TelephonyManager.DataEnabledReason int reason) {
6326 try {
6327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6328 null);
6329 } catch (Exception e) {
6330 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006331 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006332 }
6333
6334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 int phoneId = mSubscriptionController.getPhoneId(subId);
6338 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006339 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006340 + " reason=" + reason);
6341 }
6342 Phone phone = PhoneFactory.getPhone(phoneId);
6343 if (phone != null) {
6344 boolean retVal;
6345 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6346 retVal = phone.isUserDataEnabled();
6347 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006348 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006349 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006350 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006351 return retVal;
6352 } else {
6353 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006354 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006355 + subId + " retVal=false");
6356 }
6357 return false;
6358 }
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
6361 }
6362 }
6363
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006364 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006365 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006366 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6367 // Skip the check if it's one of these special uids
6368 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6369 }
6370
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006371 //load access rules from carrier configs, and check those as well: b/139133814
6372 SubscriptionController subController = SubscriptionController.getInstance();
6373 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6374 || subController == null) return privilegeFromSim;
6375
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006376 PackageManager pkgMgr = phone.getContext().getPackageManager();
6377 String[] packages = pkgMgr.getPackagesForUid(uid);
6378
6379 final long identity = Binder.clearCallingIdentity();
6380 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006381 int subId = phone.getSubId();
6382 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6383 // A test override is in place for the privileges for this subId, so don't try to
6384 // read the subscription privileges.
6385 return privilegeFromSim;
6386 }
6387 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006388 SubscriptionManager subManager = (SubscriptionManager)
6389 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6390 for (String pkg : packages) {
6391 if (subManager.canManageSubscription(subInfo, pkg)) {
6392 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6393 }
6394 }
6395 return privilegeFromSim;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
6399 }
6400
6401 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6402 String pkgName) {
6403 //load access rules from carrier configs, and check those as well: b/139133814
6404 SubscriptionController subController = SubscriptionController.getInstance();
6405 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6406 || subController == null) return privilegeFromSim;
6407
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006410 int subId = phone.getSubId();
6411 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6412 // A test override is in place for the privileges for this subId, so don't try to
6413 // read the subscription privileges.
6414 return privilegeFromSim;
6415 }
6416 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006417 SubscriptionManager subManager = (SubscriptionManager)
6418 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6419 return subManager.canManageSubscription(subInfo, pkgName)
6420 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
6424 }
6425
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006426 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006427 public int getCarrierPrivilegeStatus(int subId) {
6428 final Phone phone = getPhone(subId);
6429 if (phone == null) {
6430 loge("getCarrierPrivilegeStatus: Invalid subId");
6431 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6432 }
6433 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006434 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006435 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006436 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6437 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006438
6439 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6440 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006441 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006442 }
Junda Liu29340342014-07-10 15:23:27 -07006443
6444 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006445 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006446 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006447 final Phone phone = getPhone(subId);
6448 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006449 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006450 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6451 }
6452 UiccProfile profile =
6453 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6454 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006455 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006456 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6457 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006458 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006459 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006460 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006461 }
6462
6463 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006464 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6465 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006466 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006467 }
6468
6469 int phoneId = SubscriptionManager.getPhoneId(subId);
6470 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006471 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006472 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006473 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6474 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006475 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6476 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6477 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006478 }
6479
6480 @Override
6481 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006482 if (TextUtils.isEmpty(pkgName))
6483 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006484 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6485 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6486 UiccCard card = UiccController.getInstance().getUiccCard(i);
6487 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006488 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006489 continue;
6490 }
6491
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006492 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6493 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6494 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006495 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6496 break;
6497 }
6498 }
6499
6500 return result;
Junda Liu29340342014-07-10 15:23:27 -07006501 }
Derek Tan89e89d42014-07-08 17:00:10 -07006502
6503 @Override
Junda Liue64de782015-04-16 17:19:16 -07006504 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6505 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6506 loge("phoneId " + phoneId + " is not valid.");
6507 return null;
6508 }
6509 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006510 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006511 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006512 return null ;
6513 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006514 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006515 }
6516
Amith Yamasani6e118872016-02-19 12:53:51 -08006517 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006518 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006519 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006520 List<String> privilegedPackages = new ArrayList<>();
6521 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006522 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6523 // has UICC in that slot.
6524 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006525 if (card.hasCarrierPrivilegeRules()) {
6526 if (packages == null) {
6527 // Only check packages in user 0 for now
6528 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006529 PackageManager.MATCH_DISABLED_COMPONENTS
6530 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006531 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006532 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006533 }
6534 for (int p = packages.size() - 1; p >= 0; p--) {
6535 PackageInfo pkgInfo = packages.get(p);
6536 if (pkgInfo != null && pkgInfo.packageName != null
6537 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006538 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006539 privilegedPackages.add(pkgInfo.packageName);
6540 }
6541 }
6542 }
6543 }
6544 return privilegedPackages;
6545 }
6546
chen xuf7e9fe82019-05-09 19:31:02 -07006547 @Override
6548 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006549 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6550
6551 final long identity = Binder.clearCallingIdentity();
6552
chen xuf7e9fe82019-05-09 19:31:02 -07006553 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006554 try {
6555 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6556 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6557 }
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006560 }
6561 return privilegedPackages;
6562 }
6563
Wink Savilleb564aae2014-10-23 10:18:09 -07006564 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006565 final Phone phone = getPhone(subId);
6566 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006567 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006568 return null;
6569 }
6570 String iccId = card.getIccId();
6571 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006572 return null;
6573 }
6574 return iccId;
6575 }
6576
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006577 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006578 public void setCallComposerStatus(int subId, int status) {
6579 enforceModifyPermission();
6580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 Phone phone = getPhone(subId);
6584 if (phone != null) {
6585 Phone defaultPhone = phone.getImsPhone();
6586 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6587 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6588 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006589 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6590 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006591 }
6592 }
Shuo Qiand8782462020-12-22 19:10:14 -08006593 } catch (ImsException e) {
6594 throw new ServiceSpecificException(e.getCode());
6595 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006596 Binder.restoreCallingIdentity(identity);
6597 }
6598 }
6599
6600 @Override
6601 public int getCallComposerStatus(int subId) {
6602 enforceReadPrivilegedPermission("getCallComposerStatus");
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 Phone phone = getPhone(subId);
6607 if (phone != null) {
6608 Phone defaultPhone = phone.getImsPhone();
6609 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6610 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6611 return imsPhone.getCallComposerStatus();
6612 }
6613 }
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6618 }
6619
6620 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006621 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6622 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006623 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006624 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 final long identity = Binder.clearCallingIdentity();
6627 try {
6628 final String iccId = getIccId(subId);
6629 final Phone phone = getPhone(subId);
6630 if (phone == null) {
6631 return false;
6632 }
6633 final String subscriberId = phone.getSubscriberId();
6634
6635 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006636 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 + subscriberId + " to " + number);
6638 }
6639
6640 if (TextUtils.isEmpty(iccId)) {
6641 return false;
6642 }
6643
6644 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6645
6646 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6647 if (alphaTag == null) {
6648 editor.remove(alphaTagPrefKey);
6649 } else {
6650 editor.putString(alphaTagPrefKey, alphaTag);
6651 }
6652
6653 // Record both the line number and IMSI for this ICCID, since we need to
6654 // track all merged IMSIs based on line number
6655 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6656 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6657 if (number == null) {
6658 editor.remove(numberPrefKey);
6659 editor.remove(subscriberPrefKey);
6660 } else {
6661 editor.putString(numberPrefKey, number);
6662 editor.putString(subscriberPrefKey, subscriberId);
6663 }
6664
6665 editor.commit();
6666 return true;
6667 } finally {
6668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006669 }
Derek Tan7226c842014-07-02 17:42:23 -07006670 }
6671
6672 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006673 public String getLine1NumberForDisplay(int subId, String callingPackage,
6674 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006675 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006677 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006678 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006679 return null;
6680 }
Derek Tan97ebb422014-09-05 16:55:38 -07006681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 String iccId = getIccId(subId);
6685 if (iccId != null) {
6686 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6687 if (DBG_MERGE) {
6688 log("getLine1NumberForDisplay returning "
6689 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6690 }
6691 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6694 return null;
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006697 }
Derek Tan7226c842014-07-02 17:42:23 -07006698 }
6699
6700 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006701 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6702 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006704 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006705 return null;
6706 }
Derek Tan97ebb422014-09-05 16:55:38 -07006707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 final long identity = Binder.clearCallingIdentity();
6709 try {
6710 String iccId = getIccId(subId);
6711 if (iccId != null) {
6712 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6713 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6714 }
6715 return null;
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006718 }
Derek Tan7226c842014-07-02 17:42:23 -07006719 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006720
6721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006722 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6723 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006724 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6725 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006727 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006728 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006729 return null;
6730 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006731
Jordan Liub49b04b2019-05-06 14:45:15 -07006732 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6733 // the process, where TelephonyManager was instantiated.
6734 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006735 final long identity = Binder.clearCallingIdentity();
6736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006737 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 final TelephonyManager tele = TelephonyManager.from(context);
6739 final SubscriptionManager sub = SubscriptionManager.from(context);
6740
6741 // Figure out what subscribers are currently active
6742 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743
Jordan Liub49b04b2019-05-06 14:45:15 -07006744 // Only consider subs which match the current subId
6745 // This logic can be simplified. See b/131189269 for progress.
6746 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006747 activeSubscriberIds.add(tele.getSubscriberId(subId));
6748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749
6750 // First pass, find a number override for an active subscriber
6751 String mergeNumber = null;
6752 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6753 for (String key : prefs.keySet()) {
6754 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6755 final String subscriberId = (String) prefs.get(key);
6756 if (activeSubscriberIds.contains(subscriberId)) {
6757 final String iccId = key.substring(
6758 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6759 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6760 mergeNumber = (String) prefs.get(numberKey);
6761 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006762 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 + " for active subscriber " + subscriberId);
6764 }
6765 if (!TextUtils.isEmpty(mergeNumber)) {
6766 break;
6767 }
6768 }
6769 }
6770 }
6771
6772 // Shortcut when no active merged subscribers
6773 if (TextUtils.isEmpty(mergeNumber)) {
6774 return null;
6775 }
6776
6777 // Second pass, find all subscribers under that line override
6778 final ArraySet<String> result = new ArraySet<>();
6779 for (String key : prefs.keySet()) {
6780 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6781 final String number = (String) prefs.get(key);
6782 if (mergeNumber.equals(number)) {
6783 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6784 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6785 final String subscriberId = (String) prefs.get(subscriberKey);
6786 if (!TextUtils.isEmpty(subscriberId)) {
6787 result.add(subscriberId);
6788 }
6789 }
6790 }
6791 }
6792
6793 final String[] resultArray = result.toArray(new String[result.size()]);
6794 Arrays.sort(resultArray);
6795 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006796 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6798 }
6799 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006800 } finally {
6801 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006802 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006803 }
6804
6805 @Override
zoey chen38003472019-12-13 17:16:31 +08006806 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6807 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006808
6809 final long identity = Binder.clearCallingIdentity();
6810 try {
6811 final TelephonyManager telephonyManager = mApp.getSystemService(
6812 TelephonyManager.class);
6813 String subscriberId = telephonyManager.getSubscriberId(subId);
6814 if (subscriberId == null) {
6815 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006816 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006817 + subId);
6818 }
6819 return null;
6820 }
6821
6822 final SubscriptionInfo info = SubscriptionController.getInstance()
6823 .getSubscriptionInfo(subId);
6824 final ParcelUuid groupUuid = info.getGroupUuid();
6825 // If it doesn't belong to any group, return just subscriberId of itself.
6826 if (groupUuid == null) {
6827 return new String[]{subscriberId};
6828 }
6829
6830 // Get all subscriberIds from the group.
6831 final List<String> mergedSubscriberIds = new ArrayList<>();
6832 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006833 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006834 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006835 for (SubscriptionInfo subInfo : groupInfos) {
6836 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6837 if (subscriberId != null) {
6838 mergedSubscriberIds.add(subscriberId);
6839 }
6840 }
6841
6842 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845
6846 }
6847 }
6848
6849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006850 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006851 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006852 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853
6854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 final Phone phone = getPhone(subId);
6857 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6858 } finally {
6859 Binder.restoreCallingIdentity(identity);
6860 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006861 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006862
6863 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006864 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006865 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6866 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6868 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
6872 final Phone phone = getPhone(subId);
6873 if (phone == null) {
6874 return false;
6875 }
6876 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6877 cdmaNonRoamingList);
6878 } finally {
6879 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006880 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006881 }
6882
6883 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006884 @Deprecated
6885 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6886 enforceModifyPermission();
6887
6888 int returnValue = 0;
6889 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006890 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006891 if(result.exception == null) {
6892 if (result.result != null) {
6893 byte[] responseData = (byte[])(result.result);
6894 if(responseData.length > oemResp.length) {
6895 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6896 responseData.length + "bytes. Buffer Size is " +
6897 oemResp.length + "bytes.");
6898 }
6899 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6900 returnValue = responseData.length;
6901 }
6902 } else {
6903 CommandException ex = (CommandException) result.exception;
6904 returnValue = ex.getCommandError().ordinal();
6905 if(returnValue > 0) returnValue *= -1;
6906 }
6907 } catch (RuntimeException e) {
6908 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6909 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6910 if(returnValue > 0) returnValue *= -1;
6911 }
6912
6913 return returnValue;
6914 }
6915
6916 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006917 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006918 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006919 try {
6920 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006921 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006922 mApp, phone.getSubId(), "getRadioAccessFamily");
6923 } catch (SecurityException e) {
6924 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6925 throw e;
6926 }
chen xub97461a2018-10-26 14:17:57 -07006927 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006928 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006929 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 final long identity = Binder.clearCallingIdentity();
6932 try {
chen xub97461a2018-10-26 14:17:57 -07006933 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006934 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07006935 mApp, phone.getSubId(), "getRadioAccessFamily");
6936 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 } finally {
6938 Binder.restoreCallingIdentity(identity);
6939 }
chen xub97461a2018-10-26 14:17:57 -07006940 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006941 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006942
6943 @Override
6944 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006945 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947
6948 final long identity = Binder.clearCallingIdentity();
6949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006950 ImsManager.getInstance(defaultPhone.getContext(),
6951 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006955 }
6956
6957 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006958 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006959 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6961 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006962 return false;
6963 }
Svet Ganovb320e182015-04-16 12:30:10 -07006964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 final long identity = Binder.clearCallingIdentity();
6966 try {
6967 // Check the user preference and the system-level IMS setting. Even if the user has
6968 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6969 // In the long run, we may instead need to check if there exists a connection service
6970 // which can support video calling.
6971 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006972 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 return imsManager.isVtEnabledByPlatform()
6974 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6975 && imsManager.isVtEnabledByUser();
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
6978 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006979 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006980
Andrew Leea1239f22015-03-02 17:44:07 -08006981 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006982 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6983 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006985 mApp, subId, callingPackage, callingFeatureId,
6986 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 return false;
6988 }
6989
6990 final long identity = Binder.clearCallingIdentity();
6991 try {
6992 CarrierConfigManager configManager =
6993 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006994 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
6998 }
Andrew Leea1239f22015-03-02 17:44:07 -08006999 }
7000
7001 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007002 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007004 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 return false;
7006 }
7007
7008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 CarrierConfigManager configManager =
7011 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007012 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
Andrew Leea1239f22015-03-02 17:44:07 -08007017 }
7018
Andrew Lee9431b832015-03-09 18:46:45 -07007019 @Override
7020 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007021 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007022 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007023 }
7024
7025 @Override
7026 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007029 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 } finally {
7031 Binder.restoreCallingIdentity(identity);
7032 }
Andrew Lee9431b832015-03-09 18:46:45 -07007033 }
7034
Hall Liuf6668912018-10-31 17:05:23 -07007035 /**
7036 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7037 * support for the feature and device firmware support.
7038 *
7039 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7040 */
7041 @Override
7042 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007044 final Phone phone = getPhone(subscriptionId);
7045 if (phone == null) {
7046 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7047 return false;
7048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007050 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7052 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007053 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 return isCarrierSupported && isDeviceSupported;
7055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
Hall Liu98187582018-01-22 19:15:32 -08007058 }
7059
Hall Liuf6668912018-10-31 17:05:23 -07007060 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007061 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7062 * RTT setting, will return true if the device and carrier both support RTT.
7063 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007064 */
7065 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 final long identity = Binder.clearCallingIdentity();
7067 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007068 boolean isRttSupported = isRttSupported(subscriptionId);
7069 boolean isUserRttSettingOn = Settings.Secure.getInt(
7070 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7071 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7072 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7073 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 } finally {
7075 Binder.restoreCallingIdentity(identity);
7076 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007077 }
7078
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007079 @Deprecated
7080 @Override
7081 public String getDeviceId(String callingPackage) {
7082 return getDeviceIdWithFeature(callingPackage, null);
7083 }
7084
Sanket Padawe7310cc72015-01-14 09:53:20 -08007085 /**
7086 * Returns the unique device ID of phone, for example, the IMEI for
7087 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7088 *
7089 * <p>Requires Permission:
7090 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7091 */
7092 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007093 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007094 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007095 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007096 return null;
7097 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007098 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007099 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007100 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007101 return null;
7102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 return phone.getDeviceId();
7107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007110 }
7111
Ping Sunc67b7c22016-03-02 19:16:45 +08007112 /**
7113 * {@hide}
7114 * Returns the IMS Registration Status on a particular subid
7115 *
7116 * @param subId
7117 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007118 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007119 Phone phone = getPhone(subId);
7120 if (phone != null) {
7121 return phone.isImsRegistered();
7122 } else {
7123 return false;
7124 }
7125 }
7126
Santos Cordon7a1885b2015-02-03 11:15:19 -08007127 @Override
7128 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007135 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007136
Tyler Gunnf70ed162019-04-03 15:28:53 -07007137 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007138 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007139 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007141 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007142 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7143 }
7144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
7149 }
7150 }
7151
7152 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007153 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007154 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7155 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 Phone phone = getPhone(subscriptionId);
7159 if (phone == null) {
7160 return null;
7161 }
7162 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
7166 }
7167
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007168 /**
7169 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007170 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007171 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 Phone phone = getPhone(subId);
7175 if (phone != null) {
7176 return phone.isWifiCallingEnabled();
7177 } else {
7178 return false;
7179 }
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007182 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007183 }
7184
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007185 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007186 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007187 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007188 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 final long identity = Binder.clearCallingIdentity();
7190 try {
7191 Phone phone = getPhone(subId);
7192 if (phone != null) {
7193 return phone.isVideoEnabled();
7194 } else {
7195 return false;
7196 }
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007199 }
7200 }
7201
7202 /**
7203 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7204 * defined in {@link ImsRegistrationImplBase}.
7205 */
7206 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 final long identity = Binder.clearCallingIdentity();
7208 try {
7209 Phone phone = getPhone(subId);
7210 if (phone != null) {
7211 return phone.getImsRegistrationTech();
7212 } else {
7213 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7214 }
7215 } finally {
7216 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007217 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007218 }
7219
Stuart Scott8eef64f2015-04-08 15:13:54 -07007220 @Override
7221 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007222 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007223 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7224 return;
7225 }
7226
Svet Ganovcc087f82015-05-12 20:35:54 -07007227 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007228
Svet Ganovcc087f82015-05-12 20:35:54 -07007229 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007230 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7231 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007232 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007233 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007234 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007235 Phone phone = getPhone(subId);
7236 if (phone != null) {
7237 SubscriptionManager.setSubscriptionProperty(subId,
7238 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7239 "user=" + RadioAccessFamily.getRafFromNetworkType(
7240 RILConstants.PREFERRED_NETWORK_MODE));
7241 phone.loadAllowedNetworksFromSubscriptionDatabase();
7242 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007243 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7244 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007245 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007246 // There has been issues when Sms raw table somehow stores orphan
7247 // fragments. They lead to garbled message when new fragments come
7248 // in and combined with those stale ones. In case this happens again,
7249 // user can reset all network settings which will clean up this table.
7250 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007251 // Clean up IMS settings as well here.
7252 int slotId = getSlotIndex(subId);
7253 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7254 ImsManager.getInstance(mApp, slotId).factoryReset();
7255 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007256
7257 // Erase modem config if erase modem on network setting is enabled.
7258 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7259 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7260 if (configValue != null && Boolean.parseBoolean(configValue)) {
7261 sendEraseModemConfig(getDefaultPhone());
7262 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007263 } finally {
7264 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007265 }
7266 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007267
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007268 private void cleanUpSmsRawTable(Context context) {
7269 ContentResolver resolver = context.getContentResolver();
7270 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7271 resolver.delete(uri, null, null);
7272 }
7273
Narayan Kamath1c496c22015-04-16 14:40:19 +01007274 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007275 public String getSimLocaleForSubscriber(int subId) {
7276 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7277 final Phone phone = getPhone(subId);
7278 if (phone == null) {
7279 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007280 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
chen xu5d3637b2019-01-21 23:31:38 -08007284 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007285 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007286 if (info == null) {
7287 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7288 return null;
7289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 // Try and fetch the locale from the carrier properties or from the SIM language
7291 // preferences (EF-PL and EF-LI)...
7292 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007294 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7295 if (localeFromDefaultSim != null) {
7296 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7297 if (DBG) log("Using locale from subId: " + subId + " locale: "
7298 + localeFromDefaultSim);
7299 return localeFromDefaultSim.toLanguageTag();
7300 } else {
7301 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 }
7303 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 // The SIM language preferences only store a language (e.g. fr = French), not an
7306 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7307 // the SIM and carrier preferences does not include a country we add the country
7308 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007309 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007311 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 return mccLocale.toLanguageTag();
7313 }
7314
7315 if (DBG) log("No locale found - returning null");
7316 return null;
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007320 }
7321
7322 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007323 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007324 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007325 }
7326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 /**
7328 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7329 */
7330 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007331 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007332 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007333 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007334
Chenjie Yu1ba97252018-01-11 18:16:20 -08007335 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007336 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007337
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007338 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007339 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7340 * representing the state of the modem.
7341 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007342 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7343 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007344 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007345 */
7346 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007347 public void requestModemActivityInfo(ResultReceiver result) {
7348 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
sqian1a1be542020-03-05 11:37:28 -08007353 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007356 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007357 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007358
Siddharth Rayb8114062018-06-17 15:02:38 -07007359 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7360 // less than total activity duration.
7361 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7362 if (info == null) {
7363 return false;
7364 }
7365 int activityDurationMs =
7366 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7367 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007368 int[] txTimeMs = info.getTransmitTimeMillis();
7369 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7370 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007371 }
7372 return (info.isValid()
7373 && (info.getSleepTimeMillis() <= activityDurationMs)
7374 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007375 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007376 && (totalTxTimeMs <= activityDurationMs));
7377 }
7378
Jack Yu85bd38a2015-11-09 11:34:32 -08007379 /**
7380 * {@hide}
7381 * Returns the service state information on specified subscription.
7382 */
7383 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007384 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7385 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007387 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007388 return null;
7389 }
7390
Hall Liuf19c44f2018-11-27 14:38:17 -08007391 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7392 LocationAccessPolicy.checkLocationPermission(mApp,
7393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7394 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007395 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007396 .setCallingPid(Binder.getCallingPid())
7397 .setCallingUid(Binder.getCallingUid())
7398 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007399 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007400 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7401 .build());
7402
7403 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7404 LocationAccessPolicy.checkLocationPermission(mApp,
7405 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7406 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007407 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007408 .setCallingPid(Binder.getCallingPid())
7409 .setCallingUid(Binder.getCallingUid())
7410 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007411 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7413 .build());
7414 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7415 boolean hasFinePermission =
7416 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7417 boolean hasCoarsePermission =
7418 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 final long identity = Binder.clearCallingIdentity();
7421 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007422 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7423 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7424 Rlog.d(LOG_TAG,
7425 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7426 return null;
7427 }
7428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 final Phone phone = getPhone(subId);
7430 if (phone == null) {
7431 return null;
7432 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007433
Hall Liuf19c44f2018-11-27 14:38:17 -08007434 ServiceState ss = phone.getServiceState();
7435
7436 // Scrub out the location info in ServiceState depending on what level of access
7437 // the caller has.
7438 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007439 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7440 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007444 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007445
7446 /**
7447 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7448 *
7449 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7450 * voicemail ringtone.
7451 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7452 * PhoneAccount.
7453 */
7454 @Override
7455 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
7458 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7459 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007460 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007467 }
7468
7469 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007470 * Sets the per-account voicemail ringtone.
7471 *
7472 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7473 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7474 *
7475 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7476 * voicemail ringtone.
7477 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7478 * PhoneAccount.
7479 */
7480 @Override
7481 public void setVoicemailRingtoneUri(String callingPackage,
7482 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007485 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7486 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7488 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7489 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7495 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007496 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 }
7498 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007501 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007502 }
7503
7504 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007505 * Returns whether vibration is set for voicemail notification in Phone settings.
7506 *
7507 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7508 * voicemail vibration setting.
7509 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7510 */
7511 @Override
7512 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7516 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007524 }
7525
Youhan Wange64578a2016-05-02 15:32:42 -07007526 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007527 * Sets the per-account voicemail vibration.
7528 *
7529 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7530 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7531 *
7532 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7533 * voicemail vibration setting.
7534 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7535 * specific PhoneAccount.
7536 */
7537 @Override
7538 public void setVoicemailVibrationEnabled(String callingPackage,
7539 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007541 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007542 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7543 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7545 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7546 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007547 }
7548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7552 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007553 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 }
7555 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007558 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007559 }
7560
7561 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007562 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7563 *
7564 * @throws SecurityException if the caller does not have the required permission
7565 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007566 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007567 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007568 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007569 }
7570
7571 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007572 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7573 * permission.
7574 *
7575 * @throws SecurityException if the caller does not have the required permission
7576 */
7577 private void enforceSendSmsPermission() {
7578 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7579 }
7580
7581 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007582 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007583 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007584 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007585 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007586 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007590 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 if (componentName == null) {
7592 throw new SecurityException(
7593 "Caller not current active visual voicemail package[null]");
7594 }
7595 String vvmPackage = componentName.getPackageName();
7596 if (!callingPackage.equals(vvmPackage)) {
7597 throw new SecurityException("Caller not current active visual voicemail package["
7598 + vvmPackage + "]");
7599 }
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007602 }
7603 }
7604
7605 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007606 * Return the application ID for the app type.
7607 *
7608 * @param subId the subscription ID that this request applies to.
7609 * @param appType the uicc app type.
7610 * @return Application ID for specificied app type, or null if no uicc.
7611 */
7612 @Override
7613 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007614 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007615 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616
7617 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007618 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 if (phone == null) {
7620 return null;
7621 }
7622 String aid = null;
7623 try {
7624 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7625 .getApplicationByType(appType).getAid();
7626 } catch (Exception e) {
7627 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7628 }
7629 return aid;
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007632 }
Youhan Wange64578a2016-05-02 15:32:42 -07007633 }
7634
Youhan Wang4001d252016-05-11 10:29:41 -07007635 /**
7636 * Return the Electronic Serial Number.
7637 *
7638 * @param subId the subscription ID that this request applies to.
7639 * @return ESN or null if error.
7640 */
7641 @Override
7642 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007643 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007644 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645
7646 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007647 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 if (phone == null) {
7649 return null;
7650 }
7651 String esn = null;
7652 try {
7653 esn = phone.getEsn();
7654 } catch (Exception e) {
7655 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7656 }
7657 return esn;
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007660 }
Youhan Wang4001d252016-05-11 10:29:41 -07007661 }
7662
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007663 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007664 * Return the Preferred Roaming List Version.
7665 *
7666 * @param subId the subscription ID that this request applies to.
7667 * @return PRLVersion or null if error.
7668 */
7669 @Override
7670 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007671 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007672 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673
7674 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007675 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 if (phone == null) {
7677 return null;
7678 }
7679 String cdmaPrlVersion = null;
7680 try {
7681 cdmaPrlVersion = phone.getCdmaPrlVersion();
7682 } catch (Exception e) {
7683 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7684 }
7685 return cdmaPrlVersion;
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007688 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007689 }
7690
7691 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007692 * Get snapshot of Telephony histograms
7693 * @return List of Telephony histograms
7694 * @hide
7695 */
7696 @Override
7697 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7699 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 return RIL.getTelephonyRILTimingHistograms();
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007707 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007708
7709 /**
7710 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007711 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7712 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007713 * Require system privileges. In the future we may add this to carrier APIs.
7714 *
Michele Berionne482f8202018-11-27 18:57:59 -08007715 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007716 */
7717 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007718 @TelephonyManager.SetCarrierRestrictionResult
7719 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007720 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007722
Michele Berionne482f8202018-11-27 18:57:59 -08007723 if (carrierRestrictionRules == null) {
7724 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007725 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007729 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007730 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007734 }
7735
7736 /**
7737 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007738 * Get the allowed carrier list and the excluded carrier list, including the priority between
7739 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007740 * Require system privileges. In the future we may add this to carrier APIs.
7741 *
Michele Berionne482f8202018-11-27 18:57:59 -08007742 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007743 */
7744 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007745 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007746 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007751 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7752 if (response instanceof CarrierRestrictionRules) {
7753 return (CarrierRestrictionRules) response;
7754 }
7755 // Response is an Exception of some kind,
7756 // which is signalled to the user as a NULL retval
7757 return null;
7758 } catch (Exception e) {
7759 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7760 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007764 }
7765
fionaxu59545b42016-05-25 15:53:37 -07007766 /**
fionaxu59545b42016-05-25 15:53:37 -07007767 * Action set from carrier signalling broadcast receivers to enable/disable radio
7768 * @param subId the subscription ID that this action applies to.
7769 * @param enabled control enable or disable radio.
7770 * {@hide}
7771 */
7772 @Override
7773 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7774 enforceModifyPermission();
7775 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776
7777 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007778 if (phone == null) {
7779 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7780 return;
7781 }
7782 try {
7783 phone.carrierActionSetRadioEnabled(enabled);
7784 } catch (Exception e) {
7785 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 } finally {
7787 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007788 }
7789 }
7790
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007791 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007792 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7793 * network status based on which carrier apps could apply actions accordingly,
7794 * enable/disable default url handler for example.
7795 *
7796 * @param subId the subscription ID that this action applies to.
7797 * @param report control start/stop reporting the default network status.
7798 * {@hide}
7799 */
7800 @Override
7801 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7802 enforceModifyPermission();
7803 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804
7805 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007806 if (phone == null) {
7807 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7808 return;
7809 }
7810 try {
7811 phone.carrierActionReportDefaultNetworkStatus(report);
7812 } catch (Exception e) {
7813 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 } finally {
7815 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007816 }
7817 }
7818
7819 /**
fionaxud9622282017-07-17 17:51:30 -07007820 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7821 * @param subId the subscription ID that this action applies to.
7822 * {@hide}
7823 */
7824 @Override
7825 public void carrierActionResetAll(int subId) {
7826 enforceModifyPermission();
7827 final Phone phone = getPhone(subId);
7828 if (phone == null) {
7829 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7830 return;
7831 }
7832 try {
7833 phone.carrierActionResetAll();
7834 } catch (Exception e) {
7835 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7836 }
7837 }
7838
7839 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007840 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7841 * bug report is being generated.
7842 */
7843 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007844 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007845 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7846 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007847 writer.println("Permission Denial: can't dump Phone from pid="
7848 + Binder.getCallingPid()
7849 + ", uid=" + Binder.getCallingUid()
7850 + "without permission "
7851 + android.Manifest.permission.DUMP);
7852 return;
7853 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007854 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007855 }
Jack Yueb89b242016-06-22 13:27:47 -07007856
Brad Ebingerdac2f002018-04-03 15:17:52 -07007857 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007858 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7859 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7860 @NonNull String[] args) {
7861 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7862 this, in.getFileDescriptor(), out.getFileDescriptor(),
7863 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007864 }
7865
Jack Yueb89b242016-06-22 13:27:47 -07007866 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007867 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007868 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007869 * @param reason the reason the data enable change is taking place
7870 * @param enabled True if enabling the data, otherwise disabling.
7871 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007872 */
7873 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007874 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007875 boolean enabled) {
7876 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7877 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7878 try {
7879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007880 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007881 } catch (SecurityException se) {
7882 enforceModifyPermission();
7883 }
7884 } else {
7885 enforceModifyPermission();
7886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 Phone phone = getPhone(subId);
7891 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007892 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7893 phone.carrierActionSetMeteredApnsEnabled(enabled);
7894 } else {
7895 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 }
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007900 }
7901 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007902
7903 /**
7904 * Get Client request stats
7905 * @return List of Client Request Stats
7906 * @hide
7907 */
7908 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007909 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7910 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007911 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007912 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007913 return null;
7914 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007915 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 if (phone != null) {
7920 return phone.getClientRequestStats();
7921 }
7922
7923 return null;
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007927 }
7928
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007929 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007931 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007932 }
Jack Yueb4124c2017-02-16 15:32:43 -08007933
7934 /**
Grace Chen70990072017-03-24 17:21:30 -07007935 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007936 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007937 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007938 * @param state State of SIM (power down, power up, pass through)
7939 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7940 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7941 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007942 *
7943 **/
7944 @Override
Grace Chen70990072017-03-24 17:21:30 -07007945 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007946 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007947 Phone phone = PhoneFactory.getPhone(slotIndex);
7948
vagdeviaf9a5b92018-08-15 16:01:53 -07007949 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007954 phone.setSimPowerState(state, null, workSource);
7955 }
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
7959 }
7960
7961 /**
7962 * Set SIM card power state.
7963 *
7964 * @param slotIndex SIM slot id.
7965 * @param state State of SIM (power down, power up, pass through)
7966 * @param callback callback to trigger after success or failure
7967 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7968 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7969 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7970 *
7971 **/
7972 @Override
7973 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7974 IIntegerConsumer callback) {
7975 enforceModifyPermission();
7976 Phone phone = PhoneFactory.getPhone(slotIndex);
7977
7978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7979
7980 final long identity = Binder.clearCallingIdentity();
7981 try {
7982 if (phone != null) {
7983 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7984 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 }
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007988 }
7989 }
Shuo Qiandd210312017-04-12 22:11:33 +00007990
Tyler Gunn65d45c22017-06-05 11:22:26 -07007991 private boolean isUssdApiAllowed(int subId) {
7992 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007993 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007994 if (configManager == null) {
7995 return false;
7996 }
7997 PersistableBundle pb = configManager.getConfigForSubId(subId);
7998 if (pb == null) {
7999 return false;
8000 }
8001 return pb.getBoolean(
8002 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8003 }
8004
Shuo Qiandd210312017-04-12 22:11:33 +00008005 /**
8006 * Check if phone is in emergency callback mode
8007 * @return true if phone is in emergency callback mode
8008 * @param subId sub id
8009 */
goneil9c5f4872017-12-05 14:07:56 -08008010 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008011 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008012 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014
8015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 if (phone != null) {
8018 return phone.isInEcm();
8019 } else {
8020 return false;
8021 }
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008024 }
8025 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008026
8027 /**
8028 * Get the current signal strength information for the given subscription.
8029 * Because this information is not updated when the device is in a low power state
8030 * it should not be relied-upon to be current.
8031 * @param subId Subscription index
8032 * @return the most recent cached signal strength info from the modem
8033 */
8034 @Override
8035 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 final long identity = Binder.clearCallingIdentity();
8037 try {
8038 Phone p = getPhone(subId);
8039 if (p == null) {
8040 return null;
8041 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 return p.getSignalStrength();
8044 } finally {
8045 Binder.restoreCallingIdentity(identity);
8046 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008047 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008048
Pengquan Meng77b7f132018-08-22 14:49:57 -07008049 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008050 * Get the current modem radio state for the given slot.
8051 * @param slotIndex slot index.
8052 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008053 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008054 * @return the current radio power state from the modem
8055 */
8056 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008057 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008058 Phone phone = PhoneFactory.getPhone(slotIndex);
8059 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8061 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008062 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8063 }
8064
8065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 return phone.getRadioPowerState();
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
8070 }
8071 }
8072 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8073 }
8074
8075 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008076 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8077 *
8078 * <p>Requires one of the following permissions:
8079 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8080 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8081 * privileges.
8082 *
8083 * @param subId subscription id
8084 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8085 * {@code false}.
8086 */
8087 @Override
8088 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008089 try {
8090 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8091 null);
8092 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008093 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008094 mApp, subId, "isDataRoamingEnabled");
8095 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008096
Pengquan Menga1bb6272018-09-06 09:59:22 -07008097 boolean isEnabled = false;
8098 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008099 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008100 Phone phone = getPhone(subId);
8101 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008102 } finally {
8103 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008104 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008105 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008106 }
8107
8108
8109 /**
8110 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8111 *
8112 * <p> Requires permission:
8113 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8114 * privileges.
8115 *
8116 * @param subId subscription id
8117 * @param isEnabled {@code true} means enable, {@code false} means disable.
8118 */
8119 @Override
8120 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8122 mApp, subId, "setDataRoamingEnabled");
8123
Pengquan Menga1bb6272018-09-06 09:59:22 -07008124 final long identity = Binder.clearCallingIdentity();
8125 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008126 Phone phone = getPhone(subId);
8127 if (phone != null) {
8128 phone.setDataRoamingEnabled(isEnabled);
8129 }
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008132 }
8133 }
8134
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008135 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008136 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008137 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008138 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008139 mApp, subId, "isManualNetworkSelectionAllowed");
8140
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008141 boolean isAllowed = true;
8142 final long identity = Binder.clearCallingIdentity();
8143 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008144 Phone phone = getPhone(subId);
8145 if (phone != null) {
8146 isAllowed = phone.isCspPlmnEnabled();
8147 }
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 return isAllowed;
8152 }
8153
8154 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008155 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008156 // Verify that tha callingPackage belongs to the calling UID
8157 mApp.getSystemService(AppOpsManager.class)
8158 .checkPackage(Binder.getCallingUid(), callingPackage);
8159
Jordan Liu1e142fc2019-04-22 15:10:43 -07008160 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008161 try {
8162 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008163 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008164 } catch (SecurityException e) {
8165 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8166 // has carrier privileges on an active UICC
8167 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8168 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008169 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008170 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008171 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008172
8173 final long identity = Binder.clearCallingIdentity();
8174 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008175 UiccController uiccController = UiccController.getInstance();
8176 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008177 if (hasReadPermission) {
8178 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008179 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008180
8181 // Remove private info if the caller doesn't have access
8182 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8183 for (UiccCardInfo cardInfo : cardInfos) {
8184 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8185 // is available
8186 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8187 if (card == null || card.getUiccProfile() == null) {
8188 // assume no access if the card or profile is unavailable
8189 filteredInfos.add(cardInfo.getUnprivileged());
8190 continue;
8191 }
8192 UiccProfile profile = card.getUiccProfile();
8193 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8194 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8195 filteredInfos.add(cardInfo);
8196 } else {
8197 filteredInfos.add(cardInfo.getUnprivileged());
8198 }
8199 }
8200 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
8204 }
8205
8206 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008207 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008208 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8213 if (slots == null) {
8214 Rlog.i(LOG_TAG, "slots is null.");
8215 return null;
8216 }
8217
8218 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8219 for (int i = 0; i < slots.length; i++) {
8220 UiccSlot slot = slots[i];
8221 if (slot == null) {
8222 continue;
8223 }
8224
Jordan Liu7be7e652019-05-06 18:55:02 +00008225 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 UiccCard card = slot.getUiccCard();
8227 if (card != null) {
8228 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008229 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008230 cardId = slot.getEid();
8231 if (TextUtils.isEmpty(cardId)) {
8232 cardId = slot.getIccId();
8233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 }
8235
Jordan Liu857451f2019-05-09 16:35:35 -07008236 if (cardId != null) {
8237 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8238 // if cardId is an EID, it's all digits so this is fine
8239 cardId = IccUtils.stripTrailingFs(cardId);
8240 }
8241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 int cardState = 0;
8243 switch (slot.getCardState()) {
8244 case CARDSTATE_ABSENT:
8245 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8246 break;
8247 case CARDSTATE_PRESENT:
8248 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8249 break;
8250 case CARDSTATE_ERROR:
8251 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8252 break;
8253 case CARDSTATE_RESTRICTED:
8254 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8255 break;
8256 default:
8257 break;
8258
8259 }
8260
8261 infos[i] = new UiccSlotInfo(
8262 slot.isActive(),
8263 slot.isEuicc(),
8264 cardId,
8265 cardState,
8266 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008267 slot.isExtendedApduSupported(),
8268 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 }
8270 return infos;
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008273 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008274 }
8275
8276 @Override
8277 public boolean switchSlots(int[] physicalSlots) {
8278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279
8280 final long identity = Binder.clearCallingIdentity();
8281 try {
8282 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008286 }
Jack Yu4c988042018-02-27 15:30:01 -08008287
8288 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008289 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008290 final long identity = Binder.clearCallingIdentity();
8291 try {
8292 return UiccController.getInstance().getCardIdForDefaultEuicc();
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
8297
Pengquan Meng85728fb2018-03-12 16:31:21 -07008298 /**
goneil47ffb6e2018-04-06 15:40:58 -07008299 * A test API to reload the UICC profile.
8300 *
8301 * <p>Requires that the calling app has permission
8302 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8303 * @hide
8304 */
8305 @Override
8306 public void refreshUiccProfile(int subId) {
8307 enforceModifyPermission();
8308
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 Phone phone = getPhone(subId);
8312 if (phone == null) {
8313 return;
8314 }
8315 UiccCard uiccCard = phone.getUiccCard();
8316 if (uiccCard == null) {
8317 return;
8318 }
8319 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8320 if (uiccProfile == null) {
8321 return;
8322 }
8323 uiccProfile.refresh();
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
8329 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008330 * Returns false if the mobile data is disabled by default, otherwise return true.
8331 */
8332 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008333 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008334 }
8335
8336 /**
8337 * Returns true if the data roaming is enabled by default, i.e the system property
8338 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8339 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8340 */
8341 private boolean getDefaultDataRoamingEnabled(int subId) {
8342 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008343 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008344 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008345 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8346 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8347 return isDataRoamingEnabled;
8348 }
8349
8350 /**
8351 * Returns the default network type for the given {@code subId}, if the default network type is
8352 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8353 */
8354 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008355 List<Integer> list = TelephonyProperties.default_network();
8356 int phoneId = mSubscriptionController.getPhoneId(subId);
8357 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8358 return list.get(phoneId);
8359 }
8360 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008361 }
fionaxua13278b2018-03-21 00:08:13 -07008362
8363 @Override
8364 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008365 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008366 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 final Phone phone = getPhone(subId);
8371 if (phone == null) {
8372 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8373 return;
8374 }
chen xueaba88a2019-03-15 13:15:10 -07008375 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8376 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008377 if (carrierPrivilegeRules == null) {
8378 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8379 } else {
8380 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382 } finally {
8383 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008384 }
fionaxua13278b2018-03-21 00:08:13 -07008385 }
8386
8387 @Override
8388 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008389 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 final Phone phone = getPhone(subId);
8394 if (phone == null) {
8395 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8396 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8397 }
8398 return phone.getCarrierIdListVersion();
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008401 }
fionaxua13278b2018-03-21 00:08:13 -07008402 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008403
8404 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008405 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8406 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008408 mApp, subId, callingPackage, callingFeatureId,
8409 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008410 return -1;
8411 }
8412
8413 final long identity = Binder.clearCallingIdentity();
8414 try {
8415 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8416 } finally {
8417 Binder.restoreCallingIdentity(identity);
8418 }
8419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008420
8421 @Override
8422 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008423 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008424 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008425 mApp, subId, "getCdmaRoamingMode");
8426
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
8432 }
8433 }
8434
8435 @Override
8436 public boolean setCdmaRoamingMode(int subId, int mode) {
8437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8438 mApp, subId, "setCdmaRoamingMode");
8439
8440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
8446 }
8447
8448 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008449 public int getCdmaSubscriptionMode(int subId) {
8450 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008451 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008452 mApp, subId, "getCdmaSubscriptionMode");
8453
8454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
8460 }
8461
8462 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008463 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8465 mApp, subId, "setCdmaSubscriptionMode");
8466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
8472 }
8473 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008474
sqianc5eccab2018-10-19 18:46:41 -07008475 @Override
sqian8c685422019-02-22 15:55:18 -08008476 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008477 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008479 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8480 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008481 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8482 }
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
sqian854d44b2018-12-12 16:48:18 -08008485 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8486 for (Phone phone: PhoneFactory.getPhones()) {
8487 if (phone.getEmergencyNumberTracker() != null
8488 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8489 emergencyNumberListInternal.put(
8490 phone.getSubId(),
8491 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8492 }
sqian11b7a0e2018-12-05 18:48:28 -08008493 }
sqian854d44b2018-12-12 16:48:18 -08008494 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008495 } finally {
8496 Binder.restoreCallingIdentity(identity);
8497 }
sqianc5eccab2018-10-19 18:46:41 -07008498 }
8499
8500 @Override
sqian8c685422019-02-22 15:55:18 -08008501 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008502 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008503 if (!exactMatch) {
8504 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008505 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008506 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008507 }
8508 final long identity = Binder.clearCallingIdentity();
8509 try {
sqian854d44b2018-12-12 16:48:18 -08008510 for (Phone phone: PhoneFactory.getPhones()) {
8511 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008512 && phone.getEmergencyNumberTracker()
8513 .isEmergencyNumber(number, exactMatch)) {
8514 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008515 }
sqian11b7a0e2018-12-05 18:48:28 -08008516 }
8517 return false;
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
sqianf4ca7ed2019-01-15 18:32:07 -08008523 /**
8524 * Update emergency number list for test mode.
8525 */
8526 @Override
8527 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8528 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8529 "updateEmergencyNumberListTestMode");
8530
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 for (Phone phone: PhoneFactory.getPhones()) {
8534 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8535 if (tracker != null) {
8536 tracker.executeEmergencyNumberTestModeCommand(action, num);
8537 }
8538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
8542 }
8543
8544 /**
8545 * Get the full emergency number list for test mode.
8546 */
8547 @Override
8548 public List<String> getEmergencyNumberListTestMode() {
8549 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8550 "getEmergencyNumberListTestMode");
8551
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
8554 Set<String> emergencyNumbers = new HashSet<>();
8555 for (Phone phone: PhoneFactory.getPhones()) {
8556 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8557 if (tracker != null) {
8558 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8559 emergencyNumbers.add(num.getNumber());
8560 }
8561 }
8562 }
8563 return new ArrayList<>(emergencyNumbers);
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
chen xud6b45bd2018-10-30 22:27:10 -07008569 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008570 public int getEmergencyNumberDbVersion(int subId) {
8571 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 final Phone phone = getPhone(subId);
8576 if (phone == null) {
8577 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8578 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8579 }
8580 return phone.getEmergencyNumberDbVersion();
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
8585
8586 @Override
8587 public void notifyOtaEmergencyNumberDbInstalled() {
8588 enforceModifyPermission();
8589
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 for (Phone phone: PhoneFactory.getPhones()) {
8593 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8594 if (tracker != null) {
8595 tracker.updateOtaEmergencyNumberDatabase();
8596 }
8597 }
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
8601 }
8602
8603 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008604 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008605 enforceActiveEmergencySessionPermission();
8606
8607 final long identity = Binder.clearCallingIdentity();
8608 try {
8609 for (Phone phone: PhoneFactory.getPhones()) {
8610 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8611 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008612 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8613 }
8614 }
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
8617 }
8618 }
8619
8620 @Override
8621 public void resetOtaEmergencyNumberDbFilePath() {
8622 enforceActiveEmergencySessionPermission();
8623
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
8626 for (Phone phone: PhoneFactory.getPhones()) {
8627 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8628 if (tracker != null) {
8629 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008630 }
8631 }
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008638 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8639 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8640 Phone phone = getPhone(subId);
8641 if (phone == null) {
8642 return null;
8643 }
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 UiccProfile profile = UiccController.getInstance()
8647 .getUiccProfileForPhone(phone.getPhoneId());
8648 if (profile != null) {
8649 return profile.getCertsFromCarrierPrivilegeAccessRules();
8650 }
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
8654 return null;
8655 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008656
8657 /**
8658 * Enable or disable a modem stack.
8659 */
8660 @Override
8661 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8662 enforceModifyPermission();
8663
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
8666 Phone phone = PhoneFactory.getPhone(slotIndex);
8667 if (phone == null) {
8668 return false;
8669 } else {
8670 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8671 }
8672 } finally {
8673 Binder.restoreCallingIdentity(identity);
8674 }
8675 }
Michelecea4cf22018-12-21 15:00:11 -08008676
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008677 /**
8678 * Whether a modem stack is enabled or not.
8679 */
8680 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008681 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8682 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008683 Phone phone = PhoneFactory.getPhone(slotIndex);
8684 if (phone == null) return false;
8685
8686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008687 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8688 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008689 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8690 }
8691
8692 final long identity = Binder.clearCallingIdentity();
8693 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008694 try {
8695 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8696 } catch (NoSuchElementException ex) {
8697 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8698 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703
Michelecea4cf22018-12-21 15:00:11 -08008704 @Override
Michele0ea7d782019-03-19 14:58:42 -07008705 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008706 enforceModifyPermission();
8707
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008711 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008712 .commit();
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 }
8717
8718 @Override
Michele0ea7d782019-03-19 14:58:42 -07008719 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008720 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008722 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8723 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008724 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008725 }
Michelecea4cf22018-12-21 15:00:11 -08008726
8727 final long identity = Binder.clearCallingIdentity();
8728 try {
Michele0ea7d782019-03-19 14:58:42 -07008729 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008730 } finally {
8731 Binder.restoreCallingIdentity(identity);
8732 }
8733 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008734
Michele0ea7d782019-03-19 14:58:42 -07008735 @TelephonyManager.IsMultiSimSupportedResult
8736 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008737 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8738 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8739 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008740 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8741 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008742 }
8743 // Check if the hardware supports multisim functionality. If usage of multisim is not
8744 // supported by the modem, indicate that it is restricted.
8745 PhoneCapability staticCapability =
8746 mPhoneConfigurationManager.getStaticPhoneCapability();
8747 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008748 loge("isMultiSimSupportedInternal: no static configuration available");
8749 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008750 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008751 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008752 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8753 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008754 }
8755 // Check if support of multiple SIMs is restricted by carrier
8756 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008757 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008758 }
8759
Michele0ea7d782019-03-19 14:58:42 -07008760 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008761 }
8762
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008763 /**
8764 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008765 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8766 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8767 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008768 * @param numOfSims number of active sims we want to switch to
8769 */
8770 @Override
8771 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008772 if (numOfSims == 1) {
8773 enforceModifyPermission();
8774 } else {
8775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8776 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8777 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008778 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008779
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008780 try {
Michele30b57b22019-03-01 12:01:14 -08008781 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008782 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008783 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8784 return;
8785 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008786 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
8790 }
8791
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008792 @Override
8793 public boolean isApplicationOnUicc(int subId, int appType) {
8794 enforceReadPrivilegedPermission("isApplicationOnUicc");
8795 Phone phone = getPhone(subId);
8796 if (phone == null) {
8797 return false;
8798 }
8799 final long identity = Binder.clearCallingIdentity();
8800 try {
8801 UiccCard uiccCard = phone.getUiccCard();
8802 if (uiccCard == null) {
8803 return false;
8804 }
8805 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8806 if (uiccProfile == null) {
8807 return false;
8808 }
8809 if (TelephonyManager.APPTYPE_SIM <= appType
8810 && appType <= TelephonyManager.APPTYPE_ISIM) {
8811 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8812 }
8813 return false;
8814 } finally {
8815 Binder.restoreCallingIdentity(identity);
8816 }
8817 }
8818
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008819 /**
chen xub4baa772019-04-03 10:23:41 -07008820 * Get whether making changes to modem configurations will trigger reboot.
8821 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008822 */
8823 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008824 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8825 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008827 mApp, subId, callingPackage, callingFeatureId,
8828 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008829 return false;
8830 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
8836 }
8837 }
8838
Nathan Harold29f5f052019-02-15 13:41:57 -08008839 private void updateModemStateMetrics() {
8840 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8841 // TODO: check the state for each modem if the api is ready.
8842 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8843 }
8844
Pengquan Meng3889a572019-01-23 11:16:29 -08008845 @Override
8846 public int[] getSlotsMapping() {
8847 enforceReadPrivilegedPermission("getSlotsMapping");
8848
8849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8852 // All logical slots should have a mapping to a physical slot.
8853 int[] logicalSlotsMapping = new int[phoneCount];
8854 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8855 for (int i = 0; i < slotInfos.length; i++) {
8856 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8857 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8858 }
8859 }
8860 return logicalSlotsMapping;
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
8864 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008865
8866 /**
8867 * Get the IRadio HAL Version
8868 */
8869 @Override
8870 public int getRadioHalVersion() {
8871 Phone phone = getDefaultPhone();
8872 if (phone == null) return -1;
8873 HalVersion hv = phone.getHalVersion();
8874 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8875 return hv.major * 100 + hv.minor;
8876 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008877
8878 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008879 * Get the current calling package name.
8880 * @return the current calling package name
8881 */
8882 @Override
8883 public String getCurrentPackageName() {
8884 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8885 }
8886
8887 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008888 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8889 * corresponding network requests on a subId.
8890 *
8891 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008892 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008893 * 2) APN is un-metered for this subscription, or
8894 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008895 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008896 *
8897 * @return whether data is allowed for a apn type.
8898 *
8899 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008900 */
8901 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008902 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008903 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8904 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008905
8906 // Now that all security checks passes, perform the operation as ourselves.
8907 final long identity = Binder.clearCallingIdentity();
8908 try {
8909 Phone phone = getPhone(subId);
8910 if (phone == null) return false;
8911
Jack Yu41407ee2019-05-13 16:54:09 -07008912 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008913 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
8918
8919 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008920 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008921 enforceReadPrivilegedPermission("isApnMetered");
8922
8923 // Now that all security checks passes, perform the operation as ourselves.
8924 final long identity = Binder.clearCallingIdentity();
8925 try {
8926 Phone phone = getPhone(subId);
8927 if (phone == null) return true; // By default return true.
8928
Jack Yu41407ee2019-05-13 16:54:09 -07008929 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008934
8935 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008936 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8937 int subscriptionId, IBooleanConsumer resultCallback) {
8938 enforceModifyPermission();
8939 long token = Binder.clearCallingIdentity();
8940 try {
8941 Phone phone = getPhone(subscriptionId);
8942 if (phone == null) {
8943 try {
8944 if (resultCallback != null) {
8945 resultCallback.accept(false);
8946 }
8947 } catch (RemoteException e) {
8948 // ignore
8949 }
8950 return;
8951 }
8952 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8953 Pair.create(specifiers, (x) -> {
8954 try {
8955 if (resultCallback != null) {
8956 resultCallback.accept(x);
8957 }
8958 } catch (RemoteException e) {
8959 // ignore
8960 }
8961 });
8962 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8963 } finally {
8964 Binder.restoreCallingIdentity(token);
8965 }
8966 }
8967
8968 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008969 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8970 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008971 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08008972 mApp, subId, "getSystemSelectionChannels");
8973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 List<RadioAccessSpecifier> specifiers =
8977 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8978 null, subId, workSource);
8979 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8980 return specifiers;
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
8986 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008987 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008988 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008989 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8990 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8991 if (iccRecords == null) {
8992 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8993 return false;
8994 }
8995 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8996 }
8997
8998 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008999 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9000 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009001 if (callingPackage == null) {
9002 callingPackage = getCurrentPackageName();
9003 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009004 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9005 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009006 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9007 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009008 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9009 }
9010 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9011 Intent intent = new Intent();
9012 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9013 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9014 // Bring up choose default SMS subscription dialog right now
9015 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9016 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9017 mApp.startActivity(intent);
9018 }
chen xud5ca2d52019-05-28 15:20:57 -07009019
9020 @Override
9021 public String getMmsUAProfUrl(int subId) {
9022 //TODO investigate if this API should require proper permission check in R b/133791609
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009025 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9026 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9027 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9028 return carrierUAProfUrl;
9029 }
chen xud5ca2d52019-05-28 15:20:57 -07009030 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9031 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9032 } finally {
9033 Binder.restoreCallingIdentity(identity);
9034 }
9035 }
9036
9037 @Override
9038 public String getMmsUserAgent(int subId) {
9039 //TODO investigate if this API should require proper permission check in R b/133791609
9040 final long identity = Binder.clearCallingIdentity();
9041 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009042 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9043 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9044 if (!TextUtils.isEmpty(carrierUserAgent)) {
9045 return carrierUserAgent;
9046 }
chen xud5ca2d52019-05-28 15:20:57 -07009047 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9048 .getString(com.android.internal.R.string.config_mms_user_agent);
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
Jack Yub07d4972019-05-28 16:12:25 -07009053
9054 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009055 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9056 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 Phone phone = getPhone(subscriptionId);
9061 if (phone == null) return false;
9062
9063 switch (policy) {
9064 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9065 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9066 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9067 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9068 default:
9069 throw new IllegalArgumentException(policy + " is not a valid policy");
9070 }
9071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
9075
9076 @Override
9077 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9078 boolean enabled) {
9079 enforceModifyPermission();
9080
9081 final long identity = Binder.clearCallingIdentity();
9082 try {
9083 Phone phone = getPhone(subscriptionId);
9084 if (phone == null) return;
9085
9086 switch (policy) {
9087 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9088 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9089 break;
9090 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9091 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9092 break;
9093 default:
9094 throw new IllegalArgumentException(policy + " is not a valid policy");
9095 }
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009101 /**
Hall Liub48cf452020-09-25 11:13:49 -07009102 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009103 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9104 * otherwise.
9105 */
9106 @Override
9107 public void setCepEnabled(boolean isCepEnabled) {
9108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9109
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
9112 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9113 for (Phone phone : PhoneFactory.getPhones()) {
9114 Phone defaultPhone = phone.getImsPhone();
9115 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9116 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9117 ImsPhoneCallTracker imsPhoneCallTracker =
9118 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9119 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9120 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9121 + imsPhone.getMsisdn());
9122 }
9123 }
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
allenwtsu46dcc572020-01-08 18:24:03 +08009128
9129 /**
9130 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9131 *
9132 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9133 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9134 * before being read.
9135 */
9136 @Override
9137 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9138 isCompressed) {
9139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9140 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009141 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9142 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9143 }
9144 if (!isImsAvailableOnDevice()) {
9145 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9146 "IMS not available on device.");
9147 }
9148
9149 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009150 try {
Hui Wang068ab862020-10-31 05:12:53 +00009151 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9152 } finally {
9153 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009154 }
9155 }
zoey chenf95ca592019-12-30 16:11:23 +08009156
9157 @Override
9158 public boolean isIccLockEnabled(int subId) {
9159 enforceReadPrivilegedPermission("isIccLockEnabled");
9160
9161 // Now that all security checks passes, perform the operation as ourselves.
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 Phone phone = getPhone(subId);
9165 if (phone != null && phone.getIccCard() != null) {
9166 return phone.getIccCard().getIccLockEnabled();
9167 } else {
9168 return false;
9169 }
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 /**
zoey chene02881a2019-12-30 16:11:23 +08009176 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009177 *
zoey chene02881a2019-12-30 16:11:23 +08009178 * @return an integer representing the status of IccLock enabled or disabled in the following
9179 * three cases:
9180 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9181 * successfully.
9182 * - Positive number and zero for remaining password attempts.
9183 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009184 *
9185 */
9186 @Override
9187 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9188 enforceModifyPermission();
9189
9190 Phone phone = getPhone(subId);
9191 if (phone == null) {
9192 return 0;
9193 }
9194 // Now that all security checks passes, perform the operation as ourselves.
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9198 new Pair<Boolean, String>(enabled, password), phone, null);
9199 return attemptsRemaining;
9200
9201 } catch (Exception e) {
9202 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
9206 return 0;
9207 }
9208
9209 /**
9210 * Change the ICC password used in ICC pin lock.
9211 *
zoey chene02881a2019-12-30 16:11:23 +08009212 * @return an integer representing the status of IccLock changed in the following three cases:
9213 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9214 * - Positive number and zero for remaining password attempts.
9215 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009216 *
9217 */
9218 @Override
9219 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9220 enforceModifyPermission();
9221
9222 Phone phone = getPhone(subId);
9223 if (phone == null) {
9224 return 0;
9225 }
9226 // Now that all security checks passes, perform the operation as ourselves.
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9230 new Pair<String, String>(oldPassword, newPassword), phone, null);
9231 return attemptsRemaining;
9232
9233 } catch (Exception e) {
9234 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 return 0;
9239 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009240
Peter Wangdafb9ac2020-01-15 14:13:38 -08009241 /**
9242 * Request for receiving user activity notification
9243 */
9244 @Override
9245 public void requestUserActivityNotification() {
9246 if (!mNotifyUserActivity.get()
9247 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9248 mNotifyUserActivity.set(true);
9249 }
9250 }
9251
9252 /**
9253 * Called when userActivity is signalled in the power manager.
9254 * This is safe to call from any thread, with any window manager locks held or not.
9255 */
9256 @Override
9257 public void userActivity() {
9258 // ***************************************
9259 // * Inherited from PhoneWindowManager *
9260 // ***************************************
9261 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9262 // WITH ITS LOCKS HELD.
9263 //
9264 // This code must be VERY careful about the locks
9265 // it acquires.
9266 // In fact, the current code acquires way too many,
9267 // and probably has lurking deadlocks.
9268
9269 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9270 throw new SecurityException("Only the OS may call notifyUserActivity()");
9271 }
9272
9273 if (mNotifyUserActivity.getAndSet(false)) {
9274 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9275 USER_ACTIVITY_NOTIFICATION_DELAY);
9276 }
9277 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009278
Malcolm Chen884180b2020-04-13 11:59:40 -07009279 @Override
9280 public boolean canConnectTo5GInDsdsMode() {
9281 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9282 }
Jack Yud10cdd42020-09-28 20:28:01 -07009283
9284 @Override
9285 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9286 String callingFeatureId) {
9287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9288 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9289 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9290 }
9291
9292 Phone phone = getPhone(subId);
9293 if (phone == null) {
9294 throw new RuntimeException("phone is not available");
9295 }
9296 // Now that all security checks passes, perform the operation as ourselves.
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 return phone.getEquivalentHomePlmns();
9300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
9303 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009304
Hui Wang0866fcc2020-10-12 12:14:23 -07009305 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009306 public boolean isRadioInterfaceCapabilitySupported(
9307 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009308 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009309 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009310 if (radioInterfaceCapabilities == null) {
9311 throw new RuntimeException("radio interface capabilities are not available");
9312 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009313 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009314 }
9315 }
9316
9317 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009318 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9319 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009320 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9321 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9322 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9324 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009325 if (DBG) {
9326 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9327 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9328 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9329 }
9330
9331 if (!SubscriptionManager.isValidSubscriptionId(subId)
9332 || appType < TelephonyManager.APPTYPE_UNKNOWN
9333 || appType > TelephonyManager.APPTYPE_ISIM
9334 || nafUrl == null || securityProtocol == null || callback == null) {
9335 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9336 if (callback != null) {
9337 try {
9338 callback.onAuthenticationFailure(
9339 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9340 } catch (RemoteException exception) {
9341 log("Fail to notify onAuthenticationFailure due to " + exception);
9342 }
9343 return;
9344 }
9345 }
9346
9347 final long token = Binder.clearCallingIdentity();
9348 try {
9349 getGbaManager(subId).bootstrapAuthenticationRequest(
9350 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9351 forceBootStrapping, callback));
9352 } finally {
9353 Binder.restoreCallingIdentity(token);
9354 }
9355 }
9356
Jack Nudelman24d51a52020-11-24 12:08:04 -08009357 /**
9358 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9359 * requested radio power state will actually be set. See {@link
9360 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9361 *
9362 * @param subId the subscription ID of the phone requesting to set the radio power state.
9363 * @param enable {@code true} if trying to turn radio on.
9364 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9365 * false}.
9366 */
9367 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9368 Phone phone = getPhone(subId);
9369 if (phone != null) {
9370 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9371 return true;
9372 }
9373 return false;
9374 }
9375
9376 private int handleDataThrottlingRequest(int subId,
9377 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009378 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9379 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9380 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9381 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9382 throw new IllegalArgumentException("modem does not support data throttling");
9383 }
9384
Jack Nudelman24d51a52020-11-24 12:08:04 -08009385 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9386 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9387 if (!setRadioPowerForThermal(subId, true)) {
9388 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9389 }
9390
9391 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9392
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009393 if (isDataThrottlingSupported) {
9394 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009395 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009396 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9397 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9398 } else if (thermalMitigationResult
9399 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9400 throw new IllegalArgumentException("modem does not support data throttling");
9401 }
9402 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009403 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009404
9405 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009406 }
9407
Jack Nudelman644b91a2021-03-12 14:09:48 -08009408 private static List<String> getThermalMitigationAllowlist(Context context) {
9409 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9410 for (String pckg : context.getResources()
9411 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9412 sThermalMitigationAllowlistedPackages.add(pckg);
9413 }
9414 }
9415
9416 return sThermalMitigationAllowlistedPackages;
9417 }
9418
9419 /**
9420 * Used by shell commands to add an authorized package name for thermal mitigation.
9421 * @param packageName name of package to be allowlisted
9422 * @param context
9423 */
9424 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9425 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9426 sThermalMitigationAllowlistedPackages.add(packageName);
9427 }
9428
9429 /**
9430 * Used by shell commands to remove an authorized package name for thermal mitigation.
9431 * @param packageName name of package to remove from allowlist
9432 * @param context
9433 */
9434 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9435 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9436 sThermalMitigationAllowlistedPackages.remove(packageName);
9437 }
9438
Jack Nudelman24d51a52020-11-24 12:08:04 -08009439 /**
9440 * Thermal mitigation request to control functionalities at modem.
9441 *
9442 * @param subId the id of the subscription.
9443 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009444 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009445 *
9446 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9447 */
9448 @Override
9449 @ThermalMitigationResult
9450 public int sendThermalMitigationRequest(
9451 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009452 ThermalMitigationRequest thermalMitigationRequest,
9453 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009454 enforceModifyPermission();
9455
Jack Nudelman644b91a2021-03-12 14:09:48 -08009456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9457 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9458 .contains(callingPackage)) {
9459 throw new SecurityException("Calling package must be configured in the device config. "
9460 + "calling package: " + callingPackage);
9461 }
9462
Jack Nudelman24d51a52020-11-24 12:08:04 -08009463 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9464 final long identity = Binder.clearCallingIdentity();
9465
9466 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9467 try {
9468 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9469 switch (thermalMitigationAction) {
9470 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9471 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009472 handleDataThrottlingRequest(subId,
9473 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009474 break;
9475 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9476 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9477 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9478 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9479 }
9480
9481 // Ensure that radio is on. If not able to power on due to phone being
9482 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9483 if (!setRadioPowerForThermal(subId, true)) {
9484 thermalMitigationResult =
9485 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9486 break;
9487 }
9488
9489 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9490 false);
9491 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9492 break;
9493 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9494 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9495 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9496 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9497 }
9498
9499 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9500 if (registry != null) {
9501 TelephonyConnectionService service =
9502 registry.getTelephonyConnectionService();
9503 Phone phone = getPhone(subId);
9504 if (phone == null) {
9505 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009506 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009507 break;
9508 }
9509
9510 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009511 != TelephonyManager.CALL_STATE_IDLE
9512 || phone.isInEmergencySmsMode() || phone.isInEcm()
9513 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009514 String errorMessage = "Phone state is not valid. call state = "
9515 + PhoneConstantConversions.convertCallState(phone.getState())
9516 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9517 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9518 errorMessage += service == null
9519 ? " TelephonyConnectionService is null"
9520 : " isEmergencyCallPending = "
9521 + service.isEmergencyCallPending();
9522 Log.e(LOG_TAG, errorMessage);
9523 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009524 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009525 break;
9526 }
9527 } else {
9528 thermalMitigationResult =
9529 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9530 break;
9531 }
9532
9533 // Turn radio off. If not able to power off due to phone being unavailable,
9534 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9535 if (!setRadioPowerForThermal(subId, false)) {
9536 thermalMitigationResult =
9537 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9538 break;
9539 }
9540 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009541 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009542 break;
9543 default:
9544 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9545 + "not exist. Requested action: " + thermalMitigationAction);
9546 }
9547 } catch (IllegalArgumentException e) {
9548 throw e;
9549 } catch (Exception e) {
9550 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9551 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555
9556 if (DBG) {
9557 log("thermalMitigationRequest returning with thermalMitigationResult: "
9558 + thermalMitigationResult);
9559 }
9560
9561 return thermalMitigationResult;
9562 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009563
9564 /**
9565 * Set the GbaService Package Name that Telephony will bind to.
9566 *
9567 * @param subId The sim that the GbaService is associated with.
9568 * @param packageName The name of the package to be replaced with.
9569 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9570 */
9571 @Override
9572 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9573 enforceModifyPermission();
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 return getGbaManager(subId).overrideServicePackage(packageName);
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 }
9582
9583 /**
9584 * Return the package name of the currently bound GbaService.
9585 *
9586 * @param subId The sim that the GbaService is associated with.
9587 * @return the package name of the GbaService configuration, null if GBA is not supported.
9588 */
9589 @Override
9590 public String getBoundGbaService(int subId) {
9591 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9592
9593 final long identity = Binder.clearCallingIdentity();
9594 try {
9595 return getGbaManager(subId).getServicePackage();
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
9598 }
9599 }
9600
9601 /**
9602 * Set the release time for telephony to unbind GbaService.
9603 *
9604 * @param subId The sim that the GbaService is associated with.
9605 * @param interval The release time to unbind GbaService by millisecond.
9606 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9607 */
9608 @Override
9609 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9610 enforceModifyPermission();
9611
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 return getGbaManager(subId).overrideReleaseTime(interval);
9615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
9619
9620 /**
9621 * Return the release time for telephony to unbind GbaService.
9622 *
9623 * @param subId The sim that the GbaService is associated with.
9624 * @return The release time to unbind GbaService by millisecond.
9625 */
9626 @Override
9627 public int getGbaReleaseTime(int subId) {
9628 enforceReadPrivilegedPermission("getGbaReleaseTime");
9629
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
9632 return getGbaManager(subId).getReleaseTime();
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
9637
9638 private GbaManager getGbaManager(int subId) {
9639 GbaManager instance = GbaManager.getInstance(subId);
9640 if (instance == null) {
9641 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9642 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9643 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9644 }
9645 return instance;
9646 }
Hui Wang068ab862020-10-31 05:12:53 +00009647
9648 /**
9649 * indicate whether the device and the carrier can support
9650 * RCS VoLTE single registration.
9651 */
9652 @Override
9653 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009654 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9655 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9656 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9657 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009658
9659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9660 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9661 }
9662
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
9665 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9666 if (rpm != null) {
9667 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9668 }
9669 return false;
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
9675 /**
9676 * Register RCS provisioning callback.
9677 */
9678 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009679 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009680 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009681 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009682 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009683 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9684 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009685
9686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9687 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9688 }
9689 if (!isImsAvailableOnDevice()) {
9690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9691 "IMS not available on device.");
9692 }
9693
9694 final long identity = Binder.clearCallingIdentity();
9695 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009696 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009697 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9699 "Service not available for the subscription.");
9700 }
Hui Wang068ab862020-10-31 05:12:53 +00009701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
9706 /**
9707 * Unregister RCS provisioning callback.
9708 */
9709 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009710 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009711 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009712 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009713 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009714 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9715 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009716
9717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9718 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9719 }
9720 if (!isImsAvailableOnDevice()) {
9721 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9722 "IMS not available on device.");
9723 }
9724
9725 final long identity = Binder.clearCallingIdentity();
9726 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009727 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009728 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
9735 * trigger RCS reconfiguration.
9736 */
9737 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009738 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9739 "triggerRcsReconfiguration",
9740 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009741
9742 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9743 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9744 }
9745 if (!isImsAvailableOnDevice()) {
9746 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9747 "IMS not available on device.");
9748 }
9749
9750 final long identity = Binder.clearCallingIdentity();
9751 try {
9752 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
9756 }
9757
9758 /**
9759 * Provide the client configuration parameters of the RCS application.
9760 */
9761 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009762 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9763 "setRcsClientConfiguration",
9764 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009765
9766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9767 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9768 }
9769 if (!isImsAvailableOnDevice()) {
9770 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9771 "IMS not available on device.");
9772 }
9773
9774 final long identity = Binder.clearCallingIdentity();
9775
9776 try {
9777 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9778 if (configBinder == null) {
9779 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9780 } else {
9781 configBinder.setRcsClientConfiguration(rcc);
9782 }
9783 } catch (RemoteException e) {
9784 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9785 } finally {
9786 Binder.restoreCallingIdentity(identity);
9787 }
9788 }
9789
9790 /**
Hui Wang19a21872021-02-19 20:45:36 -08009791 * Enables or disables the test mode for RCS VoLTE single registration.
9792 */
9793 @Override
9794 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9796 "setRcsSingleRegistrationTestModeEnabled");
9797
9798 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9799 }
9800
9801 /**
9802 * Gets the test mode for RCS VoLTE single registration.
9803 */
9804 @Override
9805 public boolean getRcsSingleRegistrationTestModeEnabled() {
9806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9807 "getRcsSingleRegistrationTestModeEnabled");
9808
9809 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9810 }
9811
9812 /**
Hui Wang068ab862020-10-31 05:12:53 +00009813 * Overrides the config of RCS VoLTE single registration enabled for the device.
9814 */
9815 @Override
9816 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9818 "setDeviceSingleRegistrationEnabledOverride");
9819 enforceModifyPermission();
9820
9821 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9822 : Boolean.parseBoolean(enabledStr);
9823 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009824 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009825 }
9826
9827 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009828 * Sends a device to device communication message. Only usable via shell.
9829 * @param message message to send.
9830 * @param value message value.
9831 */
9832 @Override
9833 public void sendDeviceToDeviceMessage(int message, int value) {
9834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9835 "setCarrierSingleRegistrationEnabledOverride");
9836 enforceModifyPermission();
9837
9838 final long identity = Binder.clearCallingIdentity();
9839 try {
9840 TelephonyConnectionService service =
9841 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9842 if (service == null) {
9843 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9844 return;
9845 }
9846 service.sendTestDeviceToDeviceMessage(message, value);
9847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
9851
9852
9853 /**
Hui Wang068ab862020-10-31 05:12:53 +00009854 * Gets the config of RCS VoLTE single registration enabled for the device.
9855 */
9856 @Override
9857 public boolean getDeviceSingleRegistrationEnabled() {
9858 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9859 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9860 }
9861
9862 /**
9863 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9864 */
9865 @Override
9866 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9868 "setCarrierSingleRegistrationEnabledOverride");
9869 enforceModifyPermission();
9870
9871 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9872 : Boolean.parseBoolean(enabledStr);
9873 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9874 subId, enabled);
9875 }
9876
9877 /**
9878 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9879 */
9880 @Override
9881 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9882 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9883 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9884 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009885
9886 /**
Hui Wangeadb2562021-02-26 09:33:38 -08009887 * Overrides the ims feature validation result
9888 */
9889 @Override
9890 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
9891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9892 "setImsFeatureValidationOverride");
9893
9894 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9895 : Boolean.parseBoolean(enabledStr);
9896 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
9897 subId, enabled);
9898 }
9899
9900 /**
9901 * Gets the ims feature validation override value
9902 */
9903 @Override
9904 public boolean getImsFeatureValidationOverride(int subId) {
9905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9906 "getImsFeatureValidationOverride");
9907 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
9908 }
9909
9910 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +08009911 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9912 * their mobile plan.
9913 */
9914 @Override
9915 public String getMobileProvisioningUrl() {
9916 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9917 final long identity = Binder.clearCallingIdentity();
9918 try {
9919 return getDefaultPhone().getMobileProvisioningUrl();
9920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009924
James.cf Linbcdf8b32021-01-14 16:44:13 +08009925 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009926 * Get the EAB contact from the EAB database.
9927 */
9928 @Override
9929 public String getContactFromEab(String contact) {
9930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9931 enforceModifyPermission();
9932 final long identity = Binder.clearCallingIdentity();
9933 try {
9934 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9935 } finally {
9936 Binder.restoreCallingIdentity(identity);
9937 }
9938 }
9939
9940 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009941 * Remove the EAB contacts from the EAB database.
9942 */
9943 @Override
9944 public int removeContactFromEab(int subId, String contacts) {
9945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9946 enforceModifyPermission();
9947 final long identity = Binder.clearCallingIdentity();
9948 try {
9949 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009955 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009956 public boolean getDeviceUceEnabled() {
9957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9958 final long identity = Binder.clearCallingIdentity();
9959 try {
9960 return mApp.getDeviceUceEnabled();
9961 } finally {
9962 Binder.restoreCallingIdentity(identity);
9963 }
9964 }
9965
9966 @Override
9967 public void setDeviceUceEnabled(boolean isEnabled) {
9968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9969 final long identity = Binder.clearCallingIdentity();
9970 try {
9971 mApp.setDeviceUceEnabled(isEnabled);
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
9976
Brad Ebingerd4c5bde2021-02-12 06:18:28 +00009977 /**
9978 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
9979 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9980 */
9981 // Used for SHELL command only right now.
9982 @Override
9983 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
9984 List<String> featureTags) {
9985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9986 "addUceRegistrationOverrideShell");
9987 final long identity = Binder.clearCallingIdentity();
9988 try {
9989 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
9990 new ArraySet<>(featureTags));
9991 } catch (ImsException e) {
9992 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9993 } finally {
9994 Binder.restoreCallingIdentity(identity);
9995 }
9996 }
9997
9998 /**
9999 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10000 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10001 */
10002 // Used for SHELL command only right now.
10003 @Override
10004 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10005 List<String> featureTags) {
10006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10007 "removeUceRegistrationOverrideShell");
10008 final long identity = Binder.clearCallingIdentity();
10009 try {
10010 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10011 new ArraySet<>(featureTags));
10012 } catch (ImsException e) {
10013 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10014 } finally {
10015 Binder.restoreCallingIdentity(identity);
10016 }
10017 }
10018
10019 /**
10020 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10021 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10022 */
10023 // Used for SHELL command only right now.
10024 @Override
10025 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10027 "clearUceRegistrationOverrideShell");
10028 final long identity = Binder.clearCallingIdentity();
10029 try {
10030 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10031 } catch (ImsException e) {
10032 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
10037
10038 /**
10039 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10040 */
10041 // Used for SHELL command only right now.
10042 @Override
10043 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10045 "getLatestRcsContactUceCapabilityShell");
10046 final long identity = Binder.clearCallingIdentity();
10047 try {
10048 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10049 } catch (ImsException e) {
10050 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10051 } finally {
10052 Binder.restoreCallingIdentity(identity);
10053 }
10054 }
10055
10056 /**
10057 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10058 * device does not have an active PUBLISH.
10059 */
10060 // Used for SHELL command only right now.
10061 @Override
10062 public String getLastUcePidfXmlShell(int subId) {
10063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10064 final long identity = Binder.clearCallingIdentity();
10065 try {
10066 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10067 } catch (ImsException e) {
10068 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10069 } finally {
10070 Binder.restoreCallingIdentity(identity);
10071 }
10072 }
10073
10074
James.cf Lin4b784aa2021-01-31 03:25:15 +080010075 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010076 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10077 String callingPackage) {
10078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10079 mApp, subId, "setSignalStrengthUpdateRequest");
10080
10081 final int callingUid = Binder.getCallingUid();
10082 // Verify that tha callingPackage belongs to the calling UID
10083 mApp.getSystemService(AppOpsManager.class)
10084 .checkPackage(callingUid, callingPackage);
10085
10086 validateSignalStrengthUpdateRequest(request, callingUid);
10087
10088 final long identity = Binder.clearCallingIdentity();
10089 try {
10090 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10091 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10092
10093 if (result instanceof IllegalStateException) {
10094 throw (IllegalStateException) result;
10095 }
10096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
10100
10101 @Override
10102 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10103 String callingPackage) {
10104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10105 mApp, subId, "clearSignalStrengthUpdateRequest");
10106
10107 final int callingUid = Binder.getCallingUid();
10108 // Verify that tha callingPackage belongs to the calling UID
10109 mApp.getSystemService(AppOpsManager.class)
10110 .checkPackage(callingUid, callingPackage);
10111
10112 final long identity = Binder.clearCallingIdentity();
10113 try {
10114 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10115 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10116
10117 if (result instanceof IllegalStateException) {
10118 throw (IllegalStateException) result;
10119 }
10120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123 }
10124
10125 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10126 int callingUid) {
10127 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10128 // phone/system process do not have further restriction on request
10129 return;
10130 }
10131
10132 // Applications has restrictions on how to use the request:
10133 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10134 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10135 // This is not system caller which has been checked above
10136 throw new IllegalArgumentException(
10137 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10138 }
10139
10140 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10141 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10142 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10143 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10144 || info.isEnabled()) {
10145 throw new IllegalArgumentException(
10146 "Only system can set hide fields in SignalThresholdInfo");
10147 }
10148
10149 // Thresholds length for each RAN need in range. This has been validated in
10150 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10151 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10152 final int[] thresholds = info.getThresholds();
10153 Objects.requireNonNull(thresholds);
10154 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10155 || thresholds.length
10156 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10157 throw new IllegalArgumentException(
10158 "thresholds length is out of range: " + thresholds.length);
10159 }
10160 }
10161 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010162
10163 /**
10164 * Prepare TelephonyManager for an unattended reboot. The reboot is
10165 * required to be done shortly after the API is invoked.
10166 */
10167 @Override
10168 @TelephonyManager.PrepareUnattendedRebootResult
10169 public int prepareForUnattendedReboot() {
10170 enforceRebootPermission();
10171
10172 final long identity = Binder.clearCallingIdentity();
10173 try {
10174 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10175 } finally {
10176 Binder.restoreCallingIdentity(identity);
10177 }
10178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010179}