blob: 55d1a479fd24ce716f7139ab0178e0472eacb3ee [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;
SongFerngWangc63cf522021-03-31 22:08:45 +0800212import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800213import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800214import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
216/**
217 * Implementation of the ITelephony interface.
218 */
Santos Cordon117fee72014-05-16 17:56:12 -0700219public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 private static final String LOG_TAG = "PhoneInterfaceManager";
221 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
222 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
225 // Message codes used with mMainThreadHandler
226 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700227 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
228 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700229 private static final int CMD_OPEN_CHANNEL = 9;
230 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
231 private static final int CMD_CLOSE_CHANNEL = 11;
232 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800233 private static final int CMD_NV_READ_ITEM = 13;
234 private static final int EVENT_NV_READ_ITEM_DONE = 14;
235 private static final int CMD_NV_WRITE_ITEM = 15;
236 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
237 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
238 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700239 private static final int CMD_RESET_MODEM_CONFIG = 19;
240 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800241 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
242 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800243 private static final int CMD_SEND_ENVELOPE = 25;
244 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000245 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
246 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700247 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
248 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
249 private static final int CMD_EXCHANGE_SIM_IO = 31;
250 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800251 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
252 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700253 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
254 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700255 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
256 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700257 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
258 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
259 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
260 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700261 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
262 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
263 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
264 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700265 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800266 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
267 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000268 private static final int CMD_SWITCH_SLOTS = 50;
269 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700270 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
271 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
272 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
273 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
274 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
275 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
276 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
277 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700278 private static final int CMD_GET_ALL_CELL_INFO = 60;
279 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
280 private static final int CMD_GET_CELL_LOCATION = 62;
281 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700282 private static final int CMD_MODEM_REBOOT = 64;
283 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700284 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
285 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800286 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
287 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700288 private static final int CMD_GET_MODEM_STATUS = 70;
289 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700290 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
291 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700292 private static final int CMD_ERASE_MODEM_CONFIG = 74;
293 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800294 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
295 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
296 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
297 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800298 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
299 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800300 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800301 private static final int CMD_GET_CALL_FORWARDING = 83;
302 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
303 private static final int CMD_SET_CALL_FORWARDING = 85;
304 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
305 private static final int CMD_GET_CALL_WAITING = 87;
306 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
307 private static final int CMD_SET_CALL_WAITING = 89;
308 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700309 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
310 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
311 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
312 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700313 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
314 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800315 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
316 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800317 private static final int CMD_SET_DATA_THROTTLING = 99;
318 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800319 private static final int CMD_SET_SIM_POWER = 101;
320 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800321 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
322 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
323 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
324 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800325 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
326 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000327 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800329 // Parameters of select command.
330 private static final int SELECT_COMMAND = 0xA4;
331 private static final int SELECT_P1 = 0x04;
332 private static final int SELECT_P2 = 0;
333 private static final int SELECT_P3 = 0x10;
334
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 /** The singleton instance. */
336 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800337 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800341 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700342 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private AppOpsManager mAppOps;
344 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800345 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700347 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800348 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 /** User Activity */
351 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800352 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
353
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700354 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
355
Derek Tan97ebb422014-09-05 16:55:38 -0700356 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
357 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800358 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800359 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700360
Michelecea4cf22018-12-21 15:00:11 -0800361 // String to store multi SIM allowed
362 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
363
Derek Tan740e1672017-06-27 14:56:27 -0700364 // The AID of ISD-R.
365 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
366
yinxub1bed742017-04-17 11:45:04 -0700367 private NetworkScanRequestTracker mNetworkScanRequestTracker;
368
David Kelly5e06a7f2018-03-12 14:10:59 +0000369 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
370 private static final int MANUFACTURER_CODE_LENGTH = 8;
371
Jack Nudelman24d51a52020-11-24 12:08:04 -0800372 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800373 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800374
Derek Tan89e89d42014-07-08 17:00:10 -0700375 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700376 * Experiment flag to enable erase modem config on reset network, default value is false
377 */
378 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
379 "reset_network_erase_modem_config_enabled";
380
Rambo Wang0f050d82021-02-12 11:43:36 -0800381 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
382
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700383 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700384 * A request object to use for transmitting data to an ICC.
385 */
386 private static final class IccAPDUArgument {
387 public int channel, cla, command, p1, p2, p3;
388 public String data;
389
390 public IccAPDUArgument(int channel, int cla, int command,
391 int p1, int p2, int p3, String data) {
392 this.channel = channel;
393 this.cla = cla;
394 this.command = command;
395 this.p1 = p1;
396 this.p2 = p2;
397 this.p3 = p3;
398 this.data = data;
399 }
400 }
401
402 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700403 * A request object to use for transmitting data to an ICC.
404 */
405 private static final class ManualNetworkSelectionArgument {
406 public OperatorInfo operatorInfo;
407 public boolean persistSelection;
408
409 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
410 this.operatorInfo = operatorInfo;
411 this.persistSelection = persistSelection;
412 }
413 }
414
415 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
417 * request after sending. The main thread will notify the request when it is complete.
418 */
419 private static final class MainThreadRequest {
420 /** The argument to use for the request */
421 public Object argument;
422 /** The result of the request that is run on the main thread */
423 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800424 // The subscriber id that this request applies to. Defaults to
425 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
426 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Nathan Harold92bed182018-10-12 18:16:49 -0700428 // In cases where subId is unavailable, the caller needs to specify the phone.
429 public Phone phone;
430
vagdeviaf9a5b92018-08-15 16:01:53 -0700431 public WorkSource workSource;
432
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 public MainThreadRequest(Object argument) {
434 this.argument = argument;
435 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800436
Nathan Harold92bed182018-10-12 18:16:49 -0700437 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
438 this.argument = argument;
439 if (phone != null) {
440 this.phone = phone;
441 }
442 this.workSource = workSource;
443 }
444
vagdeviaf9a5b92018-08-15 16:01:53 -0700445 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800446 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800447 if (subId != null) {
448 this.subId = subId;
449 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700450 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 }
453
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800454 private static final class IncomingThirdPartyCallArgs {
455 public final ComponentName component;
456 public final String callId;
457 public final String callerDisplayName;
458
459 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
460 String callerDisplayName) {
461 this.component = component;
462 this.callId = callId;
463 this.callerDisplayName = callerDisplayName;
464 }
465 }
466
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 /**
468 * A handler that processes messages on the main thread in the phone process. Since many
469 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
470 * inbound binder threads to the main thread in the phone process. The Binder thread
471 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
472 * on, which will be notified when the operation completes and will contain the result of the
473 * request.
474 *
475 * <p>If a MainThreadRequest object is provided in the msg.obj field,
476 * note that request.result must be set to something non-null for the calling thread to
477 * unblock.
478 */
479 private final class MainThreadHandler extends Handler {
480 @Override
481 public void handleMessage(Message msg) {
482 MainThreadRequest request;
483 Message onCompleted;
484 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800487 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
489 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 case CMD_HANDLE_USSD_REQUEST: {
491 request = (MainThreadRequest) msg.obj;
492 final Phone phone = getPhoneFromRequest(request);
493 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
494 String ussdRequest = ussdObject.first;
495 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700496
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 if (!isUssdApiAllowed(request.subId)) {
498 // Carrier does not support use of this API, return failure.
499 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
500 UssdResponse response = new UssdResponse(ussdRequest, null);
501 Bundle returnData = new Bundle();
502 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
503 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700504
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 request.result = true;
506 notifyRequester(request);
507 return;
508 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700509
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 try {
511 request.result = phone != null
512 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
513 } catch (CallStateException cse) {
514 request.result = false;
515 }
516 // Wake up the requesting thread
517 notifyRequester(request);
518 break;
pkanwar32d516d2016-10-14 19:37:38 -0700519 }
520
Yorke Lee716f67e2015-06-17 15:39:16 -0700521 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700523 final Phone phone = getPhoneFromRequest(request);
524 request.result = phone != null ?
525 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
526 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 if (uiccCard == null) {
537 loge("iccTransmitApduLogicalChannel: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
542 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 iccArgument.channel, iccArgument.cla, iccArgument.command,
545 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 break;
549
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800559 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800561 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 } else {
563 loge("iccTransmitApduLogicalChannel: Unknown exception");
564 }
565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 break;
568
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
570 request = (MainThreadRequest) msg.obj;
571 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 if (uiccCard == null) {
574 loge("iccTransmitApduBasicChannel: No UICC");
575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 } else {
578 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
579 request);
580 uiccCard.iccTransmitApduBasicChannel(
581 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
582 iccArgument.p3, iccArgument.data, onCompleted);
583 }
584 break;
585
586 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
587 ar = (AsyncResult) msg.obj;
588 request = (MainThreadRequest) ar.userObj;
589 if (ar.exception == null && ar.result != null) {
590 request.result = ar.result;
591 } else {
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
593 if (ar.result == null) {
594 loge("iccTransmitApduBasicChannel: Empty response");
595 } else if (ar.exception instanceof CommandException) {
596 loge("iccTransmitApduBasicChannel: CommandException: " +
597 ar.exception);
598 } else {
599 loge("iccTransmitApduBasicChannel: Unknown exception");
600 }
601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 break;
604
605 case CMD_EXCHANGE_SIM_IO:
606 request = (MainThreadRequest) msg.obj;
607 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800608 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 if (uiccCard == null) {
610 loge("iccExchangeSimIO: No UICC");
611 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 } else {
614 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
615 request);
616 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
617 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
618 iccArgument.data, onCompleted);
619 }
620 break;
621
622 case EVENT_EXCHANGE_SIM_IO_DONE:
623 ar = (AsyncResult) msg.obj;
624 request = (MainThreadRequest) ar.userObj;
625 if (ar.exception == null && ar.result != null) {
626 request.result = ar.result;
627 } else {
628 request.result = new IccIoResult(0x6f, 0, (byte[])null);
629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 break;
632
Derek Tan4d5e5c12014-02-04 11:54:58 -0800633 case CMD_SEND_ENVELOPE:
634 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800635 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 if (uiccCard == null) {
637 loge("sendEnvelopeWithStatus: No UICC");
638 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 } else {
641 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
642 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
643 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 break;
645
646 case EVENT_SEND_ENVELOPE_DONE:
647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700652 request.result = new IccIoResult(0x6F, 0, (byte[])null);
653 if (ar.result == null) {
654 loge("sendEnvelopeWithStatus: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("sendEnvelopeWithStatus: CommandException: " +
657 ar.exception);
658 } else {
659 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
660 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800663 break;
664
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 case CMD_OPEN_CHANNEL:
666 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800667 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800668 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 if (uiccCard == null) {
670 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800671 request.result = new IccOpenLogicalChannelResponse(-1,
672 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 } else {
675 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800676 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
677 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
681 case EVENT_OPEN_CHANNEL_DONE:
682 ar = (AsyncResult) msg.obj;
683 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 int[] result = (int[]) ar.result;
687 int channelId = result[0];
688 byte[] selectResponse = null;
689 if (result.length > 1) {
690 selectResponse = new byte[result.length - 1];
691 for (int i = 1; i < result.length; ++i) {
692 selectResponse[i - 1] = (byte) result[i];
693 }
694 }
695 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700696 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 if (ar.result == null) {
699 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 if (ar.exception != null) {
702 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
703 }
704
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700705 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700706 if (ar.exception instanceof CommandException) {
707 CommandException.Error error =
708 ((CommandException) (ar.exception)).getCommandError();
709 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700711 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 }
714 }
715 openChannelResp = new IccOpenLogicalChannelResponse(
716 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700718 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
722 case CMD_CLOSE_CHANNEL:
723 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800724 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 if (uiccCard == null) {
726 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900727 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
731 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
732 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 break;
734
735 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800736 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
737 break;
738
739 case CMD_NV_READ_ITEM:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800742 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
743 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800744 break;
745
746 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800749 if (ar.exception == null && ar.result != null) {
750 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800752 request.result = "";
753 if (ar.result == null) {
754 loge("nvReadItem: Empty response");
755 } else if (ar.exception instanceof CommandException) {
756 loge("nvReadItem: CommandException: " +
757 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800759 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 }
761 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 break;
764
Jake Hambye994d462014-02-03 13:10:13 -0800765 case CMD_NV_WRITE_ITEM:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
768 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800769 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700770 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800771 break;
772
773 case EVENT_NV_WRITE_ITEM_DONE:
774 handleNullReturnEvent(msg, "nvWriteItem");
775 break;
776
777 case CMD_NV_WRITE_CDMA_PRL:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800780 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800781 break;
782
783 case EVENT_NV_WRITE_CDMA_PRL_DONE:
784 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
785 break;
786
chen xu6dac5ab2018-10-26 17:39:23 -0700787 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800788 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700789 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800791 break;
792
chen xu6dac5ab2018-10-26 17:39:23 -0700793 case EVENT_RESET_MODEM_CONFIG_DONE:
794 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800795 break;
796
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700797 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
800 request);
801 Phone phone = getPhoneFromRequest(request);
802 if (phone != null) {
803 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
804 } else {
805 loge("isNRDualConnectivityEnabled: No phone object");
806 request.result = false;
807 notifyRequester(request);
808 }
809 break;
810 }
811
812 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null && ar.result != null) {
816 request.result = ar.result;
817 } else {
818 // request.result must be set to something non-null
819 // for the calling thread to unblock
820 if (request.result != null) {
821 request.result = ar.result;
822 } else {
823 request.result = false;
824 }
825 if (ar.result == null) {
826 loge("isNRDualConnectivityEnabled: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("isNRDualConnectivityEnabled: CommandException: "
829 + ar.exception);
830 } else {
831 loge("isNRDualConnectivityEnabled: Unknown exception");
832 }
833 }
834 notifyRequester(request);
835 break;
836
837 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
840 Phone phone = getPhoneFromRequest(request);
841 if (phone != null) {
842 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
843 request.workSource);
844 } else {
845 loge("enableNrDualConnectivity: No phone object");
846 request.result =
847 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
848 notifyRequester(request);
849 }
850 break;
851 }
852
853 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null) {
857 request.result =
858 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
859 } else {
860 request.result =
861 TelephonyManager
862 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
863 if (ar.exception instanceof CommandException) {
864 CommandException.Error error =
865 ((CommandException) (ar.exception)).getCommandError();
866 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
867 request.result =
868 TelephonyManager
869 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000870 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
871 request.result =
872 TelephonyManager
873 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700874 }
875 loge("enableNrDualConnectivity" + ": CommandException: "
876 + ar.exception);
877 } else {
878 loge("enableNrDualConnectivity" + ": Unknown exception");
879 }
880 }
881 notifyRequester(request);
882 break;
883 }
884
SongFerngWang9e060372020-12-21 16:41:52 +0800885 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800887 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
888 request);
889 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 break;
891
SongFerngWang9e060372020-12-21 16:41:52 +0800892 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result; // Integer
897 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530898 // request.result must be set to something non-null
899 // for the calling thread to unblock
900 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800902 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800904 loge("getAllowedNetworkTypesBitmask: CommandException: "
905 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800907 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 }
909 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 break;
912
SongFerngWang9e060372020-12-21 16:41:52 +0800913 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800915 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
916 request);
917 Pair<Integer, Long> reasonWithNetworkTypes =
918 (Pair<Integer, Long>) request.argument;
919 getPhoneFromRequest(request).setAllowedNetworkTypes(
920 reasonWithNetworkTypes.first,
921 reasonWithNetworkTypes.second,
922 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 break;
924
SongFerngWang9e060372020-12-21 16:41:52 +0800925 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
926 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 break;
928
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000929 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
930 request = (MainThreadRequest)msg.obj;
931 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800932 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000933 break;
934
935 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
936 ar = (AsyncResult)msg.obj;
937 request = (MainThreadRequest)ar.userObj;
938 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000940 break;
941
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800942 case CMD_SET_VOICEMAIL_NUMBER:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
945 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800946 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
947 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800948 break;
949
950 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
951 handleNullReturnEvent(msg, "setVoicemailNumber");
952 break;
953
Stuart Scott54788802015-03-30 13:18:01 -0700954 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
957 request);
958 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
959 break;
960
961 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
962 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
963 break;
964
Shishir Agrawal302c8692015-06-19 13:49:39 -0700965 case CMD_PERFORM_NETWORK_SCAN:
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
968 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
969 break;
970
Hall Liua1acea22020-09-18 19:04:59 -0700971 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700974 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
975 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
976 request.argument;
977 int callForwardingReason = args.first;
978 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800979 break;
Hall Liua1acea22020-09-18 19:04:59 -0700980 }
981 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700984 TelephonyManager.CallForwardingInfoCallback callback =
985 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
986 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800987 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700988 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800989 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
990 for (CallForwardInfo callForwardInfo : callForwardInfos) {
991 // Service Class is a bit mask per 3gpp 27.007. Search for
992 // any service for voice call.
993 if ((callForwardInfo.serviceClass
994 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700995 callForwardingInfo = new CallForwardingInfo(true,
996 callForwardInfo.reason,
997 callForwardInfo.number,
998 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800999 break;
1000 }
1001 }
1002 // Didn't find a call forward info for voice call.
1003 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001004 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1005 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001006 }
Hall Liua1acea22020-09-18 19:04:59 -07001007 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001008 } else {
1009 if (ar.result == null) {
1010 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1011 }
1012 if (ar.exception != null) {
1013 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1014 }
Hall Liuae527aa2020-09-29 17:10:18 -07001015 int errorCode = TelephonyManager
1016 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001017 if (ar.exception instanceof CommandException) {
1018 CommandException.Error error =
1019 ((CommandException) (ar.exception)).getCommandError();
1020 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001021 errorCode = TelephonyManager
1022 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001023 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001024 errorCode = TelephonyManager
1025 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001026 }
1027 }
Hall Liua1acea22020-09-18 19:04:59 -07001028 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001029 }
sqian80370722020-01-29 15:02:51 -08001030 break;
Hall Liua1acea22020-09-18 19:04:59 -07001031 }
sqian80370722020-01-29 15:02:51 -08001032
Hall Liua1acea22020-09-18 19:04:59 -07001033 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001034 request = (MainThreadRequest) msg.obj;
1035 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001036 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001037 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001038 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1039 request.argument).first;
1040 request.phone.setCallForwardingOption(
1041 callForwardingInfoToSet.isEnabled()
1042 ? CommandsInterface.CF_ACTION_ENABLE
1043 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001044 callForwardingInfoToSet.getReason(),
1045 callForwardingInfoToSet.getNumber(),
1046 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1047 break;
Hall Liua1acea22020-09-18 19:04:59 -07001048 }
sqian80370722020-01-29 15:02:51 -08001049
Hall Liua1acea22020-09-18 19:04:59 -07001050 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001053 Consumer<Integer> callback =
1054 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1055 request.argument).second;
1056 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001057 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001058 int errorCode = TelephonyManager.CallForwardingInfoCallback
1059 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001060 if (ar.exception instanceof CommandException) {
1061 CommandException.Error error =
1062 ((CommandException) (ar.exception)).getCommandError();
1063 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001064 errorCode = TelephonyManager.CallForwardingInfoCallback
1065 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001066 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001067 errorCode = TelephonyManager.CallForwardingInfoCallback
1068 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001069 }
1070 }
1071 callback.accept(errorCode);
1072 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001073 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001074 }
sqian80370722020-01-29 15:02:51 -08001075 break;
Hall Liua1acea22020-09-18 19:04:59 -07001076 }
sqian80370722020-01-29 15:02:51 -08001077
Hall Liua1acea22020-09-18 19:04:59 -07001078 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1081 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1082 break;
Hall Liua1acea22020-09-18 19:04:59 -07001083 }
sqian80370722020-01-29 15:02:51 -08001084
Hall Liua1acea22020-09-18 19:04:59 -07001085 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001088 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001089 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1090 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001091 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001092 // Service Class is a bit mask per 3gpp 27.007.
1093 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001094 if (callForwardResults.length > 1
1095 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001096 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001097 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001098 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1099 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001100 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001101 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001102 }
1103 } else {
1104 if (ar.result == null) {
1105 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1106 }
1107 if (ar.exception != null) {
1108 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1109 }
1110 if (ar.exception instanceof CommandException) {
1111 CommandException.Error error =
1112 ((CommandException) (ar.exception)).getCommandError();
1113 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1114 callForwardingStatus =
1115 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1116 }
1117 }
1118 }
Hall Liua1acea22020-09-18 19:04:59 -07001119 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001120 break;
Hall Liua1acea22020-09-18 19:04:59 -07001121 }
sqian80370722020-01-29 15:02:51 -08001122
Hall Liua1acea22020-09-18 19:04:59 -07001123 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001124 request = (MainThreadRequest) msg.obj;
1125 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001126 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1127 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001128 break;
Hall Liua1acea22020-09-18 19:04:59 -07001129 }
sqian80370722020-01-29 15:02:51 -08001130
Hall Liua1acea22020-09-18 19:04:59 -07001131 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001132 ar = (AsyncResult) msg.obj;
1133 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001134 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1135 Consumer<Integer> callback =
1136 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1137 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001138 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001139 if (ar.exception instanceof CommandException) {
1140 CommandException.Error error =
1141 ((CommandException) (ar.exception)).getCommandError();
1142 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1143 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1144 } else {
1145 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1146 }
1147 } else {
1148 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1149 }
1150 } else {
1151 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1152 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001153 }
sqian80370722020-01-29 15:02:51 -08001154 break;
Hall Liua1acea22020-09-18 19:04:59 -07001155 }
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 Ebingerc9c432e2021-05-17 20:54:49 +00002096 mImsResolver = ImsResolver.getInstance();
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) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004348 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4349 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004350 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 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004359 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4360 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4361 loge("setImsProvisioningStatusForCapability: called for technology that does "
4362 + "not support provisioning - " + tech);
4363 return;
4364 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004365
4366 // this capability requires provisioning, route to the correct API.
4367 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4368 switch (capability) {
4369 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4370 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4371 ims.setVolteProvisioned(isProvisioned);
4372 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4373 ims.setWfcProvisioned(isProvisioned);
4374 }
4375 break;
4376 }
4377 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4378 // There is currently no difference in VT provisioning type.
4379 ims.setVtProvisioned(isProvisioned);
4380 break;
4381 }
4382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4383 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4384 // change the capability of the feature instead if needed.
4385 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4386 == isProvisioned) {
4387 // No change in provisioning.
4388 return;
4389 }
4390 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4391 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004392 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004393 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004394 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4395 + ", Exception" + e.getMessage());
4396 }
4397 break;
4398 }
4399 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004400 throw new IllegalArgumentException("Tried to set provisioning for "
4401 + "MmTel capability '" + capability + "', which does not require "
4402 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004403 }
4404 }
4405
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
4409 }
4410
4411 @Override
4412 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004413 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4414 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004415 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4416 }
4417 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
4420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004421 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004422 return true;
4423 }
4424
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004425 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4426 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4427 loge("getImsProvisioningStatusForCapability: called for technology that does "
4428 + "not support provisioning - " + tech);
4429 return true;
4430 }
4431
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004432 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4433 switch (capability) {
4434 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4435 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4436 return ims.isVolteProvisionedOnDevice();
4437 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4438 return ims.isWfcProvisionedOnDevice();
4439 }
4440 // This should never happen, since we are checking tech above to make sure it
4441 // is either LTE or IWLAN.
4442 throw new IllegalArgumentException("Invalid radio technology for voice "
4443 + "capability.");
4444 }
4445 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4446 // There is currently no difference in VT provisioning type.
4447 return ims.isVtProvisionedOnDevice();
4448 }
4449 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4450 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4451 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4452 }
4453 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004454 throw new IllegalArgumentException(
4455 "Tried to get provisioning for MmTel capability '" + capability
4456 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004457 }
4458 }
4459
4460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
4463 }
4464
4465 @Override
4466 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4467 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4468 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4469 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4470 }
4471 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4472 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4473 return (provisionedBits & capability) > 0;
4474 }
4475
4476 @Override
4477 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4478 boolean isProvisioned) {
4479 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4480 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4481 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4482 }
4483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4484 "setProvisioningStatusForCapability");
4485 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4486 // If the current provisioning status for capability already matches isProvisioned,
4487 // do nothing.
4488 if (((provisionedBits & capability) > 0) == isProvisioned) {
4489 return;
4490 }
4491 if (isProvisioned) {
4492 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4493 } else {
4494 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4495 }
4496 }
4497
4498 /**
4499 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4500 * technology. The bitfield should mirror the bitfield defined by
4501 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4502 */
4503 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4504 String key = getMmTelProvisioningKey(subId, tech);
4505 // Default is no capabilities are provisioned.
4506 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4507 }
4508
4509 /**
4510 * Sets the MmTel capability provisioning bitfield (defined by
4511 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4512 * technology specified.
4513 *
4514 * Note: This is a synchronous command and should not be called on UI thread.
4515 */
4516 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4517 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4518 String key = getMmTelProvisioningKey(subId, tech);
4519 editor.putInt(key, newField);
4520 editor.commit();
4521 }
4522
4523 private static String getMmTelProvisioningKey(int subId, int tech) {
4524 // resulting key is provision_ims_mmtel_{subId}_{tech}
4525 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4526 }
4527
4528 /**
4529 * Query CarrierConfig to see if the specified capability requires provisioning for the
4530 * carrier associated with the subscription id.
4531 */
4532 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4533 int capability) {
4534 CarrierConfigManager configManager = new CarrierConfigManager(context);
4535 PersistableBundle c = configManager.getConfigForSubId(subId);
4536 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004537 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4539 false);
4540 boolean requireVoiceVtProvisioning = c.getBoolean(
4541 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4542
4543 // First check to make sure that the capability requires provisioning.
4544 switch (capability) {
4545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4546 // intentional fallthrough
4547 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4548 if (requireVoiceVtProvisioning) {
4549 // Voice and Video requires provisioning
4550 return true;
4551 }
4552 break;
4553 }
4554 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4555 if (requireUtProvisioning) {
4556 // UT requires provisioning
4557 return true;
4558 }
4559 break;
4560 }
4561 }
4562 return false;
4563 }
4564
allenwtsu99c623b2020-01-03 18:24:23 +08004565 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4566 int capability) {
4567 CarrierConfigManager configManager = new CarrierConfigManager(context);
4568 PersistableBundle c = configManager.getConfigForSubId(subId);
4569
4570 boolean requireRcsProvisioning = c.getBoolean(
4571 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4572
4573 // First check to make sure that the capability requires provisioning.
4574 switch (capability) {
4575 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4576 // intentional fallthrough
4577 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4578 if (requireRcsProvisioning) {
4579 // OPTION or PRESENCE requires provisioning
4580 return true;
4581 }
4582 break;
4583 }
4584 }
4585 return false;
4586 }
4587
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004588 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004589 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4592 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 enforceReadPrivilegedPermission("getImsProvisioningInt");
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 int slotId = getSlotIndex(subId);
4598 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4599 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4600 + subId + "' for key:" + key);
4601 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4602 }
calvinpan9cfff472021-02-08 19:59:36 +08004603 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4606 + subId + "' for key:" + key);
4607 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611 }
4612
4613 @Override
4614 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4616 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4617 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 enforceReadPrivilegedPermission("getImsProvisioningString");
4619 final long identity = Binder.clearCallingIdentity();
4620 try {
4621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004622 int slotId = getSlotIndex(subId);
4623 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4624 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4625 + subId + "' for key:" + key);
4626 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4627 }
calvinpan9cfff472021-02-08 19:59:36 +08004628 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004629 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004630 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4631 + subId + "' for key:" + key);
4632 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
4636 }
4637
4638 @Override
4639 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4641 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4642 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4644 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 int slotId = getSlotIndex(subId);
4649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4650 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4651 + subId + "' for key:" + key);
4652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4653 }
calvinpan9cfff472021-02-08 19:59:36 +08004654 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4655 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004657 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004658 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004666 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4667 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4668 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4670 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004674 int slotId = getSlotIndex(subId);
4675 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4676 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4677 + subId + "' for key:" + key);
4678 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4679 }
calvinpan9cfff472021-02-08 19:59:36 +08004680 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4681 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004683 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
4688 }
4689
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004690 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 int slotId = SubscriptionManager.getSlotIndex(subId);
4692 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4694 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 }
4696 return slotId;
4697 }
4698
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 private int getSlotIndex(int subId) {
4700 int slotId = SubscriptionManager.getSlotIndex(subId);
4701 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4702 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4703 }
4704 return slotId;
4705 }
4706
Wink Saville36469e72014-06-11 15:17:00 -07004707 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004708 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004709 */
4710 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004711 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4712 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004713 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004714 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004716 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004717 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004718 mApp, subId, callingPackage, callingFeatureId,
4719 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004720 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4721 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 final Phone phone = getPhone(subId);
4726 if (phone != null) {
4727 return phone.getServiceState().getDataNetworkType();
4728 } else {
4729 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4730 }
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004734 }
4735
4736 /**
4737 * Returns the data network type
4738 */
4739 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004740 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004741 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4742 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004743 }
4744
4745 /**
4746 * Returns the data network type for a subId
4747 */
4748 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004749 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4750 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004752 mApp, subId, callingPackage, callingFeatureId,
4753 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004754 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4755 }
4756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 final Phone phone = getPhone(subId);
4760 if (phone != null) {
4761 return phone.getServiceState().getDataNetworkType();
4762 } else {
4763 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4764 }
4765 } finally {
4766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004768 }
4769
4770 /**
Wink Saville36469e72014-06-11 15:17:00 -07004771 * Returns the Voice network type for a subId
4772 */
4773 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004774 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4775 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004777 mApp, subId, callingPackage, callingFeatureId,
4778 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004779 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4780 }
4781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 final long identity = Binder.clearCallingIdentity();
4783 try {
4784 final Phone phone = getPhone(subId);
4785 if (phone != null) {
4786 return phone.getServiceState().getVoiceNetworkType();
4787 } else {
4788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4789 }
4790 } finally {
4791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004793 }
4794
4795 /**
4796 * @return true if a ICC card is present
4797 */
4798 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004799 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004800 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4801 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004802 }
4803
4804 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004805 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004806 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004807 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004808 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 final Phone phone = PhoneFactory.getPhone(slotIndex);
4812 if (phone != null) {
4813 return phone.getIccCard().hasIccCard();
4814 } else {
4815 return false;
4816 }
4817 } finally {
4818 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004820 }
4821
4822 /**
4823 * Return if the current radio is LTE on CDMA. This
4824 * is a tri-state return value as for a period of time
4825 * the mode may be unknown.
4826 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004827 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004828 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004829 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004830 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004831 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004832 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4833 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4834 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004835 }
4836
Sanket Padawe356d7632015-06-22 14:03:32 -07004837 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004838 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4839 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004840 try {
4841 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4842 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004843 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4844 }
4845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 final Phone phone = getPhone(subId);
4849 if (phone == null) {
4850 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4851 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004852 return TelephonyProperties.lte_on_cdma_device()
4853 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 }
4855 } finally {
4856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004857 }
Wink Saville36469e72014-06-11 15:17:00 -07004858 }
4859
Wink Saville36469e72014-06-11 15:17:00 -07004860 /**
4861 * {@hide}
4862 * Returns Default subId, 0 in the case of single standby.
4863 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004864 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004865 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004866 }
4867
Shishir Agrawala9f32182016-04-12 12:00:16 -07004868 private int getSlotForDefaultSubscription() {
4869 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4870 }
4871
Wink Savilleb564aae2014-10-23 10:18:09 -07004872 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004873 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004874 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004875
Pengquan Menge92a50d2018-09-21 15:54:48 -07004876 private boolean isActiveSubscription(int subId) {
4877 return mSubscriptionController.isActiveSubId(subId);
4878 }
4879
Ihab Awadf2177b72013-11-25 13:33:23 -08004880 /**
4881 * @see android.telephony.TelephonyManager.WifiCallingChoices
4882 */
4883 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 final long identity = Binder.clearCallingIdentity();
4885 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004886 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4888 getWhenToMakeWifiCallsDefaultPreference());
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004892 }
4893
4894 /**
4895 * @see android.telephony.TelephonyManager.WifiCallingChoices
4896 */
4897 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 final long identity = Binder.clearCallingIdentity();
4899 try {
4900 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004901 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004906 }
4907
Sailesh Nepald1e68152013-12-12 19:08:02 -08004908 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004909 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004910 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004911 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004912
Jordan Liu4c733742019-02-28 12:03:40 -08004913 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4914 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4915 if (phoneId == -1) {
4916 throw new IllegalArgumentException("Given slot index: " + slotIndex
4917 + " does not correspond to an active phone");
4918 }
4919 return PhoneFactory.getPhone(phoneId);
4920 }
4921
Shishir Agrawal566b7612013-10-28 14:41:00 -07004922 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004923 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4924 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4926 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004928 if (DBG) {
4929 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4930 }
4931 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4932 p2);
4933 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004934
Jordan Liu4c733742019-02-28 12:03:40 -08004935
4936 @Override
4937 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4938 int slotIndex, String callingPackage, String aid, int p2) {
4939 enforceModifyPermission();
4940 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4941 if (DBG) {
4942 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4943 }
4944 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4945 callingPackage, aid, p2);
4946 }
4947
4948 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4949 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 final long identity = Binder.clearCallingIdentity();
4951 try {
4952 if (TextUtils.equals(ISDR_AID, aid)) {
4953 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004954 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4955 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 if (bestComponent == null
4957 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4958 loge("The calling package is not allowed to access ISD-R.");
4959 throw new SecurityException(
4960 "The calling package is not allowed to access ISD-R.");
4961 }
Derek Tan740e1672017-06-27 14:56:27 -07004962 }
Derek Tan740e1672017-06-27 14:56:27 -07004963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004965 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4966 null /* workSource */);
4967 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 return response;
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004972 }
4973
4974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004975 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4977 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004978 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4979 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4980 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004981
Jordan Liu4c733742019-02-28 12:03:40 -08004982 @Override
4983 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4984 enforceModifyPermission();
4985 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4986 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4987 channel);
4988 }
4989
4990 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 if (channel < 0) {
4994 return false;
4995 }
Jordan Liu4c733742019-02-28 12:03:40 -08004996 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4997 null /* workSource */);
4998 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 return success;
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005002 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005003 }
5004
5005 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005006 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005007 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5009 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005010 if (DBG) {
5011 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5012 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5013 + p3 + " data=" + data);
5014 }
5015 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5016 command, p1, p2, p3, data);
5017 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005018
Jordan Liu4c733742019-02-28 12:03:40 -08005019 @Override
5020 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5021 int command, int p1, int p2, int p3, String data) {
5022 enforceModifyPermission();
5023 if (DBG) {
5024 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5025 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5026 + p3 + " data=" + data);
5027 }
5028 return iccTransmitApduLogicalChannelWithPermission(
5029 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5030 data);
5031 }
5032
5033 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5034 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005037 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 return "";
5039 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005042 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5043 null /* workSource */);
5044 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 // Append the returned status code to the end of the response payload.
5047 String s = Integer.toHexString(
5048 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5049 if (response.payload != null) {
5050 s = IccUtils.bytesToHexString(response.payload) + s;
5051 }
5052 return s;
5053 } finally {
5054 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005055 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005056 }
Jake Hambye994d462014-02-03 13:10:13 -08005057
Evan Charltonc66da362014-05-16 14:06:40 -07005058 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005059 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5060 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5062 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005064 if (DBG) {
5065 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5066 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5067 }
5068 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5069 cla, command, p1, p2, p3, data);
5070 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005071
Jordan Liu4c733742019-02-28 12:03:40 -08005072 @Override
5073 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5074 int command, int p1, int p2, int p3, String data) {
5075 enforceModifyPermission();
5076 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5077 if (DBG) {
5078 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5079 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5080 + " data=" + data);
5081 }
5082
5083 return iccTransmitApduBasicChannelWithPermission(
5084 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5085 p2, p3, data);
5086 }
5087
5088 // open APDU basic channel assuming the caller has sufficient permissions
5089 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5090 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5094 && TextUtils.equals(ISDR_AID, data)) {
5095 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005096 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5097 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 if (bestComponent == null
5099 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5100 loge("The calling package is not allowed to select ISD-R.");
5101 throw new SecurityException(
5102 "The calling package is not allowed to select ISD-R.");
5103 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005104 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005107 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5108 null /* workSource */);
5109 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 // Append the returned status code to the end of the response payload.
5112 String s = Integer.toHexString(
5113 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5114 if (response.payload != null) {
5115 s = IccUtils.bytesToHexString(response.payload) + s;
5116 }
5117 return s;
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005120 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005121 }
5122
5123 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005124 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005125 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5127 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 if (DBG) {
5132 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5133 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5134 }
5135
5136 IccIoResult response =
5137 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5138 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5139 subId);
5140
5141 if (DBG) {
5142 log("Exchange SIM_IO [R]" + response);
5143 }
5144
5145 byte[] result = null;
5146 int length = 2;
5147 if (response.payload != null) {
5148 length = 2 + response.payload.length;
5149 result = new byte[length];
5150 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5151 } else {
5152 result = new byte[length];
5153 }
5154
5155 result[length - 1] = (byte) response.sw2;
5156 result[length - 2] = (byte) response.sw1;
5157 return result;
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005160 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005161 }
5162
Nathan Haroldb3014052017-01-25 15:57:32 -08005163 /**
5164 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5165 * on a particular subscription
5166 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005167 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5168 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005169 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005170 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005171 return null;
5172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173
5174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 if (appType != TelephonyManager.APPTYPE_USIM
5177 && appType != TelephonyManager.APPTYPE_SIM) {
5178 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5179 return null;
5180 }
5181 Object response = sendRequest(
5182 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5183 if (response instanceof String[]) {
5184 return (String[]) response;
5185 }
yincheng zhaod698b842019-09-06 17:06:54 -07005186 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005188 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005191 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005192 }
5193
yincheng zhaod698b842019-09-06 17:06:54 -07005194 /**
5195 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5196 * subscription.
5197 *
5198 * @param subId the id of the subscription.
5199 * @param appType the uicc app type, must be USIM or SIM.
5200 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5201 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005202 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005203 * @return number of fplmns that is successfully written to the SIM.
5204 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005205 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5206 String callingFeatureId) {
5207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5208 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005209 if (DBG) logv("no permissions for setForbiddenplmns");
5210 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5211 }
5212 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5213 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5214 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5215 }
5216 if (fplmns == null) {
5217 throw new IllegalArgumentException("Fplmn List provided is null");
5218 }
5219 for (String fplmn : fplmns) {
5220 if (!CellIdentity.isValidPlmn(fplmn)) {
5221 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5222 }
5223 }
5224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 Object response = sendRequest(
5227 CMD_SET_FORBIDDEN_PLMNS,
5228 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5229 subId);
5230 return (int) response;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
5234 }
5235
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005236 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005237 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5239 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5244 if (response.payload == null) {
5245 return "";
5246 }
Evan Charltonc66da362014-05-16 14:06:40 -07005247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 // Append the returned status code to the end of the response payload.
5249 String s = Integer.toHexString(
5250 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5251 s = IccUtils.bytesToHexString(response.payload) + s;
5252 return s;
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Evan Charltonc66da362014-05-16 14:06:40 -07005256 }
5257
Jake Hambye994d462014-02-03 13:10:13 -08005258 /**
5259 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5260 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5261 *
5262 * @param itemID the ID of the item to read
5263 * @return the NV item as a String, or null on error.
5264 */
5265 @Override
5266 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5269 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005274 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5276 return value;
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Jake Hambye994d462014-02-03 13:10:13 -08005280 }
5281
5282 /**
5283 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5284 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5285 *
5286 * @param itemID the ID of the item to read
5287 * @param itemValue the value to write, as a String
5288 * @return true on success; false on any failure
5289 */
5290 @Override
5291 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295
5296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5299 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005300 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5302 return success;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Jake Hambye994d462014-02-03 13:10:13 -08005306 }
5307
5308 /**
5309 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5310 * Used for device configuration by some CDMA operators.
5311 *
5312 * @param preferredRoamingList byte array containing the new PRL
5313 * @return true on success; false on any failure
5314 */
5315 @Override
5316 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5323 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5324 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5325 return success;
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Jake Hambye994d462014-02-03 13:10:13 -08005329 }
5330
5331 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005332 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005333 * Used for device configuration by some CDMA operators.
5334 *
chen xu6dac5ab2018-10-26 17:39:23 -07005335 * @param slotIndex - device slot.
5336 *
Jake Hambye994d462014-02-03 13:10:13 -08005337 * @return true on success; false on any failure
5338 */
5339 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005340 public boolean resetModemConfig(int slotIndex) {
5341 Phone phone = PhoneFactory.getPhone(slotIndex);
5342 if (phone != null) {
5343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5344 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345
chen xu6dac5ab2018-10-26 17:39:23 -07005346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5349 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5350 return success;
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 }
chen xu6dac5ab2018-10-26 17:39:23 -07005355 return false;
5356 }
5357
5358 /**
5359 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5360 *
5361 * @param slotIndex - device slot.
5362 *
5363 * @return true on success; false on any failure
5364 */
5365 @Override
5366 public boolean rebootModem(int slotIndex) {
5367 Phone phone = PhoneFactory.getPhone(slotIndex);
5368 if (phone != null) {
5369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5370 mApp, phone.getSubId(), "rebootModem");
5371
5372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5375 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5376 return success;
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
5380 }
5381 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005382 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005383
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005384 public String[] getPcscfAddress(String apnType, String callingPackage,
5385 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005386 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5388 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005389 return new String[0];
5390 }
5391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005394 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
Wink Saville36469e72014-06-11 15:17:00 -07005398 }
5399
Brad Ebinger51f743a2017-01-23 13:50:20 -08005400 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005401 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5402 * {@link #disableIms(int)}.
5403 * @param slotIndex device slot.
5404 */
5405 public void resetIms(int slotIndex) {
5406 enforceModifyPermission();
5407
5408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 if (mImsResolver == null) {
5411 // may happen if the does not support IMS.
5412 return;
5413 }
5414 mImsResolver.disableIms(slotIndex);
5415 mImsResolver.enableIms(slotIndex);
5416 } finally {
5417 Binder.restoreCallingIdentity(identity);
5418 }
5419 }
5420
5421 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005422 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5423 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005424 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005425 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427
5428 final long identity = Binder.clearCallingIdentity();
5429 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005430 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005431 // may happen if the device does not support IMS.
5432 return;
5433 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005434 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005438 }
5439
5440 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005441 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5442 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005443 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005444 public void disableIms(int slotId) {
5445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446
5447 final long identity = Binder.clearCallingIdentity();
5448 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005449 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005450 // may happen if the device does not support IMS.
5451 return;
5452 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005453 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005457 }
5458
5459 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005460 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5461 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005462 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005463 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005464 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005465 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466
5467 final long identity = Binder.clearCallingIdentity();
5468 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005469 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005470 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5471 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005472 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005473 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 } finally {
5475 Binder.restoreCallingIdentity(identity);
5476 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005477 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005478 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005479 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5480 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005481 @Override
5482 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005483 enforceModifyPermission();
5484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005488 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
5492 }
5493
5494 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005495 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005496 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005497 */
5498 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005503 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005504 // may happen if the device does not support IMS.
5505 return null;
5506 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005507 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005511 }
5512
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005513 /**
5514 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005515 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005516 */
5517 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005522 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005523 // may happen if the device does not support IMS.
5524 return null;
5525 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005526 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 } finally {
5528 Binder.restoreCallingIdentity(identity);
5529 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005530 }
5531
Brad Ebinger884c07b2018-02-15 16:17:40 -08005532 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005533 * Sets the ImsService Package Name that Telephony will bind to.
5534 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005535 * @param slotIndex the slot ID that the ImsService should bind for.
5536 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005537 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005538 * @param featureTypes An integer array of feature types associated with a packageName.
5539 * @param packageName The name of the package that the current configuration will be replaced
5540 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005541 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005542 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005543 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5544 int[] featureTypes, String packageName) {
5545 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5546 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5548 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005549 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 final long identity = Binder.clearCallingIdentity();
5552 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005553 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005554 // may happen if the device does not support IMS.
5555 return false;
5556 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005557 Map<Integer, String> featureConfig = new HashMap<>();
5558 for (int featureType : featureTypes) {
5559 featureConfig.put(featureType, packageName);
5560 }
5561 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5562 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005566 }
5567
5568 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005569 * Clears any carrier ImsService overrides for the slot index specified that were previously
5570 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5571 *
5572 * This should only be used for testing.
5573 *
5574 * @param slotIndex the slot ID that the ImsService should bind for.
5575 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5576 */
5577 @Override
5578 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5579 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5580 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5581 "clearCarrierImsServiceOverride");
5582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5583 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5584 "clearCarrierImsServiceOverride");
5585
5586 final long identity = Binder.clearCallingIdentity();
5587 try {
5588 if (mImsResolver == null) {
5589 // may happen if the device does not support IMS.
5590 return false;
5591 }
5592 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
5596 }
5597
5598 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005600 *
5601 * @param slotId The slot that the ImsService is associated with.
5602 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5603 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005604 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005605 * @return the package name of the ImsService configuration.
5606 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005607 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5608 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005609 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005610 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005611 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005612 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5613 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 final long identity = Binder.clearCallingIdentity();
5616 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005617 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005618 // may happen if the device does not support IMS.
5619 return "";
5620 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005621 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005622 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5623 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005627 }
5628
Brad Ebinger77b832e2019-10-17 17:03:22 -07005629 /**
5630 * Get the MmTelFeature state associated with the requested subscription id.
5631 * @param subId The subscription that the MmTelFeature is associated with.
5632 * @param callback A callback with an integer containing the
5633 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5634 */
5635 @Override
5636 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5637 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5638 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5639 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5640 "IMS not available on device.");
5641 }
5642 final long token = Binder.clearCallingIdentity();
5643 try {
5644 int slotId = getSlotIndex(subId);
5645 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5646 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5647 + subId + "'");
5648 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5649 }
5650 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5651 try {
5652 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5653 } catch (RemoteException e) {
5654 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5655 + "Ignore");
5656 }
5657 });
5658 } finally {
5659 Binder.restoreCallingIdentity(token);
5660 }
5661 }
5662
Daniel Brightbb5840b2021-01-12 15:48:18 -08005663 /**
5664 * Sets the ims registration state on all valid {@link Phone}s.
5665 */
5666 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005671 // NOTE: Before S, this method only set the default phone.
5672 for (final Phone phone : PhoneFactory.getPhones()) {
5673 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5674 phone.setImsRegistrationState(registered);
5675 }
5676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Wink Saville36469e72014-06-11 15:17:00 -07005680 }
5681
5682 /**
Stuart Scott54788802015-03-30 13:18:01 -07005683 * Set the network selection mode to automatic.
5684 *
5685 */
5686 @Override
5687 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5689 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
shilufc958392020-01-20 11:36:01 -08005693 if (!isActiveSubscription(subId)) {
5694 return;
5695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005697 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5698 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Stuart Scott54788802015-03-30 13:18:01 -07005702 }
5703
Jack Yud10cdd42020-09-28 20:28:01 -07005704 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005705 * Ask the radio to connect to the input network and change selection mode to manual.
5706 *
5707 * @param subId the id of the subscription.
5708 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5709 * the operator to attach to.
5710 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5711 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5712 * normal network selection next time.
5713 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005714 */
5715 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005716 public boolean setNetworkSelectionModeManual(
5717 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005720
5721 if (!isActiveSubscription(subId)) {
5722 return false;
5723 }
5724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005727 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005729 if (DBG) {
5730 log("setNetworkSelectionModeManual: subId: " + subId
5731 + " operator: " + operatorInfo);
5732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005737 }
shilu84f6e8b2019-12-19 13:58:01 -08005738 /**
5739 * Get the manual network selection
5740 *
5741 * @param subId the id of the subscription.
5742 *
5743 * @return the previously saved user selected PLMN
5744 */
5745 @Override
5746 public String getManualNetworkSelectionPlmn(int subId) {
5747 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005748 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005749 mApp, subId, "getManualNetworkSelectionPlmn");
5750
5751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 if (!isActiveSubscription(subId)) {
5754 return "";
5755 }
5756
5757 final Phone phone = getPhone(subId);
5758 if (phone == null) {
5759 return "";
5760 }
5761 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5762 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5763 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
5767 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005768
5769 /**
5770 * Scans for available networks.
5771 */
5772 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005773 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5774 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5776 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005777 LocationAccessPolicy.LocationPermissionResult locationResult =
5778 LocationAccessPolicy.checkLocationPermission(mApp,
5779 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5780 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005781 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005782 .setCallingPid(Binder.getCallingPid())
5783 .setCallingUid(Binder.getCallingUid())
5784 .setMethod("getCellNetworkScanResults")
5785 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005786 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5787 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005788 .build());
5789 switch (locationResult) {
5790 case DENIED_HARD:
5791 throw new SecurityException("Not allowed to access scan results -- location");
5792 case DENIED_SOFT:
5793 return null;
5794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795
Pengquan Menga1bb6272018-09-06 09:59:22 -07005796 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 try {
5798 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005799 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005804 }
5805
5806 /**
sqian80370722020-01-29 15:02:51 -08005807 * Get the call forwarding info, given the call forwarding reason.
5808 */
5809 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005810 public void getCallForwarding(int subId, int callForwardingReason,
5811 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005812 enforceReadPrivilegedPermission("getCallForwarding");
5813 long identity = Binder.clearCallingIdentity();
5814 try {
5815 if (DBG) {
5816 log("getCallForwarding: subId " + subId
5817 + " callForwardingReason" + callForwardingReason);
5818 }
Hall Liua1acea22020-09-18 19:04:59 -07005819
5820 Phone phone = getPhone(subId);
5821 if (phone == null) {
5822 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005823 callback.onError(
5824 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005825 } catch (RemoteException e) {
5826 // ignore
5827 }
5828 return;
5829 }
5830
5831 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5832 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5833 @Override
5834 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5835 try {
5836 callback.onCallForwardingInfoAvailable(info);
5837 } catch (RemoteException e) {
5838 // ignore
5839 }
5840 }
5841
5842 @Override
5843 public void onError(int error) {
5844 try {
5845 callback.onError(error);
5846 } catch (RemoteException e) {
5847 // ignore
5848 }
5849 }
5850 });
5851 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
5855 }
5856
5857 /**
5858 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5859 * reason, the number to forward, and the timeout before the forwarding is attempted.
5860 */
5861 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005862 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5863 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005864 enforceModifyPermission();
5865 long identity = Binder.clearCallingIdentity();
5866 try {
5867 if (DBG) {
5868 log("setCallForwarding: subId " + subId
5869 + " callForwardingInfo" + callForwardingInfo);
5870 }
Hall Liua1acea22020-09-18 19:04:59 -07005871
5872 Phone phone = getPhone(subId);
5873 if (phone == null) {
5874 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005875 callback.accept(
5876 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005877 } catch (RemoteException e) {
5878 // ignore
5879 }
5880 return;
5881 }
5882
5883 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5884 FunctionalUtils.ignoreRemoteException(callback::accept));
5885
5886 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
5890 }
5891
5892 /**
Hall Liua1acea22020-09-18 19:04:59 -07005893 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005894 */
5895 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005896 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005897 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005898 long identity = Binder.clearCallingIdentity();
5899 try {
Hall Liua1acea22020-09-18 19:04:59 -07005900 Phone phone = getPhone(subId);
5901 if (phone == null) {
5902 try {
5903 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5904 } catch (RemoteException e) {
5905 // ignore
5906 }
5907 return;
5908 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005909 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5910 PersistableBundle c = configManager.getConfigForSubId(subId);
5911 boolean requireUssd = c.getBoolean(
5912 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005913
sqian80370722020-01-29 15:02:51 -08005914 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005915 if (requireUssd) {
5916 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5917 getSubscriptionCarrierId(subId));
5918 String newUssdCommand = "";
5919 try {
5920 newUssdCommand = carrierXmlParser.getFeature(
5921 CarrierXmlParser.FEATURE_CALL_WAITING)
5922 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5923 } catch (NullPointerException e) {
5924 loge("Failed to generate USSD number" + e);
5925 }
5926 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5927 mMainThreadHandler, callback, carrierXmlParser,
5928 CarrierXmlParser.SsEntry.SSAction.QUERY);
5929 final String ussdCommand = newUssdCommand;
5930 Executors.newSingleThreadExecutor().execute(() -> {
5931 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5932 });
5933 } else {
5934 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5935 callback::accept);
5936 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5937 }
sqian80370722020-01-29 15:02:51 -08005938 } finally {
5939 Binder.restoreCallingIdentity(identity);
5940 }
5941 }
5942
5943 /**
Hall Liua1acea22020-09-18 19:04:59 -07005944 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005945 */
5946 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005947 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005948 enforceModifyPermission();
5949 long identity = Binder.clearCallingIdentity();
5950 try {
Hall Liua1acea22020-09-18 19:04:59 -07005951 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5952
5953 Phone phone = getPhone(subId);
5954 if (phone == null) {
5955 try {
5956 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5957 } catch (RemoteException e) {
5958 // ignore
5959 }
5960 return;
5961 }
5962
SongFerngWangc63cf522021-03-31 22:08:45 +08005963 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5964 PersistableBundle c = configManager.getConfigForSubId(subId);
5965 boolean requireUssd = c.getBoolean(
5966 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005967
SongFerngWangc63cf522021-03-31 22:08:45 +08005968 if (DBG) log("getCallWaitingStatus: subId " + subId);
5969 if (requireUssd) {
5970 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5971 getSubscriptionCarrierId(subId));
5972 CarrierXmlParser.SsEntry.SSAction ssAction =
5973 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5974 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5975 String newUssdCommand = "";
5976 try {
5977 newUssdCommand = carrierXmlParser.getFeature(
5978 CarrierXmlParser.FEATURE_CALL_WAITING)
5979 .makeCommand(ssAction, null);
5980 } catch (NullPointerException e) {
5981 loge("Failed to generate USSD number" + e);
5982 }
5983 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5984 mMainThreadHandler, callback, carrierXmlParser, ssAction);
5985 final String ussdCommand = newUssdCommand;
5986 Executors.newSingleThreadExecutor().execute(() -> {
5987 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5988 });
5989 } else {
5990 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5991 FunctionalUtils.ignoreRemoteException(callback::accept));
5992
5993 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
5994 }
sqian80370722020-01-29 15:02:51 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
5998 }
5999
6000 /**
yinxub1bed742017-04-17 11:45:04 -07006001 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006002 *
yinxub1bed742017-04-17 11:45:04 -07006003 * @param subId id of the subscription
6004 * @param request contains the radio access networks with bands/channels to scan
6005 * @param messenger callback messenger for scan results or errors
6006 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006007 * @return the id of the requested scan which can be used to stop the scan.
6008 */
6009 @Override
6010 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006011 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006014 LocationAccessPolicy.LocationPermissionResult locationResult =
6015 LocationAccessPolicy.checkLocationPermission(mApp,
6016 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6017 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006018 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006019 .setCallingPid(Binder.getCallingPid())
6020 .setCallingUid(Binder.getCallingUid())
6021 .setMethod("requestNetworkScan")
6022 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6023 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006024 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006025 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6026 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006027 if (e != null) {
6028 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6029 throw e;
6030 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006031 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006032 return TelephonyScanManager.INVALID_SCAN_ID;
6033 }
6034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 }
Hall Liu912dfd32019-04-25 14:02:26 -07006036 int callingUid = Binder.getCallingUid();
6037 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006038 final long identity = Binder.clearCallingIdentity();
6039 try {
6040 return mNetworkScanRequestTracker.startNetworkScan(
6041 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006042 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006043 } finally {
6044 Binder.restoreCallingIdentity(identity);
6045 }
yinxu504e1392017-04-12 16:03:22 -07006046 }
6047
Hall Liub2ac8ef2019-02-28 15:56:23 -08006048 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006049 NetworkScanRequest request, int subId, String callingPackage) {
6050 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006051 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6052 boolean hasNetworkScanPermission =
6053 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6054 == PERMISSION_GRANTED;
6055
6056 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6057 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6058 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006059 }
6060
6061 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6062 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006063 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6064 return new SecurityException("Specific channels must not be"
6065 + " scanned without location access.");
6066 }
6067 }
6068 }
6069
Hall Liub2ac8ef2019-02-28 15:56:23 -08006070 return null;
6071 }
6072
yinxu504e1392017-04-12 16:03:22 -07006073 /**
6074 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006075 *
6076 * @param subId id of the subscription
6077 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006078 */
6079 @Override
6080 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6082 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083
Hall Liu912dfd32019-04-25 14:02:26 -07006084 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 final long identity = Binder.clearCallingIdentity();
6086 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006087 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
yinxu504e1392017-04-12 16:03:22 -07006091 }
6092
6093 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006094 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006095 *
SongFerngWang9e060372020-12-21 16:41:52 +08006096 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006097 */
6098 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006099 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006100 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006101 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006102 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103
6104 final long identity = Binder.clearCallingIdentity();
6105 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006106 if (DBG) log("getAllowedNetworkTypesBitmask");
6107 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6108 int networkTypesBitmask = (result != null ? result[0] : -1);
6109 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6110 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006114 }
6115
6116 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006117 * Get the allowed network types for certain reason.
6118 *
6119 * @param subId the id of the subscription.
6120 * @param reason the reason the allowed network type change is taking place
6121 * @return the allowed network types.
6122 */
6123 @Override
6124 public long getAllowedNetworkTypesForReason(int subId,
6125 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006126 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006127 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
6134 }
6135
6136 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006137 * Enable/Disable E-UTRA-NR Dual Connectivity
6138 * @param subId subscription id of the sim card
6139 * @param nrDualConnectivityState expected NR dual connectivity state
6140 * This can be passed following states
6141 * <ol>
6142 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6143 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6144 * <li>Disable NR dual connectivity and force secondary cell to be released
6145 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6146 * </ol>
6147 * @return operation result.
6148 */
6149 @Override
6150 public int setNrDualConnectivityState(int subId,
6151 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6153 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006154 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006155 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6156 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6157 }
6158
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6163 nrDualConnectivityState, subId,
6164 workSource);
6165 if (DBG) log("enableNRDualConnectivity result: " + result);
6166 return result;
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
6170 }
6171
6172 /**
6173 * Is E-UTRA-NR Dual Connectivity enabled
6174 * @return true if dual connectivity is enabled else false
6175 */
6176 @Override
6177 public boolean isNrDualConnectivityEnabled(int subId) {
6178 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006179 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006180 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006181 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006182 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6183 return false;
6184 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6189 null, subId, workSource);
6190 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6191 return isEnabled;
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
6195 }
6196
6197 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006198 * Set the allowed network types of the device and
6199 * provide the reason triggering the allowed network change.
6200 *
6201 * @param subId the id of the subscription.
6202 * @param reason the reason the allowed network type change is taking place
6203 * @param allowedNetworkTypes the allowed network types.
6204 * @return true on success; false on any failure.
6205 */
6206 @Override
6207 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006208 @TelephonyManager.AllowedNetworkTypesReason int reason,
6209 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6211 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006212 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6213 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6214 return false;
6215 }
6216
SongFerngWang522637d2021-03-02 22:09:29 +08006217 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6218 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6219
6220
6221 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6222 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6223 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006224 }
SongFerngWang522637d2021-03-02 22:09:29 +08006225
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006226 final long identity = Binder.clearCallingIdentity();
6227 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006228 Boolean success = (Boolean) sendRequest(
6229 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6230 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6231
6232 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6233 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006234 } finally {
6235 Binder.restoreCallingIdentity(identity);
6236 }
6237 }
6238
6239 /**
Miaoa84611c2019-03-15 09:21:10 +08006240 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006241 *
Miaoa84611c2019-03-15 09:21:10 +08006242 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006243 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006244 * @hide
6245 */
6246 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006247 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 try {
Miaoa84611c2019-03-15 09:21:10 +08006252 if (phone != null) {
6253 return phone.hasMatchedTetherApnSetting();
6254 } else {
6255 return false;
6256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006259 }
Junda Liu475951f2014-11-07 16:45:03 -08006260 }
6261
6262 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006263 * Enable or disable always reporting signal strength changes from radio.
6264 *
6265 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6266 */
6267 @Override
6268 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6269 enforceModifyPermission();
6270 enforceSystemCaller();
6271
6272 final long identity = Binder.clearCallingIdentity();
6273 final Phone phone = getPhone(subId);
6274 try {
6275 if (phone != null) {
6276 if (DBG) {
6277 log("setAlwaysReportSignalStrength: subId=" + subId
6278 + " isEnable=" + isEnable);
6279 }
6280 phone.setAlwaysReportSignalStrength(isEnable);
6281 } else {
6282 loge("setAlwaysReportSignalStrength: no phone found for subId="
6283 + subId);
6284 }
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
6287 }
6288 }
6289
6290 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006291 * Get the user enabled state of Mobile Data.
6292 *
6293 * TODO: remove and use isUserDataEnabled.
6294 * This can't be removed now because some vendor codes
6295 * calls through ITelephony directly while they should
6296 * use TelephonyManager.
6297 *
6298 * @return true on enabled
6299 */
6300 @Override
6301 public boolean getDataEnabled(int subId) {
6302 return isUserDataEnabled(subId);
6303 }
6304
6305 /**
6306 * Get whether mobile data is enabled per user setting.
6307 *
6308 * There are other factors deciding whether mobile data is actually enabled, but they are
6309 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006310 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006311 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006312 *
6313 * @return {@code true} if data is enabled else {@code false}
6314 */
6315 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006316 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006317 try {
6318 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6319 null);
6320 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6322 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324
6325 final long identity = Binder.clearCallingIdentity();
6326 try {
6327 int phoneId = mSubscriptionController.getPhoneId(subId);
6328 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6329 Phone phone = PhoneFactory.getPhone(phoneId);
6330 if (phone != null) {
6331 boolean retVal = phone.isUserDataEnabled();
6332 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6333 return retVal;
6334 } else {
6335 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6336 return false;
6337 }
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006340 }
6341 }
6342
6343 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006344 * Checks if the device is capable of mobile data by considering whether whether the
6345 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6346 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006347 *
Shuo Qian985d1232020-01-08 14:30:06 -08006348 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006349 */
6350 @Override
6351 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006352 try {
6353 try {
6354 mApp.enforceCallingOrSelfPermission(
6355 android.Manifest.permission.ACCESS_NETWORK_STATE,
6356 null);
6357 } catch (Exception e) {
6358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6359 "isDataEnabled");
6360 }
6361 } catch (Exception e) {
6362 enforceReadPrivilegedPermission("isDataEnabled");
6363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364
6365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 int phoneId = mSubscriptionController.getPhoneId(subId);
6368 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6369 Phone phone = PhoneFactory.getPhone(phoneId);
6370 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006371 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6373 return retVal;
6374 } else {
6375 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6376 return false;
6377 }
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006380 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006381 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006382
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006383 /**
6384 * Check if data is enabled for a specific reason
6385 * @param subId Subscription index
6386 * @param reason the reason the data enable change is taking place
6387 * @return {@code true} if the overall data is enabled; {@code false} if not.
6388 */
6389 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006390 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006391 @TelephonyManager.DataEnabledReason int reason) {
6392 try {
6393 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6394 null);
6395 } catch (Exception e) {
6396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006397 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006398 }
6399
6400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 int phoneId = mSubscriptionController.getPhoneId(subId);
6404 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006405 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006406 + " reason=" + reason);
6407 }
6408 Phone phone = PhoneFactory.getPhone(phoneId);
6409 if (phone != null) {
6410 boolean retVal;
6411 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6412 retVal = phone.isUserDataEnabled();
6413 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006414 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006415 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006416 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006417 return retVal;
6418 } else {
6419 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006420 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006421 + subId + " retVal=false");
6422 }
6423 return false;
6424 }
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006430 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006431 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006432 if (uid == Process.PHONE_UID) {
6433 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6434 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006435 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6436 }
6437
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006438 //load access rules from carrier configs, and check those as well: b/139133814
6439 SubscriptionController subController = SubscriptionController.getInstance();
6440 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6441 || subController == null) return privilegeFromSim;
6442
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006443 PackageManager pkgMgr = phone.getContext().getPackageManager();
6444 String[] packages = pkgMgr.getPackagesForUid(uid);
6445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006448 int subId = phone.getSubId();
6449 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6450 // A test override is in place for the privileges for this subId, so don't try to
6451 // read the subscription privileges.
6452 return privilegeFromSim;
6453 }
6454 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006455 SubscriptionManager subManager = (SubscriptionManager)
6456 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6457 for (String pkg : packages) {
6458 if (subManager.canManageSubscription(subInfo, pkg)) {
6459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6460 }
6461 }
6462 return privilegeFromSim;
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6469 String pkgName) {
6470 //load access rules from carrier configs, and check those as well: b/139133814
6471 SubscriptionController subController = SubscriptionController.getInstance();
6472 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6473 || subController == null) return privilegeFromSim;
6474
6475 final long identity = Binder.clearCallingIdentity();
6476 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006477 int subId = phone.getSubId();
6478 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6479 // A test override is in place for the privileges for this subId, so don't try to
6480 // read the subscription privileges.
6481 return privilegeFromSim;
6482 }
6483 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006484 SubscriptionManager subManager = (SubscriptionManager)
6485 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6486 return subManager.canManageSubscription(subInfo, pkgName)
6487 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
6492
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006493 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006494 public int getCarrierPrivilegeStatus(int subId) {
6495 final Phone phone = getPhone(subId);
6496 if (phone == null) {
6497 loge("getCarrierPrivilegeStatus: Invalid subId");
6498 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6499 }
6500 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006501 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006502 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006503 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6504 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006505
6506 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6507 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006508 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006509 }
Junda Liu29340342014-07-10 15:23:27 -07006510
6511 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006512 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006513 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006514 final Phone phone = getPhone(subId);
6515 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006516 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006517 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6518 }
6519 UiccProfile profile =
6520 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6521 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006522 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006523 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6524 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006525 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006526 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006527 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006528 }
6529
6530 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006531 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6532 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006533 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006534 }
6535
6536 int phoneId = SubscriptionManager.getPhoneId(subId);
6537 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006538 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006539 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006540 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6541 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006542 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6543 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6544 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006545 }
6546
6547 @Override
6548 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006549 if (TextUtils.isEmpty(pkgName))
6550 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006551 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6553 UiccCard card = UiccController.getInstance().getUiccCard(i);
6554 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006555 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006556 continue;
6557 }
6558
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006559 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6560 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6561 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006562 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6563 break;
6564 }
6565 }
6566
6567 return result;
Junda Liu29340342014-07-10 15:23:27 -07006568 }
Derek Tan89e89d42014-07-08 17:00:10 -07006569
6570 @Override
Junda Liue64de782015-04-16 17:19:16 -07006571 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6572 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6573 loge("phoneId " + phoneId + " is not valid.");
6574 return null;
6575 }
6576 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006577 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006578 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006579 return null ;
6580 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006581 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006582 }
6583
Amith Yamasani6e118872016-02-19 12:53:51 -08006584 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006585 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006586 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006587 List<String> privilegedPackages = new ArrayList<>();
6588 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006589 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6590 // has UICC in that slot.
6591 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006592 if (card.hasCarrierPrivilegeRules()) {
6593 if (packages == null) {
6594 // Only check packages in user 0 for now
6595 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006596 PackageManager.MATCH_DISABLED_COMPONENTS
6597 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006598 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006599 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006600 }
6601 for (int p = packages.size() - 1; p >= 0; p--) {
6602 PackageInfo pkgInfo = packages.get(p);
6603 if (pkgInfo != null && pkgInfo.packageName != null
6604 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006605 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006606 privilegedPackages.add(pkgInfo.packageName);
6607 }
6608 }
6609 }
6610 }
6611 return privilegedPackages;
6612 }
6613
chen xuf7e9fe82019-05-09 19:31:02 -07006614 @Override
6615 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006616 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6617
6618 final long identity = Binder.clearCallingIdentity();
6619
chen xuf7e9fe82019-05-09 19:31:02 -07006620 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006621 try {
6622 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6623 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6624 }
6625 } finally {
6626 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006627 }
6628 return privilegedPackages;
6629 }
6630
Wink Savilleb564aae2014-10-23 10:18:09 -07006631 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006632 final Phone phone = getPhone(subId);
6633 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006634 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006635 return null;
6636 }
6637 String iccId = card.getIccId();
6638 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006639 return null;
6640 }
6641 return iccId;
6642 }
6643
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006644 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006645 public void setCallComposerStatus(int subId, int status) {
6646 enforceModifyPermission();
6647
6648 final long identity = Binder.clearCallingIdentity();
6649 try {
6650 Phone phone = getPhone(subId);
6651 if (phone != null) {
6652 Phone defaultPhone = phone.getImsPhone();
6653 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6654 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6655 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006656 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6657 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006658 }
6659 }
Shuo Qiand8782462020-12-22 19:10:14 -08006660 } catch (ImsException e) {
6661 throw new ServiceSpecificException(e.getCode());
6662 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006663 Binder.restoreCallingIdentity(identity);
6664 }
6665 }
6666
6667 @Override
6668 public int getCallComposerStatus(int subId) {
6669 enforceReadPrivilegedPermission("getCallComposerStatus");
6670
6671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 Phone phone = getPhone(subId);
6674 if (phone != null) {
6675 Phone defaultPhone = phone.getImsPhone();
6676 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6677 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6678 return imsPhone.getCallComposerStatus();
6679 }
6680 }
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
6684 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6685 }
6686
6687 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006688 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6689 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006690 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006691 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 final String iccId = getIccId(subId);
6696 final Phone phone = getPhone(subId);
6697 if (phone == null) {
6698 return false;
6699 }
6700 final String subscriberId = phone.getSubscriberId();
6701
6702 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006703 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 + subscriberId + " to " + number);
6705 }
6706
6707 if (TextUtils.isEmpty(iccId)) {
6708 return false;
6709 }
6710
6711 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6712
6713 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6714 if (alphaTag == null) {
6715 editor.remove(alphaTagPrefKey);
6716 } else {
6717 editor.putString(alphaTagPrefKey, alphaTag);
6718 }
6719
6720 // Record both the line number and IMSI for this ICCID, since we need to
6721 // track all merged IMSIs based on line number
6722 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6723 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6724 if (number == null) {
6725 editor.remove(numberPrefKey);
6726 editor.remove(subscriberPrefKey);
6727 } else {
6728 editor.putString(numberPrefKey, number);
6729 editor.putString(subscriberPrefKey, subscriberId);
6730 }
6731
6732 editor.commit();
6733 return true;
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006736 }
Derek Tan7226c842014-07-02 17:42:23 -07006737 }
6738
6739 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006740 public String getLine1NumberForDisplay(int subId, String callingPackage,
6741 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006742 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006744 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006745 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006746 return null;
6747 }
Derek Tan97ebb422014-09-05 16:55:38 -07006748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 String iccId = getIccId(subId);
6752 if (iccId != null) {
6753 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6754 if (DBG_MERGE) {
6755 log("getLine1NumberForDisplay returning "
6756 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6757 }
6758 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6761 return null;
6762 } finally {
6763 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006764 }
Derek Tan7226c842014-07-02 17:42:23 -07006765 }
6766
6767 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006768 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6769 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006771 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006772 return null;
6773 }
Derek Tan97ebb422014-09-05 16:55:38 -07006774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 String iccId = getIccId(subId);
6778 if (iccId != null) {
6779 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6780 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6781 }
6782 return null;
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006785 }
Derek Tan7226c842014-07-02 17:42:23 -07006786 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006787
6788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006789 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6790 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006791 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6792 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006794 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006795 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006796 return null;
6797 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006798
Jordan Liub49b04b2019-05-06 14:45:15 -07006799 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6800 // the process, where TelephonyManager was instantiated.
6801 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006802 final long identity = Binder.clearCallingIdentity();
6803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006804 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 final TelephonyManager tele = TelephonyManager.from(context);
6806 final SubscriptionManager sub = SubscriptionManager.from(context);
6807
6808 // Figure out what subscribers are currently active
6809 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810
Jordan Liub49b04b2019-05-06 14:45:15 -07006811 // Only consider subs which match the current subId
6812 // This logic can be simplified. See b/131189269 for progress.
6813 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006814 activeSubscriberIds.add(tele.getSubscriberId(subId));
6815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816
6817 // First pass, find a number override for an active subscriber
6818 String mergeNumber = null;
6819 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6820 for (String key : prefs.keySet()) {
6821 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6822 final String subscriberId = (String) prefs.get(key);
6823 if (activeSubscriberIds.contains(subscriberId)) {
6824 final String iccId = key.substring(
6825 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6826 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6827 mergeNumber = (String) prefs.get(numberKey);
6828 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006829 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830 + " for active subscriber " + subscriberId);
6831 }
6832 if (!TextUtils.isEmpty(mergeNumber)) {
6833 break;
6834 }
6835 }
6836 }
6837 }
6838
6839 // Shortcut when no active merged subscribers
6840 if (TextUtils.isEmpty(mergeNumber)) {
6841 return null;
6842 }
6843
6844 // Second pass, find all subscribers under that line override
6845 final ArraySet<String> result = new ArraySet<>();
6846 for (String key : prefs.keySet()) {
6847 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6848 final String number = (String) prefs.get(key);
6849 if (mergeNumber.equals(number)) {
6850 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6851 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6852 final String subscriberId = (String) prefs.get(subscriberKey);
6853 if (!TextUtils.isEmpty(subscriberId)) {
6854 result.add(subscriberId);
6855 }
6856 }
6857 }
6858 }
6859
6860 final String[] resultArray = result.toArray(new String[result.size()]);
6861 Arrays.sort(resultArray);
6862 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006863 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6865 }
6866 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006867 } finally {
6868 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006869 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006870 }
6871
6872 @Override
zoey chen38003472019-12-13 17:16:31 +08006873 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6874 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 final TelephonyManager telephonyManager = mApp.getSystemService(
6879 TelephonyManager.class);
6880 String subscriberId = telephonyManager.getSubscriberId(subId);
6881 if (subscriberId == null) {
6882 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006883 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006884 + subId);
6885 }
6886 return null;
6887 }
6888
6889 final SubscriptionInfo info = SubscriptionController.getInstance()
6890 .getSubscriptionInfo(subId);
6891 final ParcelUuid groupUuid = info.getGroupUuid();
6892 // If it doesn't belong to any group, return just subscriberId of itself.
6893 if (groupUuid == null) {
6894 return new String[]{subscriberId};
6895 }
6896
6897 // Get all subscriberIds from the group.
6898 final List<String> mergedSubscriberIds = new ArrayList<>();
6899 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006900 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006901 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006902 for (SubscriptionInfo subInfo : groupInfos) {
6903 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6904 if (subscriberId != null) {
6905 mergedSubscriberIds.add(subscriberId);
6906 }
6907 }
6908
6909 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912
6913 }
6914 }
6915
6916 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006917 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006918 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006919 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920
6921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 final Phone phone = getPhone(subId);
6924 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6925 } finally {
6926 Binder.restoreCallingIdentity(identity);
6927 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006928 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006929
6930 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006931 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006932 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6933 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006934 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6935 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936
6937 final long identity = Binder.clearCallingIdentity();
6938 try {
6939 final Phone phone = getPhone(subId);
6940 if (phone == null) {
6941 return false;
6942 }
6943 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6944 cdmaNonRoamingList);
6945 } finally {
6946 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006947 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006948 }
6949
6950 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006951 @Deprecated
6952 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6953 enforceModifyPermission();
6954
6955 int returnValue = 0;
6956 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006957 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006958 if(result.exception == null) {
6959 if (result.result != null) {
6960 byte[] responseData = (byte[])(result.result);
6961 if(responseData.length > oemResp.length) {
6962 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6963 responseData.length + "bytes. Buffer Size is " +
6964 oemResp.length + "bytes.");
6965 }
6966 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6967 returnValue = responseData.length;
6968 }
6969 } else {
6970 CommandException ex = (CommandException) result.exception;
6971 returnValue = ex.getCommandError().ordinal();
6972 if(returnValue > 0) returnValue *= -1;
6973 }
6974 } catch (RuntimeException e) {
6975 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6976 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6977 if(returnValue > 0) returnValue *= -1;
6978 }
6979
6980 return returnValue;
6981 }
6982
6983 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006984 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006985 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006986 try {
6987 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006988 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006989 mApp, phone.getSubId(), "getRadioAccessFamily");
6990 } catch (SecurityException e) {
6991 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6992 throw e;
6993 }
chen xub97461a2018-10-26 14:17:57 -07006994 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006995 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006996 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final long identity = Binder.clearCallingIdentity();
6999 try {
chen xub97461a2018-10-26 14:17:57 -07007000 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007001 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007002 mApp, phone.getSubId(), "getRadioAccessFamily");
7003 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
chen xub97461a2018-10-26 14:17:57 -07007007 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007008 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007009
7010 @Override
7011 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007012 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007013 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 final long identity = Binder.clearCallingIdentity();
7016 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007017 ImsManager.getInstance(defaultPhone.getContext(),
7018 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 } finally {
7020 Binder.restoreCallingIdentity(identity);
7021 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007022 }
7023
7024 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007025 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007026 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7028 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007029 return false;
7030 }
Svet Ganovb320e182015-04-16 12:30:10 -07007031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 // Check the user preference and the system-level IMS setting. Even if the user has
7035 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7036 // In the long run, we may instead need to check if there exists a connection service
7037 // which can support video calling.
7038 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007039 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 return imsManager.isVtEnabledByPlatform()
7041 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7042 && imsManager.isVtEnabledByUser();
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007046 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007047
Andrew Leea1239f22015-03-02 17:44:07 -08007048 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007049 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7050 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007052 mApp, subId, callingPackage, callingFeatureId,
7053 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 return false;
7055 }
7056
7057 final long identity = Binder.clearCallingIdentity();
7058 try {
7059 CarrierConfigManager configManager =
7060 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007061 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
Andrew Leea1239f22015-03-02 17:44:07 -08007066 }
7067
7068 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007069 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007071 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 return false;
7073 }
7074
7075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 CarrierConfigManager configManager =
7078 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
Andrew Leea1239f22015-03-02 17:44:07 -08007084 }
7085
Andrew Lee9431b832015-03-09 18:46:45 -07007086 @Override
7087 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007088 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007089 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007090 }
7091
7092 @Override
7093 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 final long identity = Binder.clearCallingIdentity();
7095 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007096 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 } finally {
7098 Binder.restoreCallingIdentity(identity);
7099 }
Andrew Lee9431b832015-03-09 18:46:45 -07007100 }
7101
Hall Liuf6668912018-10-31 17:05:23 -07007102 /**
7103 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7104 * support for the feature and device firmware support.
7105 *
7106 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7107 */
7108 @Override
7109 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007111 final Phone phone = getPhone(subscriptionId);
7112 if (phone == null) {
7113 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7114 return false;
7115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007117 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7119 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 return isCarrierSupported && isDeviceSupported;
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
Hall Liu98187582018-01-22 19:15:32 -08007125 }
7126
Hall Liuf6668912018-10-31 17:05:23 -07007127 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007128 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7129 * RTT setting, will return true if the device and carrier both support RTT.
7130 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007131 */
7132 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007135 boolean isRttSupported = isRttSupported(subscriptionId);
7136 boolean isUserRttSettingOn = Settings.Secure.getInt(
7137 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7138 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7139 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7140 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007144 }
7145
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007146 @Deprecated
7147 @Override
7148 public String getDeviceId(String callingPackage) {
7149 return getDeviceIdWithFeature(callingPackage, null);
7150 }
7151
Sanket Padawe7310cc72015-01-14 09:53:20 -08007152 /**
7153 * Returns the unique device ID of phone, for example, the IMEI for
7154 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7155 *
7156 * <p>Requires Permission:
7157 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7158 */
7159 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007160 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007161 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007162 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007163 return null;
7164 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007165 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007166 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007167 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007168 return null;
7169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170
7171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 return phone.getDeviceId();
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
7176 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007177 }
7178
Ping Sunc67b7c22016-03-02 19:16:45 +08007179 /**
7180 * {@hide}
7181 * Returns the IMS Registration Status on a particular subid
7182 *
7183 * @param subId
7184 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007185 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007186 Phone phone = getPhone(subId);
7187 if (phone != null) {
7188 return phone.isImsRegistered();
7189 } else {
7190 return false;
7191 }
7192 }
7193
Santos Cordon7a1885b2015-02-03 11:15:19 -08007194 @Override
7195 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007202 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007203
Tyler Gunnf70ed162019-04-03 15:28:53 -07007204 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007205 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007206 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007208 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007209 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7210 }
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
7217 }
7218
7219 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007220 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007221 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7222 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 Phone phone = getPhone(subscriptionId);
7226 if (phone == null) {
7227 return null;
7228 }
7229 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007235 /**
7236 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007237 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007238 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 Phone phone = getPhone(subId);
7242 if (phone != null) {
7243 return phone.isWifiCallingEnabled();
7244 } else {
7245 return false;
7246 }
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007249 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007250 }
7251
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007252 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007253 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007254 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007255 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 Phone phone = getPhone(subId);
7259 if (phone != null) {
7260 return phone.isVideoEnabled();
7261 } else {
7262 return false;
7263 }
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007266 }
7267 }
7268
7269 /**
7270 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7271 * defined in {@link ImsRegistrationImplBase}.
7272 */
7273 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 Phone phone = getPhone(subId);
7277 if (phone != null) {
7278 return phone.getImsRegistrationTech();
7279 } else {
7280 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7281 }
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007284 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007285 }
7286
Stuart Scott8eef64f2015-04-08 15:13:54 -07007287 @Override
7288 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007289 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007290 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7291 return;
7292 }
7293
Svet Ganovcc087f82015-05-12 20:35:54 -07007294 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007295
Svet Ganovcc087f82015-05-12 20:35:54 -07007296 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007297 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7298 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007299 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007300 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007301 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007302 Phone phone = getPhone(subId);
7303 if (phone != null) {
7304 SubscriptionManager.setSubscriptionProperty(subId,
7305 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7306 "user=" + RadioAccessFamily.getRafFromNetworkType(
7307 RILConstants.PREFERRED_NETWORK_MODE));
7308 phone.loadAllowedNetworksFromSubscriptionDatabase();
7309 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007310 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7311 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007312 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007313 // There has been issues when Sms raw table somehow stores orphan
7314 // fragments. They lead to garbled message when new fragments come
7315 // in and combined with those stale ones. In case this happens again,
7316 // user can reset all network settings which will clean up this table.
7317 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007318 // Clean up IMS settings as well here.
7319 int slotId = getSlotIndex(subId);
7320 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7321 ImsManager.getInstance(mApp, slotId).factoryReset();
7322 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007323
7324 // Erase modem config if erase modem on network setting is enabled.
7325 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7326 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7327 if (configValue != null && Boolean.parseBoolean(configValue)) {
7328 sendEraseModemConfig(getDefaultPhone());
7329 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007330 } finally {
7331 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007332 }
7333 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007334
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007335 private void cleanUpSmsRawTable(Context context) {
7336 ContentResolver resolver = context.getContentResolver();
7337 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7338 resolver.delete(uri, null, null);
7339 }
7340
Narayan Kamath1c496c22015-04-16 14:40:19 +01007341 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007342 public String getSimLocaleForSubscriber(int subId) {
7343 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7344 final Phone phone = getPhone(subId);
7345 if (phone == null) {
7346 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007347 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 final long identity = Binder.clearCallingIdentity();
7350 try {
chen xu5d3637b2019-01-21 23:31:38 -08007351 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007352 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007353 if (info == null) {
7354 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7355 return null;
7356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 // Try and fetch the locale from the carrier properties or from the SIM language
7358 // preferences (EF-PL and EF-LI)...
7359 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007361 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7362 if (localeFromDefaultSim != null) {
7363 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7364 if (DBG) log("Using locale from subId: " + subId + " locale: "
7365 + localeFromDefaultSim);
7366 return localeFromDefaultSim.toLanguageTag();
7367 } else {
7368 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 }
7370 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 // The SIM language preferences only store a language (e.g. fr = French), not an
7373 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7374 // the SIM and carrier preferences does not include a country we add the country
7375 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007376 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007378 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 return mccLocale.toLanguageTag();
7380 }
7381
7382 if (DBG) log("No locale found - returning null");
7383 return null;
7384 } finally {
7385 Binder.restoreCallingIdentity(identity);
7386 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007387 }
7388
7389 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007390 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007391 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007392 }
7393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 /**
7395 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7396 */
7397 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007398 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007399 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007400 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007401
Chenjie Yu1ba97252018-01-11 18:16:20 -08007402 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007403 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007404
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007405 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007406 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7407 * representing the state of the modem.
7408 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007409 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7410 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007411 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007412 */
7413 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007414 public void requestModemActivityInfo(ResultReceiver result) {
7415 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007416 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417
7418 final long identity = Binder.clearCallingIdentity();
7419 try {
sqian1a1be542020-03-05 11:37:28 -08007420 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 } finally {
7422 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007423 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007424 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007425
Siddharth Rayb8114062018-06-17 15:02:38 -07007426 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7427 // less than total activity duration.
7428 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7429 if (info == null) {
7430 return false;
7431 }
7432 int activityDurationMs =
7433 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7434 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007435 int[] txTimeMs = info.getTransmitTimeMillis();
7436 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7437 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007438 }
7439 return (info.isValid()
7440 && (info.getSleepTimeMillis() <= activityDurationMs)
7441 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007442 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007443 && (totalTxTimeMs <= activityDurationMs));
7444 }
7445
Jack Yu85bd38a2015-11-09 11:34:32 -08007446 /**
7447 * {@hide}
7448 * Returns the service state information on specified subscription.
7449 */
7450 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007451 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7452 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007454 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007455 return null;
7456 }
7457
Hall Liuf19c44f2018-11-27 14:38:17 -08007458 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7459 LocationAccessPolicy.checkLocationPermission(mApp,
7460 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7461 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007462 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007463 .setCallingPid(Binder.getCallingPid())
7464 .setCallingUid(Binder.getCallingUid())
7465 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007466 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007467 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007468 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7469 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007470 .build());
7471
7472 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7473 LocationAccessPolicy.checkLocationPermission(mApp,
7474 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7475 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007476 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007477 .setCallingPid(Binder.getCallingPid())
7478 .setCallingUid(Binder.getCallingUid())
7479 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007480 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007481 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007482 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7483 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007484 .build());
7485 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7486 boolean hasFinePermission =
7487 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7488 boolean hasCoarsePermission =
7489 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 final long identity = Binder.clearCallingIdentity();
7492 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007493 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7494 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7495 Rlog.d(LOG_TAG,
7496 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7497 return null;
7498 }
7499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final Phone phone = getPhone(subId);
7501 if (phone == null) {
7502 return null;
7503 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007504
Hall Liuf19c44f2018-11-27 14:38:17 -08007505 ServiceState ss = phone.getServiceState();
7506
7507 // Scrub out the location info in ServiceState depending on what level of access
7508 // the caller has.
7509 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007510 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7511 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007515 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007516
7517 /**
7518 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7519 *
7520 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7521 * voicemail ringtone.
7522 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7523 * PhoneAccount.
7524 */
7525 @Override
7526 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7530 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007531 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007538 }
7539
7540 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007541 * Sets the per-account voicemail ringtone.
7542 *
7543 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7544 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7545 *
7546 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7547 * voicemail ringtone.
7548 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7549 * PhoneAccount.
7550 */
7551 @Override
7552 public void setVoicemailRingtoneUri(String callingPackage,
7553 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007554 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007556 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7557 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7559 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7560 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7566 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 }
7569 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007572 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007573 }
7574
7575 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007576 * Returns whether vibration is set for voicemail notification in Phone settings.
7577 *
7578 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7579 * voicemail vibration setting.
7580 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7581 */
7582 @Override
7583 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7587 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007595 }
7596
Youhan Wange64578a2016-05-02 15:32:42 -07007597 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007598 * Sets the per-account voicemail vibration.
7599 *
7600 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7601 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7602 *
7603 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7604 * voicemail vibration setting.
7605 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7606 * specific PhoneAccount.
7607 */
7608 @Override
7609 public void setVoicemailVibrationEnabled(String callingPackage,
7610 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007611 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007612 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007613 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7614 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7616 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7617 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007618 }
7619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7623 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 }
7626 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7627 } finally {
7628 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007629 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007630 }
7631
7632 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007633 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7634 *
7635 * @throws SecurityException if the caller does not have the required permission
7636 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007637 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007639 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007640 }
7641
7642 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007643 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7644 * permission.
7645 *
7646 * @throws SecurityException if the caller does not have the required permission
7647 */
7648 private void enforceSendSmsPermission() {
7649 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7650 }
7651
7652 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007653 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007654 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007655 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007656 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007657 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 final long identity = Binder.clearCallingIdentity();
7659 try {
7660 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007661 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 if (componentName == null) {
7663 throw new SecurityException(
7664 "Caller not current active visual voicemail package[null]");
7665 }
7666 String vvmPackage = componentName.getPackageName();
7667 if (!callingPackage.equals(vvmPackage)) {
7668 throw new SecurityException("Caller not current active visual voicemail package["
7669 + vvmPackage + "]");
7670 }
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007673 }
7674 }
7675
7676 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007677 * Return the application ID for the app type.
7678 *
7679 * @param subId the subscription ID that this request applies to.
7680 * @param appType the uicc app type.
7681 * @return Application ID for specificied app type, or null if no uicc.
7682 */
7683 @Override
7684 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007685 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007686 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687
7688 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007689 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 if (phone == null) {
7691 return null;
7692 }
7693 String aid = null;
7694 try {
7695 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7696 .getApplicationByType(appType).getAid();
7697 } catch (Exception e) {
7698 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7699 }
7700 return aid;
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007703 }
Youhan Wange64578a2016-05-02 15:32:42 -07007704 }
7705
Youhan Wang4001d252016-05-11 10:29:41 -07007706 /**
7707 * Return the Electronic Serial Number.
7708 *
7709 * @param subId the subscription ID that this request applies to.
7710 * @return ESN or null if error.
7711 */
7712 @Override
7713 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007714 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007715 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716
7717 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007718 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 if (phone == null) {
7720 return null;
7721 }
7722 String esn = null;
7723 try {
7724 esn = phone.getEsn();
7725 } catch (Exception e) {
7726 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7727 }
7728 return esn;
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007731 }
Youhan Wang4001d252016-05-11 10:29:41 -07007732 }
7733
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007734 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007735 * Return the Preferred Roaming List Version.
7736 *
7737 * @param subId the subscription ID that this request applies to.
7738 * @return PRLVersion or null if error.
7739 */
7740 @Override
7741 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007742 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007743 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744
7745 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007746 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 if (phone == null) {
7748 return null;
7749 }
7750 String cdmaPrlVersion = null;
7751 try {
7752 cdmaPrlVersion = phone.getCdmaPrlVersion();
7753 } catch (Exception e) {
7754 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7755 }
7756 return cdmaPrlVersion;
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007759 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007760 }
7761
7762 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007763 * Get snapshot of Telephony histograms
7764 * @return List of Telephony histograms
7765 * @hide
7766 */
7767 @Override
7768 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7770 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771
7772 final long identity = Binder.clearCallingIdentity();
7773 try {
7774 return RIL.getTelephonyRILTimingHistograms();
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007778 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007779
7780 /**
7781 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007782 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7783 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007784 * Require system privileges. In the future we may add this to carrier APIs.
7785 *
Michele Berionne482f8202018-11-27 18:57:59 -08007786 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007787 */
7788 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007789 @TelephonyManager.SetCarrierRestrictionResult
7790 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007791 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007792 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007793
Michele Berionne482f8202018-11-27 18:57:59 -08007794 if (carrierRestrictionRules == null) {
7795 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007796 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 final long identity = Binder.clearCallingIdentity();
7799 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007800 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007801 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007805 }
7806
7807 /**
7808 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007809 * Get the allowed carrier list and the excluded carrier list, including the priority between
7810 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007811 * Require system privileges. In the future we may add this to carrier APIs.
7812 *
Michele Berionne482f8202018-11-27 18:57:59 -08007813 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007814 */
7815 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007816 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007817 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819
7820 final long identity = Binder.clearCallingIdentity();
7821 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007822 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7823 if (response instanceof CarrierRestrictionRules) {
7824 return (CarrierRestrictionRules) response;
7825 }
7826 // Response is an Exception of some kind,
7827 // which is signalled to the user as a NULL retval
7828 return null;
7829 } catch (Exception e) {
7830 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7831 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007835 }
7836
fionaxu59545b42016-05-25 15:53:37 -07007837 /**
fionaxu59545b42016-05-25 15:53:37 -07007838 * Action set from carrier signalling broadcast receivers to enable/disable radio
7839 * @param subId the subscription ID that this action applies to.
7840 * @param enabled control enable or disable radio.
7841 * {@hide}
7842 */
7843 @Override
7844 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7845 enforceModifyPermission();
7846 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847
7848 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007849 if (phone == null) {
7850 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7851 return;
7852 }
7853 try {
7854 phone.carrierActionSetRadioEnabled(enabled);
7855 } catch (Exception e) {
7856 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 } finally {
7858 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007859 }
7860 }
7861
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007862 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007863 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7864 * network status based on which carrier apps could apply actions accordingly,
7865 * enable/disable default url handler for example.
7866 *
7867 * @param subId the subscription ID that this action applies to.
7868 * @param report control start/stop reporting the default network status.
7869 * {@hide}
7870 */
7871 @Override
7872 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7873 enforceModifyPermission();
7874 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875
7876 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007877 if (phone == null) {
7878 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7879 return;
7880 }
7881 try {
7882 phone.carrierActionReportDefaultNetworkStatus(report);
7883 } catch (Exception e) {
7884 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 } finally {
7886 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007887 }
7888 }
7889
7890 /**
fionaxud9622282017-07-17 17:51:30 -07007891 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7892 * @param subId the subscription ID that this action applies to.
7893 * {@hide}
7894 */
7895 @Override
7896 public void carrierActionResetAll(int subId) {
7897 enforceModifyPermission();
7898 final Phone phone = getPhone(subId);
7899 if (phone == null) {
7900 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7901 return;
7902 }
7903 try {
7904 phone.carrierActionResetAll();
7905 } catch (Exception e) {
7906 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7907 }
7908 }
7909
7910 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007911 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7912 * bug report is being generated.
7913 */
7914 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007915 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007916 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7917 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007918 writer.println("Permission Denial: can't dump Phone from pid="
7919 + Binder.getCallingPid()
7920 + ", uid=" + Binder.getCallingUid()
7921 + "without permission "
7922 + android.Manifest.permission.DUMP);
7923 return;
7924 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007925 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007926 }
Jack Yueb89b242016-06-22 13:27:47 -07007927
Brad Ebingerdac2f002018-04-03 15:17:52 -07007928 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007929 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7930 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7931 @NonNull String[] args) {
7932 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7933 this, in.getFileDescriptor(), out.getFileDescriptor(),
7934 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007935 }
7936
Jack Yueb89b242016-06-22 13:27:47 -07007937 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007938 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007939 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007940 * @param reason the reason the data enable change is taking place
7941 * @param enabled True if enabling the data, otherwise disabling.
7942 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007943 */
7944 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007945 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007946 boolean enabled) {
7947 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7948 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7949 try {
7950 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007951 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007952 } catch (SecurityException se) {
7953 enforceModifyPermission();
7954 }
7955 } else {
7956 enforceModifyPermission();
7957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958
7959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 Phone phone = getPhone(subId);
7962 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007963 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7964 phone.carrierActionSetMeteredApnsEnabled(enabled);
7965 } else {
7966 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 }
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007971 }
7972 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007973
7974 /**
7975 * Get Client request stats
7976 * @return List of Client Request Stats
7977 * @hide
7978 */
7979 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007980 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7981 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007983 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007984 return null;
7985 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007986 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 if (phone != null) {
7991 return phone.getClientRequestStats();
7992 }
7993
7994 return null;
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007998 }
7999
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008000 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008001 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008002 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008003 }
Jack Yueb4124c2017-02-16 15:32:43 -08008004
8005 /**
Grace Chen70990072017-03-24 17:21:30 -07008006 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008007 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008008 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008009 * @param state State of SIM (power down, power up, pass through)
8010 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8011 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8012 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008013 *
8014 **/
8015 @Override
Grace Chen70990072017-03-24 17:21:30 -07008016 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008017 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008018 Phone phone = PhoneFactory.getPhone(slotIndex);
8019
vagdeviaf9a5b92018-08-15 16:01:53 -07008020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008025 phone.setSimPowerState(state, null, workSource);
8026 }
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
8030 }
8031
8032 /**
8033 * Set SIM card power state.
8034 *
8035 * @param slotIndex SIM slot id.
8036 * @param state State of SIM (power down, power up, pass through)
8037 * @param callback callback to trigger after success or failure
8038 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8039 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8040 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8041 *
8042 **/
8043 @Override
8044 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8045 IIntegerConsumer callback) {
8046 enforceModifyPermission();
8047 Phone phone = PhoneFactory.getPhone(slotIndex);
8048
8049 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8050
8051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 if (phone != null) {
8054 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8055 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 }
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008059 }
8060 }
Shuo Qiandd210312017-04-12 22:11:33 +00008061
Tyler Gunn65d45c22017-06-05 11:22:26 -07008062 private boolean isUssdApiAllowed(int subId) {
8063 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008064 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008065 if (configManager == null) {
8066 return false;
8067 }
8068 PersistableBundle pb = configManager.getConfigForSubId(subId);
8069 if (pb == null) {
8070 return false;
8071 }
8072 return pb.getBoolean(
8073 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8074 }
8075
Shuo Qiandd210312017-04-12 22:11:33 +00008076 /**
8077 * Check if phone is in emergency callback mode
8078 * @return true if phone is in emergency callback mode
8079 * @param subId sub id
8080 */
goneil9c5f4872017-12-05 14:07:56 -08008081 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008082 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008083 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008084 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085
8086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 if (phone != null) {
8089 return phone.isInEcm();
8090 } else {
8091 return false;
8092 }
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008095 }
8096 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008097
8098 /**
8099 * Get the current signal strength information for the given subscription.
8100 * Because this information is not updated when the device is in a low power state
8101 * it should not be relied-upon to be current.
8102 * @param subId Subscription index
8103 * @return the most recent cached signal strength info from the modem
8104 */
8105 @Override
8106 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 final long identity = Binder.clearCallingIdentity();
8108 try {
8109 Phone p = getPhone(subId);
8110 if (p == null) {
8111 return null;
8112 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 return p.getSignalStrength();
8115 } finally {
8116 Binder.restoreCallingIdentity(identity);
8117 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008118 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008119
Pengquan Meng77b7f132018-08-22 14:49:57 -07008120 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008121 * Get the current modem radio state for the given slot.
8122 * @param slotIndex slot index.
8123 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008124 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008125 * @return the current radio power state from the modem
8126 */
8127 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008128 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008129 Phone phone = PhoneFactory.getPhone(slotIndex);
8130 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8132 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008133 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8134 }
8135
8136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 return phone.getRadioPowerState();
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
8142 }
8143 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8144 }
8145
8146 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008147 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8148 *
8149 * <p>Requires one of the following permissions:
8150 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8151 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8152 * privileges.
8153 *
8154 * @param subId subscription id
8155 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8156 * {@code false}.
8157 */
8158 @Override
8159 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008160 try {
8161 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8162 null);
8163 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008164 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008165 mApp, subId, "isDataRoamingEnabled");
8166 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008167
Pengquan Menga1bb6272018-09-06 09:59:22 -07008168 boolean isEnabled = false;
8169 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008170 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008171 Phone phone = getPhone(subId);
8172 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008173 } finally {
8174 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008175 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008176 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008177 }
8178
8179
8180 /**
8181 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8182 *
8183 * <p> Requires permission:
8184 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8185 * privileges.
8186 *
8187 * @param subId subscription id
8188 * @param isEnabled {@code true} means enable, {@code false} means disable.
8189 */
8190 @Override
8191 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8193 mApp, subId, "setDataRoamingEnabled");
8194
Pengquan Menga1bb6272018-09-06 09:59:22 -07008195 final long identity = Binder.clearCallingIdentity();
8196 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008197 Phone phone = getPhone(subId);
8198 if (phone != null) {
8199 phone.setDataRoamingEnabled(isEnabled);
8200 }
8201 } finally {
8202 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008203 }
8204 }
8205
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008206 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008207 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008208 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008209 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008210 mApp, subId, "isManualNetworkSelectionAllowed");
8211
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008212 boolean isAllowed = true;
8213 final long identity = Binder.clearCallingIdentity();
8214 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008215 Phone phone = getPhone(subId);
8216 if (phone != null) {
8217 isAllowed = phone.isCspPlmnEnabled();
8218 }
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
8222 return isAllowed;
8223 }
8224
8225 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008226 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008227 // Verify that tha callingPackage belongs to the calling UID
8228 mApp.getSystemService(AppOpsManager.class)
8229 .checkPackage(Binder.getCallingUid(), callingPackage);
8230
Jordan Liu1e142fc2019-04-22 15:10:43 -07008231 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008232 try {
8233 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008234 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008235 } catch (SecurityException e) {
8236 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8237 // has carrier privileges on an active UICC
8238 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8239 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008240 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008241 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008242 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008243
8244 final long identity = Binder.clearCallingIdentity();
8245 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008246 UiccController uiccController = UiccController.getInstance();
8247 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008248 if (hasReadPermission) {
8249 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008250 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008251
8252 // Remove private info if the caller doesn't have access
8253 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8254 for (UiccCardInfo cardInfo : cardInfos) {
8255 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8256 // is available
8257 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8258 if (card == null || card.getUiccProfile() == null) {
8259 // assume no access if the card or profile is unavailable
8260 filteredInfos.add(cardInfo.getUnprivileged());
8261 continue;
8262 }
8263 UiccProfile profile = card.getUiccProfile();
8264 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8265 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8266 filteredInfos.add(cardInfo);
8267 } else {
8268 filteredInfos.add(cardInfo.getUnprivileged());
8269 }
8270 }
8271 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
8275 }
8276
8277 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008278 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008279 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 final long identity = Binder.clearCallingIdentity();
8282 try {
8283 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8284 if (slots == null) {
8285 Rlog.i(LOG_TAG, "slots is null.");
8286 return null;
8287 }
8288
8289 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8290 for (int i = 0; i < slots.length; i++) {
8291 UiccSlot slot = slots[i];
8292 if (slot == null) {
8293 continue;
8294 }
8295
Jordan Liu7be7e652019-05-06 18:55:02 +00008296 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 UiccCard card = slot.getUiccCard();
8298 if (card != null) {
8299 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008300 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008301 cardId = slot.getEid();
8302 if (TextUtils.isEmpty(cardId)) {
8303 cardId = slot.getIccId();
8304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 }
8306
Jordan Liu857451f2019-05-09 16:35:35 -07008307 if (cardId != null) {
8308 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8309 // if cardId is an EID, it's all digits so this is fine
8310 cardId = IccUtils.stripTrailingFs(cardId);
8311 }
8312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 int cardState = 0;
8314 switch (slot.getCardState()) {
8315 case CARDSTATE_ABSENT:
8316 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8317 break;
8318 case CARDSTATE_PRESENT:
8319 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8320 break;
8321 case CARDSTATE_ERROR:
8322 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8323 break;
8324 case CARDSTATE_RESTRICTED:
8325 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8326 break;
8327 default:
8328 break;
8329
8330 }
8331
8332 infos[i] = new UiccSlotInfo(
8333 slot.isActive(),
8334 slot.isEuicc(),
8335 cardId,
8336 cardState,
8337 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008338 slot.isExtendedApduSupported(),
8339 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 }
8341 return infos;
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008344 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008345 }
8346
8347 @Override
8348 public boolean switchSlots(int[] physicalSlots) {
8349 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8354 } finally {
8355 Binder.restoreCallingIdentity(identity);
8356 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008357 }
Jack Yu4c988042018-02-27 15:30:01 -08008358
8359 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008360 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 return UiccController.getInstance().getCardIdForDefaultEuicc();
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 }
8368
Pengquan Meng85728fb2018-03-12 16:31:21 -07008369 /**
goneil47ffb6e2018-04-06 15:40:58 -07008370 * A test API to reload the UICC profile.
8371 *
8372 * <p>Requires that the calling app has permission
8373 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8374 * @hide
8375 */
8376 @Override
8377 public void refreshUiccProfile(int subId) {
8378 enforceModifyPermission();
8379
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
8382 Phone phone = getPhone(subId);
8383 if (phone == null) {
8384 return;
8385 }
8386 UiccCard uiccCard = phone.getUiccCard();
8387 if (uiccCard == null) {
8388 return;
8389 }
8390 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8391 if (uiccProfile == null) {
8392 return;
8393 }
8394 uiccProfile.refresh();
8395 } finally {
8396 Binder.restoreCallingIdentity(identity);
8397 }
8398 }
8399
8400 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008401 * Returns false if the mobile data is disabled by default, otherwise return true.
8402 */
8403 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008404 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008405 }
8406
8407 /**
8408 * Returns true if the data roaming is enabled by default, i.e the system property
8409 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8410 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8411 */
8412 private boolean getDefaultDataRoamingEnabled(int subId) {
8413 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008414 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008415 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008416 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8417 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8418 return isDataRoamingEnabled;
8419 }
8420
8421 /**
8422 * Returns the default network type for the given {@code subId}, if the default network type is
8423 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8424 */
8425 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008426 List<Integer> list = TelephonyProperties.default_network();
8427 int phoneId = mSubscriptionController.getPhoneId(subId);
8428 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8429 return list.get(phoneId);
8430 }
8431 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008432 }
fionaxua13278b2018-03-21 00:08:13 -07008433
8434 @Override
8435 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008436 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438
8439 final long identity = Binder.clearCallingIdentity();
8440 try {
8441 final Phone phone = getPhone(subId);
8442 if (phone == null) {
8443 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8444 return;
8445 }
chen xueaba88a2019-03-15 13:15:10 -07008446 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8447 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008448 if (carrierPrivilegeRules == null) {
8449 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8450 } else {
8451 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 } finally {
8454 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008455 }
fionaxua13278b2018-03-21 00:08:13 -07008456 }
8457
8458 @Override
8459 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008460 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 final Phone phone = getPhone(subId);
8465 if (phone == null) {
8466 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8467 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8468 }
8469 return phone.getCarrierIdListVersion();
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008472 }
fionaxua13278b2018-03-21 00:08:13 -07008473 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008474
8475 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008476 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8477 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008479 mApp, subId, callingPackage, callingFeatureId,
8480 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008481 return -1;
8482 }
8483
8484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
8490 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008491
8492 @Override
8493 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008494 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008495 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008496 mApp, subId, "getCdmaRoamingMode");
8497
8498 final long identity = Binder.clearCallingIdentity();
8499 try {
8500 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
8503 }
8504 }
8505
8506 @Override
8507 public boolean setCdmaRoamingMode(int subId, int mode) {
8508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8509 mApp, subId, "setCdmaRoamingMode");
8510
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
8518
8519 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008520 public int getCdmaSubscriptionMode(int subId) {
8521 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008522 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008523 mApp, subId, "getCdmaSubscriptionMode");
8524
8525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
8530 }
8531 }
8532
8533 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008534 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8536 mApp, subId, "setCdmaSubscriptionMode");
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
8543 }
8544 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008545
sqianc5eccab2018-10-19 18:46:41 -07008546 @Override
sqian8c685422019-02-22 15:55:18 -08008547 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008548 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008550 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8551 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008552 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8553 }
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
sqian854d44b2018-12-12 16:48:18 -08008556 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8557 for (Phone phone: PhoneFactory.getPhones()) {
8558 if (phone.getEmergencyNumberTracker() != null
8559 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8560 emergencyNumberListInternal.put(
8561 phone.getSubId(),
8562 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8563 }
sqian11b7a0e2018-12-05 18:48:28 -08008564 }
sqian854d44b2018-12-12 16:48:18 -08008565 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008566 } finally {
8567 Binder.restoreCallingIdentity(identity);
8568 }
sqianc5eccab2018-10-19 18:46:41 -07008569 }
8570
8571 @Override
sqian8c685422019-02-22 15:55:18 -08008572 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008573 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008574 if (!exactMatch) {
8575 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008576 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008577 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008578 }
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
sqian854d44b2018-12-12 16:48:18 -08008581 for (Phone phone: PhoneFactory.getPhones()) {
8582 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008583 && phone.getEmergencyNumberTracker()
8584 .isEmergencyNumber(number, exactMatch)) {
8585 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008586 }
sqian11b7a0e2018-12-05 18:48:28 -08008587 }
8588 return false;
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593
sqianf4ca7ed2019-01-15 18:32:07 -08008594 /**
8595 * Update emergency number list for test mode.
8596 */
8597 @Override
8598 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8599 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8600 "updateEmergencyNumberListTestMode");
8601
8602 final long identity = Binder.clearCallingIdentity();
8603 try {
8604 for (Phone phone: PhoneFactory.getPhones()) {
8605 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8606 if (tracker != null) {
8607 tracker.executeEmergencyNumberTestModeCommand(action, num);
8608 }
8609 }
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
8612 }
8613 }
8614
8615 /**
8616 * Get the full emergency number list for test mode.
8617 */
8618 @Override
8619 public List<String> getEmergencyNumberListTestMode() {
8620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8621 "getEmergencyNumberListTestMode");
8622
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 Set<String> emergencyNumbers = new HashSet<>();
8626 for (Phone phone: PhoneFactory.getPhones()) {
8627 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8628 if (tracker != null) {
8629 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8630 emergencyNumbers.add(num.getNumber());
8631 }
8632 }
8633 }
8634 return new ArrayList<>(emergencyNumbers);
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
8638 }
8639
chen xud6b45bd2018-10-30 22:27:10 -07008640 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008641 public int getEmergencyNumberDbVersion(int subId) {
8642 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8643
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 final Phone phone = getPhone(subId);
8647 if (phone == null) {
8648 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8649 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8650 }
8651 return phone.getEmergencyNumberDbVersion();
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
8655 }
8656
8657 @Override
8658 public void notifyOtaEmergencyNumberDbInstalled() {
8659 enforceModifyPermission();
8660
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
8663 for (Phone phone: PhoneFactory.getPhones()) {
8664 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8665 if (tracker != null) {
8666 tracker.updateOtaEmergencyNumberDatabase();
8667 }
8668 }
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
8671 }
8672 }
8673
8674 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008675 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008676 enforceActiveEmergencySessionPermission();
8677
8678 final long identity = Binder.clearCallingIdentity();
8679 try {
8680 for (Phone phone: PhoneFactory.getPhones()) {
8681 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8682 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008683 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8684 }
8685 }
8686 } finally {
8687 Binder.restoreCallingIdentity(identity);
8688 }
8689 }
8690
8691 @Override
8692 public void resetOtaEmergencyNumberDbFilePath() {
8693 enforceActiveEmergencySessionPermission();
8694
8695 final long identity = Binder.clearCallingIdentity();
8696 try {
8697 for (Phone phone: PhoneFactory.getPhones()) {
8698 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8699 if (tracker != null) {
8700 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008701 }
8702 }
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
8708 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008709 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8710 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8711 Phone phone = getPhone(subId);
8712 if (phone == null) {
8713 return null;
8714 }
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
8717 UiccProfile profile = UiccController.getInstance()
8718 .getUiccProfileForPhone(phone.getPhoneId());
8719 if (profile != null) {
8720 return profile.getCertsFromCarrierPrivilegeAccessRules();
8721 }
8722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 return null;
8726 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008727
8728 /**
8729 * Enable or disable a modem stack.
8730 */
8731 @Override
8732 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8733 enforceModifyPermission();
8734
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
8737 Phone phone = PhoneFactory.getPhone(slotIndex);
8738 if (phone == null) {
8739 return false;
8740 } else {
8741 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8742 }
8743 } finally {
8744 Binder.restoreCallingIdentity(identity);
8745 }
8746 }
Michelecea4cf22018-12-21 15:00:11 -08008747
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008748 /**
8749 * Whether a modem stack is enabled or not.
8750 */
8751 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008752 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8753 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008754 Phone phone = PhoneFactory.getPhone(slotIndex);
8755 if (phone == null) return false;
8756
8757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008758 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8759 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008760 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8761 }
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008765 try {
8766 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8767 } catch (NoSuchElementException ex) {
8768 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8769 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008770 } finally {
8771 Binder.restoreCallingIdentity(identity);
8772 }
8773 }
8774
Michelecea4cf22018-12-21 15:00:11 -08008775 @Override
Michele0ea7d782019-03-19 14:58:42 -07008776 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008777 enforceModifyPermission();
8778
8779 final long identity = Binder.clearCallingIdentity();
8780 try {
8781 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008782 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008783 .commit();
8784 } finally {
8785 Binder.restoreCallingIdentity(identity);
8786 }
8787 }
8788
8789 @Override
Michele0ea7d782019-03-19 14:58:42 -07008790 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008791 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008793 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8794 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008795 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008796 }
Michelecea4cf22018-12-21 15:00:11 -08008797
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
Michele0ea7d782019-03-19 14:58:42 -07008800 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008805
Michele0ea7d782019-03-19 14:58:42 -07008806 @TelephonyManager.IsMultiSimSupportedResult
8807 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008808 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8809 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8810 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008811 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8812 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008813 }
8814 // Check if the hardware supports multisim functionality. If usage of multisim is not
8815 // supported by the modem, indicate that it is restricted.
8816 PhoneCapability staticCapability =
8817 mPhoneConfigurationManager.getStaticPhoneCapability();
8818 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008819 loge("isMultiSimSupportedInternal: no static configuration available");
8820 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008821 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008822 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008823 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8824 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008825 }
8826 // Check if support of multiple SIMs is restricted by carrier
8827 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008828 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008829 }
8830
Michele0ea7d782019-03-19 14:58:42 -07008831 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008832 }
8833
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008834 /**
8835 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008836 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8837 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8838 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008839 * @param numOfSims number of active sims we want to switch to
8840 */
8841 @Override
8842 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008843 if (numOfSims == 1) {
8844 enforceModifyPermission();
8845 } else {
8846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8847 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8848 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008849 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008850
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008851 try {
Michele30b57b22019-03-01 12:01:14 -08008852 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008853 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008854 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8855 return;
8856 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008857 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8858 } finally {
8859 Binder.restoreCallingIdentity(identity);
8860 }
8861 }
8862
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008863 @Override
8864 public boolean isApplicationOnUicc(int subId, int appType) {
8865 enforceReadPrivilegedPermission("isApplicationOnUicc");
8866 Phone phone = getPhone(subId);
8867 if (phone == null) {
8868 return false;
8869 }
8870 final long identity = Binder.clearCallingIdentity();
8871 try {
8872 UiccCard uiccCard = phone.getUiccCard();
8873 if (uiccCard == null) {
8874 return false;
8875 }
8876 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8877 if (uiccProfile == null) {
8878 return false;
8879 }
8880 if (TelephonyManager.APPTYPE_SIM <= appType
8881 && appType <= TelephonyManager.APPTYPE_ISIM) {
8882 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8883 }
8884 return false;
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
8888 }
8889
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008890 /**
chen xub4baa772019-04-03 10:23:41 -07008891 * Get whether making changes to modem configurations will trigger reboot.
8892 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008893 */
8894 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008895 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8896 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008898 mApp, subId, callingPackage, callingFeatureId,
8899 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008900 return false;
8901 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
8908 }
8909
Nathan Harold29f5f052019-02-15 13:41:57 -08008910 private void updateModemStateMetrics() {
8911 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8912 // TODO: check the state for each modem if the api is ready.
8913 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8914 }
8915
Pengquan Meng3889a572019-01-23 11:16:29 -08008916 @Override
8917 public int[] getSlotsMapping() {
8918 enforceReadPrivilegedPermission("getSlotsMapping");
8919
8920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8923 // All logical slots should have a mapping to a physical slot.
8924 int[] logicalSlotsMapping = new int[phoneCount];
8925 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8926 for (int i = 0; i < slotInfos.length; i++) {
8927 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8928 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8929 }
8930 }
8931 return logicalSlotsMapping;
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
8935 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008936
8937 /**
8938 * Get the IRadio HAL Version
8939 */
8940 @Override
8941 public int getRadioHalVersion() {
8942 Phone phone = getDefaultPhone();
8943 if (phone == null) return -1;
8944 HalVersion hv = phone.getHalVersion();
8945 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8946 return hv.major * 100 + hv.minor;
8947 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008948
8949 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008950 * Get the current calling package name.
8951 * @return the current calling package name
8952 */
8953 @Override
8954 public String getCurrentPackageName() {
8955 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8956 }
8957
8958 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008959 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8960 * corresponding network requests on a subId.
8961 *
8962 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008963 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008964 * 2) APN is un-metered for this subscription, or
8965 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008966 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008967 *
8968 * @return whether data is allowed for a apn type.
8969 *
8970 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008971 */
8972 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008973 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008974 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8975 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008976
8977 // Now that all security checks passes, perform the operation as ourselves.
8978 final long identity = Binder.clearCallingIdentity();
8979 try {
8980 Phone phone = getPhone(subId);
8981 if (phone == null) return false;
8982
Jack Yu41407ee2019-05-13 16:54:09 -07008983 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008984 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
8988 }
8989
8990 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008991 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008992 enforceReadPrivilegedPermission("isApnMetered");
8993
8994 // Now that all security checks passes, perform the operation as ourselves.
8995 final long identity = Binder.clearCallingIdentity();
8996 try {
8997 Phone phone = getPhone(subId);
8998 if (phone == null) return true; // By default return true.
8999
Jack Yu41407ee2019-05-13 16:54:09 -07009000 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009005
9006 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009007 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9008 int subscriptionId, IBooleanConsumer resultCallback) {
9009 enforceModifyPermission();
9010 long token = Binder.clearCallingIdentity();
9011 try {
9012 Phone phone = getPhone(subscriptionId);
9013 if (phone == null) {
9014 try {
9015 if (resultCallback != null) {
9016 resultCallback.accept(false);
9017 }
9018 } catch (RemoteException e) {
9019 // ignore
9020 }
9021 return;
9022 }
9023 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9024 Pair.create(specifiers, (x) -> {
9025 try {
9026 if (resultCallback != null) {
9027 resultCallback.accept(x);
9028 }
9029 } catch (RemoteException e) {
9030 // ignore
9031 }
9032 });
9033 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9034 } finally {
9035 Binder.restoreCallingIdentity(token);
9036 }
9037 }
9038
9039 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009040 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9041 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009042 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009043 mApp, subId, "getSystemSelectionChannels");
9044 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 List<RadioAccessSpecifier> specifiers =
9048 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9049 null, subId, workSource);
9050 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9051 return specifiers;
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
9056
9057 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009058 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009059 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009060 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9061 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9062 if (iccRecords == null) {
9063 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9064 return false;
9065 }
9066 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9067 }
9068
9069 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009070 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9071 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009072 if (callingPackage == null) {
9073 callingPackage = getCurrentPackageName();
9074 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009075 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9076 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009077 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9078 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009079 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9080 }
9081 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9082 Intent intent = new Intent();
9083 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9084 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9085 // Bring up choose default SMS subscription dialog right now
9086 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9087 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9088 mApp.startActivity(intent);
9089 }
chen xud5ca2d52019-05-28 15:20:57 -07009090
9091 @Override
9092 public String getMmsUAProfUrl(int subId) {
9093 //TODO investigate if this API should require proper permission check in R b/133791609
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009096 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9097 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9098 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9099 return carrierUAProfUrl;
9100 }
chen xud5ca2d52019-05-28 15:20:57 -07009101 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9102 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9103 } finally {
9104 Binder.restoreCallingIdentity(identity);
9105 }
9106 }
9107
9108 @Override
9109 public String getMmsUserAgent(int subId) {
9110 //TODO investigate if this API should require proper permission check in R b/133791609
9111 final long identity = Binder.clearCallingIdentity();
9112 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009113 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9114 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9115 if (!TextUtils.isEmpty(carrierUserAgent)) {
9116 return carrierUserAgent;
9117 }
chen xud5ca2d52019-05-28 15:20:57 -07009118 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9119 .getString(com.android.internal.R.string.config_mms_user_agent);
9120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
Jack Yub07d4972019-05-28 16:12:25 -07009124
9125 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009126 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9127 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
9131 Phone phone = getPhone(subscriptionId);
9132 if (phone == null) return false;
9133
9134 switch (policy) {
9135 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9136 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9137 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9138 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9139 default:
9140 throw new IllegalArgumentException(policy + " is not a valid policy");
9141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
9146
9147 @Override
9148 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9149 boolean enabled) {
9150 enforceModifyPermission();
9151
9152 final long identity = Binder.clearCallingIdentity();
9153 try {
9154 Phone phone = getPhone(subscriptionId);
9155 if (phone == null) return;
9156
9157 switch (policy) {
9158 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9159 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9160 break;
9161 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9162 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9163 break;
9164 default:
9165 throw new IllegalArgumentException(policy + " is not a valid policy");
9166 }
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
9170 }
9171
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009172 /**
Hall Liub48cf452020-09-25 11:13:49 -07009173 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009174 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9175 * otherwise.
9176 */
9177 @Override
9178 public void setCepEnabled(boolean isCepEnabled) {
9179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9184 for (Phone phone : PhoneFactory.getPhones()) {
9185 Phone defaultPhone = phone.getImsPhone();
9186 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9187 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9188 ImsPhoneCallTracker imsPhoneCallTracker =
9189 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9190 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9191 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9192 + imsPhone.getMsisdn());
9193 }
9194 }
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
allenwtsu46dcc572020-01-08 18:24:03 +08009199
9200 /**
9201 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9202 *
9203 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9204 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9205 * before being read.
9206 */
9207 @Override
9208 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9209 isCompressed) {
9210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9211 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9213 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9214 }
9215 if (!isImsAvailableOnDevice()) {
9216 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9217 "IMS not available on device.");
9218 }
9219
9220 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009221 try {
Hui Wang068ab862020-10-31 05:12:53 +00009222 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009225 }
9226 }
zoey chenf95ca592019-12-30 16:11:23 +08009227
9228 @Override
9229 public boolean isIccLockEnabled(int subId) {
9230 enforceReadPrivilegedPermission("isIccLockEnabled");
9231
9232 // Now that all security checks passes, perform the operation as ourselves.
9233 final long identity = Binder.clearCallingIdentity();
9234 try {
9235 Phone phone = getPhone(subId);
9236 if (phone != null && phone.getIccCard() != null) {
9237 return phone.getIccCard().getIccLockEnabled();
9238 } else {
9239 return false;
9240 }
9241 } finally {
9242 Binder.restoreCallingIdentity(identity);
9243 }
9244 }
9245
9246 /**
zoey chene02881a2019-12-30 16:11:23 +08009247 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009248 *
zoey chene02881a2019-12-30 16:11:23 +08009249 * @return an integer representing the status of IccLock enabled or disabled in the following
9250 * three cases:
9251 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9252 * successfully.
9253 * - Positive number and zero for remaining password attempts.
9254 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009255 *
9256 */
9257 @Override
9258 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9259 enforceModifyPermission();
9260
9261 Phone phone = getPhone(subId);
9262 if (phone == null) {
9263 return 0;
9264 }
9265 // Now that all security checks passes, perform the operation as ourselves.
9266 final long identity = Binder.clearCallingIdentity();
9267 try {
9268 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9269 new Pair<Boolean, String>(enabled, password), phone, null);
9270 return attemptsRemaining;
9271
9272 } catch (Exception e) {
9273 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 return 0;
9278 }
9279
9280 /**
9281 * Change the ICC password used in ICC pin lock.
9282 *
zoey chene02881a2019-12-30 16:11:23 +08009283 * @return an integer representing the status of IccLock changed in the following three cases:
9284 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9285 * - Positive number and zero for remaining password attempts.
9286 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009287 *
9288 */
9289 @Override
9290 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9291 enforceModifyPermission();
9292
9293 Phone phone = getPhone(subId);
9294 if (phone == null) {
9295 return 0;
9296 }
9297 // Now that all security checks passes, perform the operation as ourselves.
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9301 new Pair<String, String>(oldPassword, newPassword), phone, null);
9302 return attemptsRemaining;
9303
9304 } catch (Exception e) {
9305 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 return 0;
9310 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009311
Peter Wangdafb9ac2020-01-15 14:13:38 -08009312 /**
9313 * Request for receiving user activity notification
9314 */
9315 @Override
9316 public void requestUserActivityNotification() {
9317 if (!mNotifyUserActivity.get()
9318 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9319 mNotifyUserActivity.set(true);
9320 }
9321 }
9322
9323 /**
9324 * Called when userActivity is signalled in the power manager.
9325 * This is safe to call from any thread, with any window manager locks held or not.
9326 */
9327 @Override
9328 public void userActivity() {
9329 // ***************************************
9330 // * Inherited from PhoneWindowManager *
9331 // ***************************************
9332 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9333 // WITH ITS LOCKS HELD.
9334 //
9335 // This code must be VERY careful about the locks
9336 // it acquires.
9337 // In fact, the current code acquires way too many,
9338 // and probably has lurking deadlocks.
9339
9340 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9341 throw new SecurityException("Only the OS may call notifyUserActivity()");
9342 }
9343
9344 if (mNotifyUserActivity.getAndSet(false)) {
9345 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9346 USER_ACTIVITY_NOTIFICATION_DELAY);
9347 }
9348 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009349
Malcolm Chen884180b2020-04-13 11:59:40 -07009350 @Override
9351 public boolean canConnectTo5GInDsdsMode() {
9352 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9353 }
Jack Yud10cdd42020-09-28 20:28:01 -07009354
9355 @Override
9356 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9357 String callingFeatureId) {
9358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9359 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9360 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9361 }
9362
9363 Phone phone = getPhone(subId);
9364 if (phone == null) {
9365 throw new RuntimeException("phone is not available");
9366 }
9367 // Now that all security checks passes, perform the operation as ourselves.
9368 final long identity = Binder.clearCallingIdentity();
9369 try {
9370 return phone.getEquivalentHomePlmns();
9371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009375
Hui Wang0866fcc2020-10-12 12:14:23 -07009376 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009377 public boolean isRadioInterfaceCapabilitySupported(
9378 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009379 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009380 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009381 if (radioInterfaceCapabilities == null) {
9382 throw new RuntimeException("radio interface capabilities are not available");
9383 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009384 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009385 }
9386 }
9387
9388 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009389 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9390 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009391 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9392 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9393 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9394 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9395 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009396 if (DBG) {
9397 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9398 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9399 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9400 }
9401
9402 if (!SubscriptionManager.isValidSubscriptionId(subId)
9403 || appType < TelephonyManager.APPTYPE_UNKNOWN
9404 || appType > TelephonyManager.APPTYPE_ISIM
9405 || nafUrl == null || securityProtocol == null || callback == null) {
9406 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9407 if (callback != null) {
9408 try {
9409 callback.onAuthenticationFailure(
9410 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9411 } catch (RemoteException exception) {
9412 log("Fail to notify onAuthenticationFailure due to " + exception);
9413 }
9414 return;
9415 }
9416 }
9417
9418 final long token = Binder.clearCallingIdentity();
9419 try {
9420 getGbaManager(subId).bootstrapAuthenticationRequest(
9421 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9422 forceBootStrapping, callback));
9423 } finally {
9424 Binder.restoreCallingIdentity(token);
9425 }
9426 }
9427
Jack Nudelman24d51a52020-11-24 12:08:04 -08009428 /**
9429 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9430 * requested radio power state will actually be set. See {@link
9431 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9432 *
9433 * @param subId the subscription ID of the phone requesting to set the radio power state.
9434 * @param enable {@code true} if trying to turn radio on.
9435 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9436 * false}.
9437 */
9438 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9439 Phone phone = getPhone(subId);
9440 if (phone != null) {
9441 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9442 return true;
9443 }
9444 return false;
9445 }
9446
9447 private int handleDataThrottlingRequest(int subId,
9448 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009449 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9450 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9451 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9452 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9453 throw new IllegalArgumentException("modem does not support data throttling");
9454 }
9455
Jack Nudelman24d51a52020-11-24 12:08:04 -08009456 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9457 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9458 if (!setRadioPowerForThermal(subId, true)) {
9459 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9460 }
9461
9462 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9463
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009464 if (isDataThrottlingSupported) {
9465 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009466 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009467 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9468 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9469 } else if (thermalMitigationResult
9470 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9471 throw new IllegalArgumentException("modem does not support data throttling");
9472 }
9473 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009474 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009475
9476 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009477 }
9478
Jack Nudelman644b91a2021-03-12 14:09:48 -08009479 private static List<String> getThermalMitigationAllowlist(Context context) {
9480 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9481 for (String pckg : context.getResources()
9482 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9483 sThermalMitigationAllowlistedPackages.add(pckg);
9484 }
9485 }
9486
9487 return sThermalMitigationAllowlistedPackages;
9488 }
9489
9490 /**
9491 * Used by shell commands to add an authorized package name for thermal mitigation.
9492 * @param packageName name of package to be allowlisted
9493 * @param context
9494 */
9495 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9496 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9497 sThermalMitigationAllowlistedPackages.add(packageName);
9498 }
9499
9500 /**
9501 * Used by shell commands to remove an authorized package name for thermal mitigation.
9502 * @param packageName name of package to remove from allowlist
9503 * @param context
9504 */
9505 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9506 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9507 sThermalMitigationAllowlistedPackages.remove(packageName);
9508 }
9509
Jack Nudelman24d51a52020-11-24 12:08:04 -08009510 /**
9511 * Thermal mitigation request to control functionalities at modem.
9512 *
9513 * @param subId the id of the subscription.
9514 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009515 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009516 *
9517 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9518 */
9519 @Override
9520 @ThermalMitigationResult
9521 public int sendThermalMitigationRequest(
9522 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009523 ThermalMitigationRequest thermalMitigationRequest,
9524 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009525 enforceModifyPermission();
9526
Jack Nudelman644b91a2021-03-12 14:09:48 -08009527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9528 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9529 .contains(callingPackage)) {
9530 throw new SecurityException("Calling package must be configured in the device config. "
9531 + "calling package: " + callingPackage);
9532 }
9533
Jack Nudelman24d51a52020-11-24 12:08:04 -08009534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9535 final long identity = Binder.clearCallingIdentity();
9536
9537 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9538 try {
9539 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9540 switch (thermalMitigationAction) {
9541 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9542 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009543 handleDataThrottlingRequest(subId,
9544 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009545 break;
9546 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9547 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9548 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9549 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9550 }
9551
9552 // Ensure that radio is on. If not able to power on due to phone being
9553 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9554 if (!setRadioPowerForThermal(subId, true)) {
9555 thermalMitigationResult =
9556 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9557 break;
9558 }
9559
9560 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9561 false);
9562 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9563 break;
9564 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9565 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9566 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9567 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9568 }
9569
9570 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9571 if (registry != null) {
9572 TelephonyConnectionService service =
9573 registry.getTelephonyConnectionService();
9574 Phone phone = getPhone(subId);
9575 if (phone == null) {
9576 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009577 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009578 break;
9579 }
9580
9581 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009582 != TelephonyManager.CALL_STATE_IDLE
9583 || phone.isInEmergencySmsMode() || phone.isInEcm()
9584 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009585 String errorMessage = "Phone state is not valid. call state = "
9586 + PhoneConstantConversions.convertCallState(phone.getState())
9587 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9588 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9589 errorMessage += service == null
9590 ? " TelephonyConnectionService is null"
9591 : " isEmergencyCallPending = "
9592 + service.isEmergencyCallPending();
9593 Log.e(LOG_TAG, errorMessage);
9594 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009595 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009596 break;
9597 }
9598 } else {
9599 thermalMitigationResult =
9600 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9601 break;
9602 }
9603
9604 // Turn radio off. If not able to power off due to phone being unavailable,
9605 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9606 if (!setRadioPowerForThermal(subId, false)) {
9607 thermalMitigationResult =
9608 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9609 break;
9610 }
9611 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009612 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009613 break;
9614 default:
9615 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9616 + "not exist. Requested action: " + thermalMitigationAction);
9617 }
9618 } catch (IllegalArgumentException e) {
9619 throw e;
9620 } catch (Exception e) {
9621 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9622 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626
9627 if (DBG) {
9628 log("thermalMitigationRequest returning with thermalMitigationResult: "
9629 + thermalMitigationResult);
9630 }
9631
9632 return thermalMitigationResult;
9633 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009634
9635 /**
9636 * Set the GbaService Package Name that Telephony will bind to.
9637 *
9638 * @param subId The sim that the GbaService is associated with.
9639 * @param packageName The name of the package to be replaced with.
9640 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9641 */
9642 @Override
9643 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9644 enforceModifyPermission();
9645
9646 final long identity = Binder.clearCallingIdentity();
9647 try {
9648 return getGbaManager(subId).overrideServicePackage(packageName);
9649 } finally {
9650 Binder.restoreCallingIdentity(identity);
9651 }
9652 }
9653
9654 /**
9655 * Return the package name of the currently bound GbaService.
9656 *
9657 * @param subId The sim that the GbaService is associated with.
9658 * @return the package name of the GbaService configuration, null if GBA is not supported.
9659 */
9660 @Override
9661 public String getBoundGbaService(int subId) {
9662 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9663
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 return getGbaManager(subId).getServicePackage();
9667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
9671
9672 /**
9673 * Set the release time for telephony to unbind GbaService.
9674 *
9675 * @param subId The sim that the GbaService is associated with.
9676 * @param interval The release time to unbind GbaService by millisecond.
9677 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9678 */
9679 @Override
9680 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9681 enforceModifyPermission();
9682
9683 final long identity = Binder.clearCallingIdentity();
9684 try {
9685 return getGbaManager(subId).overrideReleaseTime(interval);
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 }
9690
9691 /**
9692 * Return the release time for telephony to unbind GbaService.
9693 *
9694 * @param subId The sim that the GbaService is associated with.
9695 * @return The release time to unbind GbaService by millisecond.
9696 */
9697 @Override
9698 public int getGbaReleaseTime(int subId) {
9699 enforceReadPrivilegedPermission("getGbaReleaseTime");
9700
9701 final long identity = Binder.clearCallingIdentity();
9702 try {
9703 return getGbaManager(subId).getReleaseTime();
9704 } finally {
9705 Binder.restoreCallingIdentity(identity);
9706 }
9707 }
9708
9709 private GbaManager getGbaManager(int subId) {
9710 GbaManager instance = GbaManager.getInstance(subId);
9711 if (instance == null) {
9712 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9713 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9714 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9715 }
9716 return instance;
9717 }
Hui Wang068ab862020-10-31 05:12:53 +00009718
9719 /**
9720 * indicate whether the device and the carrier can support
9721 * RCS VoLTE single registration.
9722 */
9723 @Override
9724 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009725 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9726 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9727 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9728 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009729
9730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9731 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9732 }
9733
9734 final long identity = Binder.clearCallingIdentity();
9735 try {
9736 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9737 if (rpm != null) {
9738 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9739 }
9740 return false;
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
9746 /**
9747 * Register RCS provisioning callback.
9748 */
9749 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009750 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009751 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009752 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009753 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009754 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9755 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009756
9757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9758 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9759 }
9760 if (!isImsAvailableOnDevice()) {
9761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9762 "IMS not available on device.");
9763 }
9764
9765 final long identity = Binder.clearCallingIdentity();
9766 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009767 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009768 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009769 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9770 "Service not available for the subscription.");
9771 }
Hui Wang068ab862020-10-31 05:12:53 +00009772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
9776
9777 /**
9778 * Unregister RCS provisioning callback.
9779 */
9780 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009781 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009782 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009783 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009784 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009785 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9786 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009787
9788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9790 }
9791 if (!isImsAvailableOnDevice()) {
9792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9793 "IMS not available on device.");
9794 }
9795
9796 final long identity = Binder.clearCallingIdentity();
9797 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009798 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009799 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009800 } finally {
9801 Binder.restoreCallingIdentity(identity);
9802 }
9803 }
9804
9805 /**
9806 * trigger RCS reconfiguration.
9807 */
9808 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009809 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9810 "triggerRcsReconfiguration",
9811 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009812
9813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9814 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9815 }
9816 if (!isImsAvailableOnDevice()) {
9817 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9818 "IMS not available on device.");
9819 }
9820
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9824 } finally {
9825 Binder.restoreCallingIdentity(identity);
9826 }
9827 }
9828
9829 /**
9830 * Provide the client configuration parameters of the RCS application.
9831 */
9832 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009833 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9834 "setRcsClientConfiguration",
9835 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009836
9837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9838 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9839 }
9840 if (!isImsAvailableOnDevice()) {
9841 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9842 "IMS not available on device.");
9843 }
9844
9845 final long identity = Binder.clearCallingIdentity();
9846
9847 try {
9848 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9849 if (configBinder == null) {
9850 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9851 } else {
9852 configBinder.setRcsClientConfiguration(rcc);
9853 }
9854 } catch (RemoteException e) {
9855 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
9860
9861 /**
Hui Wang19a21872021-02-19 20:45:36 -08009862 * Enables or disables the test mode for RCS VoLTE single registration.
9863 */
9864 @Override
9865 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9867 "setRcsSingleRegistrationTestModeEnabled");
9868
9869 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9870 }
9871
9872 /**
9873 * Gets the test mode for RCS VoLTE single registration.
9874 */
9875 @Override
9876 public boolean getRcsSingleRegistrationTestModeEnabled() {
9877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9878 "getRcsSingleRegistrationTestModeEnabled");
9879
9880 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9881 }
9882
9883 /**
Hui Wang068ab862020-10-31 05:12:53 +00009884 * Overrides the config of RCS VoLTE single registration enabled for the device.
9885 */
9886 @Override
9887 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9889 "setDeviceSingleRegistrationEnabledOverride");
9890 enforceModifyPermission();
9891
9892 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9893 : Boolean.parseBoolean(enabledStr);
9894 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009895 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009896 }
9897
9898 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009899 * Sends a device to device communication message. Only usable via shell.
9900 * @param message message to send.
9901 * @param value message value.
9902 */
9903 @Override
9904 public void sendDeviceToDeviceMessage(int message, int value) {
9905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9906 "setCarrierSingleRegistrationEnabledOverride");
9907 enforceModifyPermission();
9908
9909 final long identity = Binder.clearCallingIdentity();
9910 try {
9911 TelephonyConnectionService service =
9912 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9913 if (service == null) {
9914 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9915 return;
9916 }
9917 service.sendTestDeviceToDeviceMessage(message, value);
9918 } finally {
9919 Binder.restoreCallingIdentity(identity);
9920 }
9921 }
9922
9923
9924 /**
Hui Wang068ab862020-10-31 05:12:53 +00009925 * Gets the config of RCS VoLTE single registration enabled for the device.
9926 */
9927 @Override
9928 public boolean getDeviceSingleRegistrationEnabled() {
9929 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9930 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9931 }
9932
9933 /**
9934 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9935 */
9936 @Override
9937 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9939 "setCarrierSingleRegistrationEnabledOverride");
9940 enforceModifyPermission();
9941
9942 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9943 : Boolean.parseBoolean(enabledStr);
9944 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9945 subId, enabled);
9946 }
9947
9948 /**
9949 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9950 */
9951 @Override
9952 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9953 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9954 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9955 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009956
9957 /**
Hui Wangeadb2562021-02-26 09:33:38 -08009958 * Overrides the ims feature validation result
9959 */
9960 @Override
9961 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
9962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9963 "setImsFeatureValidationOverride");
9964
9965 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9966 : Boolean.parseBoolean(enabledStr);
9967 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
9968 subId, enabled);
9969 }
9970
9971 /**
9972 * Gets the ims feature validation override value
9973 */
9974 @Override
9975 public boolean getImsFeatureValidationOverride(int subId) {
9976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9977 "getImsFeatureValidationOverride");
9978 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
9979 }
9980
9981 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +08009982 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9983 * their mobile plan.
9984 */
9985 @Override
9986 public String getMobileProvisioningUrl() {
9987 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9988 final long identity = Binder.clearCallingIdentity();
9989 try {
9990 return getDefaultPhone().getMobileProvisioningUrl();
9991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009995
James.cf Linbcdf8b32021-01-14 16:44:13 +08009996 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009997 * Get the EAB contact from the EAB database.
9998 */
9999 @Override
10000 public String getContactFromEab(String contact) {
10001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10002 enforceModifyPermission();
10003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10006 } finally {
10007 Binder.restoreCallingIdentity(identity);
10008 }
10009 }
10010
10011 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010012 * Remove the EAB contacts from the EAB database.
10013 */
10014 @Override
10015 public int removeContactFromEab(int subId, String contacts) {
10016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10017 enforceModifyPermission();
10018 final long identity = Binder.clearCallingIdentity();
10019 try {
10020 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
10025
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010026 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010027 public boolean getDeviceUceEnabled() {
10028 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10029 final long identity = Binder.clearCallingIdentity();
10030 try {
10031 return mApp.getDeviceUceEnabled();
10032 } finally {
10033 Binder.restoreCallingIdentity(identity);
10034 }
10035 }
10036
10037 @Override
10038 public void setDeviceUceEnabled(boolean isEnabled) {
10039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10040 final long identity = Binder.clearCallingIdentity();
10041 try {
10042 mApp.setDeviceUceEnabled(isEnabled);
10043 } finally {
10044 Binder.restoreCallingIdentity(identity);
10045 }
10046 }
10047
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010048 /**
10049 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10050 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10051 */
10052 // Used for SHELL command only right now.
10053 @Override
10054 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10055 List<String> featureTags) {
10056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10057 "addUceRegistrationOverrideShell");
10058 final long identity = Binder.clearCallingIdentity();
10059 try {
10060 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10061 new ArraySet<>(featureTags));
10062 } catch (ImsException e) {
10063 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10064 } finally {
10065 Binder.restoreCallingIdentity(identity);
10066 }
10067 }
10068
10069 /**
10070 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10071 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10072 */
10073 // Used for SHELL command only right now.
10074 @Override
10075 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10076 List<String> featureTags) {
10077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10078 "removeUceRegistrationOverrideShell");
10079 final long identity = Binder.clearCallingIdentity();
10080 try {
10081 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10082 new ArraySet<>(featureTags));
10083 } catch (ImsException e) {
10084 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10085 } finally {
10086 Binder.restoreCallingIdentity(identity);
10087 }
10088 }
10089
10090 /**
10091 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10092 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10093 */
10094 // Used for SHELL command only right now.
10095 @Override
10096 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10098 "clearUceRegistrationOverrideShell");
10099 final long identity = Binder.clearCallingIdentity();
10100 try {
10101 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10102 } catch (ImsException e) {
10103 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10104 } finally {
10105 Binder.restoreCallingIdentity(identity);
10106 }
10107 }
10108
10109 /**
10110 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10111 */
10112 // Used for SHELL command only right now.
10113 @Override
10114 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10116 "getLatestRcsContactUceCapabilityShell");
10117 final long identity = Binder.clearCallingIdentity();
10118 try {
10119 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10120 } catch (ImsException e) {
10121 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10122 } finally {
10123 Binder.restoreCallingIdentity(identity);
10124 }
10125 }
10126
10127 /**
10128 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10129 * device does not have an active PUBLISH.
10130 */
10131 // Used for SHELL command only right now.
10132 @Override
10133 public String getLastUcePidfXmlShell(int subId) {
10134 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10135 final long identity = Binder.clearCallingIdentity();
10136 try {
10137 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10138 } catch (ImsException e) {
10139 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10140 } finally {
10141 Binder.restoreCallingIdentity(identity);
10142 }
10143 }
10144
James.cf Line8713a42021-04-29 16:04:26 +080010145 /**
10146 * Remove UCE requests cannot be sent to the network status.
10147 */
10148 // Used for SHELL command only right now.
10149 @Override
10150 public boolean removeUceRequestDisallowedStatus(int subId) {
10151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10155 } catch (ImsException e) {
10156 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10157 } finally {
10158 Binder.restoreCallingIdentity(identity);
10159 }
10160 }
10161
James.cf Lin18bb9002021-05-25 01:37:38 +080010162 /**
10163 * Remove UCE requests cannot be sent to the network status.
10164 */
10165 // Used for SHELL command only.
10166 @Override
10167 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10169 final long identity = Binder.clearCallingIdentity();
10170 try {
10171 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10172 } catch (ImsException e) {
10173 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10174 } finally {
10175 Binder.restoreCallingIdentity(identity);
10176 }
10177 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010178
James.cf Lin4b784aa2021-01-31 03:25:15 +080010179 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010180 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10181 String callingPackage) {
10182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10183 mApp, subId, "setSignalStrengthUpdateRequest");
10184
10185 final int callingUid = Binder.getCallingUid();
10186 // Verify that tha callingPackage belongs to the calling UID
10187 mApp.getSystemService(AppOpsManager.class)
10188 .checkPackage(callingUid, callingPackage);
10189
10190 validateSignalStrengthUpdateRequest(request, callingUid);
10191
10192 final long identity = Binder.clearCallingIdentity();
10193 try {
10194 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10195 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10196
10197 if (result instanceof IllegalStateException) {
10198 throw (IllegalStateException) result;
10199 }
10200 } finally {
10201 Binder.restoreCallingIdentity(identity);
10202 }
10203 }
10204
10205 @Override
10206 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10207 String callingPackage) {
10208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10209 mApp, subId, "clearSignalStrengthUpdateRequest");
10210
10211 final int callingUid = Binder.getCallingUid();
10212 // Verify that tha callingPackage belongs to the calling UID
10213 mApp.getSystemService(AppOpsManager.class)
10214 .checkPackage(callingUid, callingPackage);
10215
10216 final long identity = Binder.clearCallingIdentity();
10217 try {
10218 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10219 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10220
10221 if (result instanceof IllegalStateException) {
10222 throw (IllegalStateException) result;
10223 }
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10230 int callingUid) {
10231 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10232 // phone/system process do not have further restriction on request
10233 return;
10234 }
10235
10236 // Applications has restrictions on how to use the request:
10237 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10238 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10239 // This is not system caller which has been checked above
10240 throw new IllegalArgumentException(
10241 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10242 }
10243
10244 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10245 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10246 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10247 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10248 || info.isEnabled()) {
10249 throw new IllegalArgumentException(
10250 "Only system can set hide fields in SignalThresholdInfo");
10251 }
10252
10253 // Thresholds length for each RAN need in range. This has been validated in
10254 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10255 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10256 final int[] thresholds = info.getThresholds();
10257 Objects.requireNonNull(thresholds);
10258 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10259 || thresholds.length
10260 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10261 throw new IllegalArgumentException(
10262 "thresholds length is out of range: " + thresholds.length);
10263 }
10264 }
10265 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010266
10267 /**
10268 * Prepare TelephonyManager for an unattended reboot. The reboot is
10269 * required to be done shortly after the API is invoked.
10270 */
10271 @Override
10272 @TelephonyManager.PrepareUnattendedRebootResult
10273 public int prepareForUnattendedReboot() {
10274 enforceRebootPermission();
10275
10276 final long identity = Binder.clearCallingIdentity();
10277 try {
10278 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010283}