blob: c257fb81992308c9a9bfc79234f699791bff7e38 [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;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800162import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700163import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700164import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800166import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800167import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700169import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700171import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800172import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700173import com.android.internal.telephony.imsphone.ImsPhone;
174import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800175import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900176import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800178import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700181import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800186import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700187import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700188import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800192import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700193import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700194import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800195import com.android.services.telephony.TelecomAccountRegistry;
196import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800197import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800198
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700199import java.io.FileDescriptor;
200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800211import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800212import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
214/**
215 * Implementation of the ITelephony interface.
216 */
Santos Cordon117fee72014-05-16 17:56:12 -0700217public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 private static final String LOG_TAG = "PhoneInterfaceManager";
219 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
220 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 // Message codes used with mMainThreadHandler
224 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700225 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
226 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227 private static final int CMD_OPEN_CHANNEL = 9;
228 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
229 private static final int CMD_CLOSE_CHANNEL = 11;
230 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800231 private static final int CMD_NV_READ_ITEM = 13;
232 private static final int EVENT_NV_READ_ITEM_DONE = 14;
233 private static final int CMD_NV_WRITE_ITEM = 15;
234 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
235 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
236 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700237 private static final int CMD_RESET_MODEM_CONFIG = 19;
238 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800239 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
240 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800241 private static final int CMD_SEND_ENVELOPE = 25;
242 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000243 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
244 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700245 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
246 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
247 private static final int CMD_EXCHANGE_SIM_IO = 31;
248 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800249 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
250 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700251 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
252 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700253 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
254 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700255 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
256 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
257 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700259 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
260 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
261 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
262 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700263 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800264 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
265 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000266 private static final int CMD_SWITCH_SLOTS = 50;
267 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700268 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
269 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
270 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
271 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
272 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
273 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
274 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
275 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700276 private static final int CMD_GET_ALL_CELL_INFO = 60;
277 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
278 private static final int CMD_GET_CELL_LOCATION = 62;
279 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700280 private static final int CMD_MODEM_REBOOT = 64;
281 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700282 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
283 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800284 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
285 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700286 private static final int CMD_GET_MODEM_STATUS = 70;
287 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700288 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
289 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700290 private static final int CMD_ERASE_MODEM_CONFIG = 74;
291 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800292 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
293 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
294 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
295 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800296 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
297 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800298 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800299 private static final int CMD_GET_CALL_FORWARDING = 83;
300 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
301 private static final int CMD_SET_CALL_FORWARDING = 85;
302 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
303 private static final int CMD_GET_CALL_WAITING = 87;
304 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
305 private static final int CMD_SET_CALL_WAITING = 89;
306 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700307 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
308 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
309 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
310 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700311 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
312 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800313 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
314 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800315 private static final int CMD_SET_DATA_THROTTLING = 99;
316 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800317 private static final int CMD_SET_SIM_POWER = 101;
318 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800319 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
320 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
321 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
322 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800323 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
324 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000325 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800327 // Parameters of select command.
328 private static final int SELECT_COMMAND = 0xA4;
329 private static final int SELECT_P1 = 0x04;
330 private static final int SELECT_P2 = 0;
331 private static final int SELECT_P3 = 0x10;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 /** The singleton instance. */
334 private static PhoneInterfaceManager sInstance;
335
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800338 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700339 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private AppOpsManager mAppOps;
341 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800342 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700344 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800345 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 /** User Activity */
348 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800349 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
350
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700351 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
352
Derek Tan97ebb422014-09-05 16:55:38 -0700353 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
354 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800355 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800356 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700357
Michelecea4cf22018-12-21 15:00:11 -0800358 // String to store multi SIM allowed
359 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
360
Derek Tan740e1672017-06-27 14:56:27 -0700361 // The AID of ISD-R.
362 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
363
yinxub1bed742017-04-17 11:45:04 -0700364 private NetworkScanRequestTracker mNetworkScanRequestTracker;
365
David Kelly5e06a7f2018-03-12 14:10:59 +0000366 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
367 private static final int MANUFACTURER_CODE_LENGTH = 8;
368
Jack Nudelman24d51a52020-11-24 12:08:04 -0800369 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
370
Derek Tan89e89d42014-07-08 17:00:10 -0700371 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700372 * Experiment flag to enable erase modem config on reset network, default value is false
373 */
374 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
375 "reset_network_erase_modem_config_enabled";
376
Rambo Wang0f050d82021-02-12 11:43:36 -0800377 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
378
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700379 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700380 * A request object to use for transmitting data to an ICC.
381 */
382 private static final class IccAPDUArgument {
383 public int channel, cla, command, p1, p2, p3;
384 public String data;
385
386 public IccAPDUArgument(int channel, int cla, int command,
387 int p1, int p2, int p3, String data) {
388 this.channel = channel;
389 this.cla = cla;
390 this.command = command;
391 this.p1 = p1;
392 this.p2 = p2;
393 this.p3 = p3;
394 this.data = data;
395 }
396 }
397
398 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700399 * A request object to use for transmitting data to an ICC.
400 */
401 private static final class ManualNetworkSelectionArgument {
402 public OperatorInfo operatorInfo;
403 public boolean persistSelection;
404
405 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
406 this.operatorInfo = operatorInfo;
407 this.persistSelection = persistSelection;
408 }
409 }
410
411 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
413 * request after sending. The main thread will notify the request when it is complete.
414 */
415 private static final class MainThreadRequest {
416 /** The argument to use for the request */
417 public Object argument;
418 /** The result of the request that is run on the main thread */
419 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800420 // The subscriber id that this request applies to. Defaults to
421 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
422 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Nathan Harold92bed182018-10-12 18:16:49 -0700424 // In cases where subId is unavailable, the caller needs to specify the phone.
425 public Phone phone;
426
vagdeviaf9a5b92018-08-15 16:01:53 -0700427 public WorkSource workSource;
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 public MainThreadRequest(Object argument) {
430 this.argument = argument;
431 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800432
Nathan Harold92bed182018-10-12 18:16:49 -0700433 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
434 this.argument = argument;
435 if (phone != null) {
436 this.phone = phone;
437 }
438 this.workSource = workSource;
439 }
440
vagdeviaf9a5b92018-08-15 16:01:53 -0700441 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800442 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800443 if (subId != null) {
444 this.subId = subId;
445 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700446 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 }
449
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800450 private static final class IncomingThirdPartyCallArgs {
451 public final ComponentName component;
452 public final String callId;
453 public final String callerDisplayName;
454
455 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
456 String callerDisplayName) {
457 this.component = component;
458 this.callId = callId;
459 this.callerDisplayName = callerDisplayName;
460 }
461 }
462
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 /**
464 * A handler that processes messages on the main thread in the phone process. Since many
465 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
466 * inbound binder threads to the main thread in the phone process. The Binder thread
467 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
468 * on, which will be notified when the operation completes and will contain the result of the
469 * request.
470 *
471 * <p>If a MainThreadRequest object is provided in the msg.obj field,
472 * note that request.result must be set to something non-null for the calling thread to
473 * unblock.
474 */
475 private final class MainThreadHandler extends Handler {
476 @Override
477 public void handleMessage(Message msg) {
478 MainThreadRequest request;
479 Message onCompleted;
480 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800483 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484
485 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 case CMD_HANDLE_USSD_REQUEST: {
487 request = (MainThreadRequest) msg.obj;
488 final Phone phone = getPhoneFromRequest(request);
489 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
490 String ussdRequest = ussdObject.first;
491 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700492
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 if (!isUssdApiAllowed(request.subId)) {
494 // Carrier does not support use of this API, return failure.
495 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
496 UssdResponse response = new UssdResponse(ussdRequest, null);
497 Bundle returnData = new Bundle();
498 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
499 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700500
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 request.result = true;
502 notifyRequester(request);
503 return;
504 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700505
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 try {
507 request.result = phone != null
508 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
509 } catch (CallStateException cse) {
510 request.result = false;
511 }
512 // Wake up the requesting thread
513 notifyRequester(request);
514 break;
pkanwar32d516d2016-10-14 19:37:38 -0700515 }
516
Yorke Lee716f67e2015-06-17 15:39:16 -0700517 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 final Phone phone = getPhoneFromRequest(request);
520 request.result = phone != null ?
521 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
522 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("iccTransmitApduLogicalChannel: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
538 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 iccArgument.channel, iccArgument.cla, iccArgument.command,
541 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 break;
545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 ar = (AsyncResult) msg.obj;
548 request = (MainThreadRequest) ar.userObj;
549 if (ar.exception == null && ar.result != null) {
550 request.result = ar.result;
551 } else {
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 if (ar.result == null) {
554 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800555 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800557 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 } else {
559 loge("iccTransmitApduLogicalChannel: Unknown exception");
560 }
561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
566 request = (MainThreadRequest) msg.obj;
567 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 if (uiccCard == null) {
570 loge("iccTransmitApduBasicChannel: No UICC");
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 } else {
574 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
575 request);
576 uiccCard.iccTransmitApduBasicChannel(
577 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
578 iccArgument.p3, iccArgument.data, onCompleted);
579 }
580 break;
581
582 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
583 ar = (AsyncResult) msg.obj;
584 request = (MainThreadRequest) ar.userObj;
585 if (ar.exception == null && ar.result != null) {
586 request.result = ar.result;
587 } else {
588 request.result = new IccIoResult(0x6F, 0, (byte[])null);
589 if (ar.result == null) {
590 loge("iccTransmitApduBasicChannel: Empty response");
591 } else if (ar.exception instanceof CommandException) {
592 loge("iccTransmitApduBasicChannel: CommandException: " +
593 ar.exception);
594 } else {
595 loge("iccTransmitApduBasicChannel: Unknown exception");
596 }
597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 break;
600
601 case CMD_EXCHANGE_SIM_IO:
602 request = (MainThreadRequest) msg.obj;
603 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800604 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 if (uiccCard == null) {
606 loge("iccExchangeSimIO: No UICC");
607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 } else {
610 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
611 request);
612 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
613 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
614 iccArgument.data, onCompleted);
615 }
616 break;
617
618 case EVENT_EXCHANGE_SIM_IO_DONE:
619 ar = (AsyncResult) msg.obj;
620 request = (MainThreadRequest) ar.userObj;
621 if (ar.exception == null && ar.result != null) {
622 request.result = ar.result;
623 } else {
624 request.result = new IccIoResult(0x6f, 0, (byte[])null);
625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 break;
628
Derek Tan4d5e5c12014-02-04 11:54:58 -0800629 case CMD_SEND_ENVELOPE:
630 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 if (uiccCard == null) {
633 loge("sendEnvelopeWithStatus: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
638 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
639 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 break;
641
642 case EVENT_SEND_ENVELOPE_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700648 request.result = new IccIoResult(0x6F, 0, (byte[])null);
649 if (ar.result == null) {
650 loge("sendEnvelopeWithStatus: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("sendEnvelopeWithStatus: CommandException: " +
653 ar.exception);
654 } else {
655 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
656 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 break;
660
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 case CMD_OPEN_CHANNEL:
662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800663 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800664 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 if (uiccCard == null) {
666 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800667 request.result = new IccOpenLogicalChannelResponse(-1,
668 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800672 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
673 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case EVENT_OPEN_CHANNEL_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 int[] result = (int[]) ar.result;
683 int channelId = result[0];
684 byte[] selectResponse = null;
685 if (result.length > 1) {
686 selectResponse = new byte[result.length - 1];
687 for (int i = 1; i < result.length; ++i) {
688 selectResponse[i - 1] = (byte) result[i];
689 }
690 }
691 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 if (ar.result == null) {
695 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.exception != null) {
698 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
699 }
700
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700701 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700702 if (ar.exception instanceof CommandException) {
703 CommandException.Error error =
704 ((CommandException) (ar.exception)).getCommandError();
705 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700706 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700707 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 }
710 }
711 openChannelResp = new IccOpenLogicalChannelResponse(
712 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700714 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 break;
717
718 case CMD_CLOSE_CHANNEL:
719 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800720 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 if (uiccCard == null) {
722 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900723 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 } else {
726 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
727 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
728 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 break;
730
731 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800732 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
733 break;
734
735 case CMD_NV_READ_ITEM:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800738 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
739 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
742 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 ar = (AsyncResult) msg.obj;
744 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800745 if (ar.exception == null && ar.result != null) {
746 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800748 request.result = "";
749 if (ar.result == null) {
750 loge("nvReadItem: Empty response");
751 } else if (ar.exception instanceof CommandException) {
752 loge("nvReadItem: CommandException: " +
753 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800755 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 }
757 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 break;
760
Jake Hambye994d462014-02-03 13:10:13 -0800761 case CMD_NV_WRITE_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
764 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_WRITE_ITEM_DONE:
770 handleNullReturnEvent(msg, "nvWriteItem");
771 break;
772
773 case CMD_NV_WRITE_CDMA_PRL:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800776 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800777 break;
778
779 case EVENT_NV_WRITE_CDMA_PRL_DONE:
780 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
781 break;
782
chen xu6dac5ab2018-10-26 17:39:23 -0700783 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800784 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700785 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
chen xu6dac5ab2018-10-26 17:39:23 -0700789 case EVENT_RESET_MODEM_CONFIG_DONE:
790 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800791 break;
792
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700793 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
794 request = (MainThreadRequest) msg.obj;
795 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
796 request);
797 Phone phone = getPhoneFromRequest(request);
798 if (phone != null) {
799 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
800 } else {
801 loge("isNRDualConnectivityEnabled: No phone object");
802 request.result = false;
803 notifyRequester(request);
804 }
805 break;
806 }
807
808 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
811 if (ar.exception == null && ar.result != null) {
812 request.result = ar.result;
813 } else {
814 // request.result must be set to something non-null
815 // for the calling thread to unblock
816 if (request.result != null) {
817 request.result = ar.result;
818 } else {
819 request.result = false;
820 }
821 if (ar.result == null) {
822 loge("isNRDualConnectivityEnabled: Empty response");
823 } else if (ar.exception instanceof CommandException) {
824 loge("isNRDualConnectivityEnabled: CommandException: "
825 + ar.exception);
826 } else {
827 loge("isNRDualConnectivityEnabled: Unknown exception");
828 }
829 }
830 notifyRequester(request);
831 break;
832
833 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
836 Phone phone = getPhoneFromRequest(request);
837 if (phone != null) {
838 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
839 request.workSource);
840 } else {
841 loge("enableNrDualConnectivity: No phone object");
842 request.result =
843 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
844 notifyRequester(request);
845 }
846 break;
847 }
848
849 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null) {
853 request.result =
854 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
855 } else {
856 request.result =
857 TelephonyManager
858 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
859 if (ar.exception instanceof CommandException) {
860 CommandException.Error error =
861 ((CommandException) (ar.exception)).getCommandError();
862 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
863 request.result =
864 TelephonyManager
865 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000866 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
867 request.result =
868 TelephonyManager
869 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700870 }
871 loge("enableNrDualConnectivity" + ": CommandException: "
872 + ar.exception);
873 } else {
874 loge("enableNrDualConnectivity" + ": Unknown exception");
875 }
876 }
877 notifyRequester(request);
878 break;
879 }
880
SongFerngWang9e060372020-12-21 16:41:52 +0800881 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800882 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800883 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
884 request);
885 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 break;
887
SongFerngWang9e060372020-12-21 16:41:52 +0800888 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result; // Integer
893 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530894 // request.result must be set to something non-null
895 // for the calling thread to unblock
896 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800898 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800900 loge("getAllowedNetworkTypesBitmask: CommandException: "
901 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800903 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
SongFerngWang9e060372020-12-21 16:41:52 +0800909 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800911 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
912 request);
913 Pair<Integer, Long> reasonWithNetworkTypes =
914 (Pair<Integer, Long>) request.argument;
915 getPhoneFromRequest(request).setAllowedNetworkTypes(
916 reasonWithNetworkTypes.first,
917 reasonWithNetworkTypes.second,
918 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 break;
920
SongFerngWang9e060372020-12-21 16:41:52 +0800921 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
922 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 break;
924
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000925 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
926 request = (MainThreadRequest)msg.obj;
927 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800928 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000929 break;
930
931 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
932 ar = (AsyncResult)msg.obj;
933 request = (MainThreadRequest)ar.userObj;
934 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000936 break;
937
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800938 case CMD_SET_VOICEMAIL_NUMBER:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
941 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800942 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
943 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800944 break;
945
946 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
947 handleNullReturnEvent(msg, "setVoicemailNumber");
948 break;
949
Stuart Scott54788802015-03-30 13:18:01 -0700950 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
953 request);
954 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
955 break;
956
957 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
958 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
959 break;
960
Shishir Agrawal302c8692015-06-19 13:49:39 -0700961 case CMD_PERFORM_NETWORK_SCAN:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
964 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
965 break;
966
Hall Liua1acea22020-09-18 19:04:59 -0700967 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700970 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
971 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
972 request.argument;
973 int callForwardingReason = args.first;
974 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800975 break;
Hall Liua1acea22020-09-18 19:04:59 -0700976 }
977 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700980 TelephonyManager.CallForwardingInfoCallback callback =
981 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
982 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800983 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700984 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800985 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
986 for (CallForwardInfo callForwardInfo : callForwardInfos) {
987 // Service Class is a bit mask per 3gpp 27.007. Search for
988 // any service for voice call.
989 if ((callForwardInfo.serviceClass
990 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700991 callForwardingInfo = new CallForwardingInfo(true,
992 callForwardInfo.reason,
993 callForwardInfo.number,
994 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800995 break;
996 }
997 }
998 // Didn't find a call forward info for voice call.
999 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001000 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1001 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001002 }
Hall Liua1acea22020-09-18 19:04:59 -07001003 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001004 } else {
1005 if (ar.result == null) {
1006 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1007 }
1008 if (ar.exception != null) {
1009 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1010 }
Hall Liuae527aa2020-09-29 17:10:18 -07001011 int errorCode = TelephonyManager
1012 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001013 if (ar.exception instanceof CommandException) {
1014 CommandException.Error error =
1015 ((CommandException) (ar.exception)).getCommandError();
1016 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001017 errorCode = TelephonyManager
1018 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001019 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001020 errorCode = TelephonyManager
1021 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001022 }
1023 }
Hall Liua1acea22020-09-18 19:04:59 -07001024 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001025 }
sqian80370722020-01-29 15:02:51 -08001026 break;
Hall Liua1acea22020-09-18 19:04:59 -07001027 }
sqian80370722020-01-29 15:02:51 -08001028
Hall Liua1acea22020-09-18 19:04:59 -07001029 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001032 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001033 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001034 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1035 request.argument).first;
1036 request.phone.setCallForwardingOption(
1037 callForwardingInfoToSet.isEnabled()
1038 ? CommandsInterface.CF_ACTION_ENABLE
1039 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001040 callForwardingInfoToSet.getReason(),
1041 callForwardingInfoToSet.getNumber(),
1042 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1043 break;
Hall Liua1acea22020-09-18 19:04:59 -07001044 }
sqian80370722020-01-29 15:02:51 -08001045
Hall Liua1acea22020-09-18 19:04:59 -07001046 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001049 Consumer<Integer> callback =
1050 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1051 request.argument).second;
1052 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001053 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001054 int errorCode = TelephonyManager.CallForwardingInfoCallback
1055 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001056 if (ar.exception instanceof CommandException) {
1057 CommandException.Error error =
1058 ((CommandException) (ar.exception)).getCommandError();
1059 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001060 errorCode = TelephonyManager.CallForwardingInfoCallback
1061 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001062 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001063 errorCode = TelephonyManager.CallForwardingInfoCallback
1064 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001065 }
1066 }
1067 callback.accept(errorCode);
1068 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001069 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001070 }
sqian80370722020-01-29 15:02:51 -08001071 break;
Hall Liua1acea22020-09-18 19:04:59 -07001072 }
sqian80370722020-01-29 15:02:51 -08001073
Hall Liua1acea22020-09-18 19:04:59 -07001074 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1077 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1078 break;
Hall Liua1acea22020-09-18 19:04:59 -07001079 }
sqian80370722020-01-29 15:02:51 -08001080
Hall Liua1acea22020-09-18 19:04:59 -07001081 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001084 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001085 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1086 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001087 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001088 // Service Class is a bit mask per 3gpp 27.007.
1089 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001090 if (callForwardResults.length > 1
1091 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001092 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001093 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001094 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1095 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001096 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001097 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001098 }
1099 } else {
1100 if (ar.result == null) {
1101 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1102 }
1103 if (ar.exception != null) {
1104 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1105 }
1106 if (ar.exception instanceof CommandException) {
1107 CommandException.Error error =
1108 ((CommandException) (ar.exception)).getCommandError();
1109 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1110 callForwardingStatus =
1111 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1112 }
1113 }
1114 }
Hall Liua1acea22020-09-18 19:04:59 -07001115 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001116 break;
Hall Liua1acea22020-09-18 19:04:59 -07001117 }
sqian80370722020-01-29 15:02:51 -08001118
Hall Liua1acea22020-09-18 19:04:59 -07001119 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001120 request = (MainThreadRequest) msg.obj;
1121 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001122 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1123 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001124 break;
Hall Liua1acea22020-09-18 19:04:59 -07001125 }
sqian80370722020-01-29 15:02:51 -08001126
Hall Liua1acea22020-09-18 19:04:59 -07001127 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001130 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1131 Consumer<Integer> callback =
1132 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1133 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001134 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001135 if (ar.exception instanceof CommandException) {
1136 CommandException.Error error =
1137 ((CommandException) (ar.exception)).getCommandError();
1138 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1140 } else {
1141 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1142 }
1143 } else {
1144 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1145 }
1146 } else {
1147 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1148 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001149 }
sqian80370722020-01-29 15:02:51 -08001150 break;
Hall Liua1acea22020-09-18 19:04:59 -07001151 }
sqian80370722020-01-29 15:02:51 -08001152
Shishir Agrawal302c8692015-06-19 13:49:39 -07001153 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 CellNetworkScanResult cellScanResult;
1157 if (ar.exception == null && ar.result != null) {
1158 cellScanResult = new CellNetworkScanResult(
1159 CellNetworkScanResult.STATUS_SUCCESS,
1160 (List<OperatorInfo>) ar.result);
1161 } else {
1162 if (ar.result == null) {
1163 loge("getCellNetworkScanResults: Empty response");
1164 }
1165 if (ar.exception != null) {
1166 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1167 }
1168 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1169 if (ar.exception instanceof CommandException) {
1170 CommandException.Error error =
1171 ((CommandException) (ar.exception)).getCommandError();
1172 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1173 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1174 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1175 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1176 }
1177 }
1178 cellScanResult = new CellNetworkScanResult(errorCode, null);
1179 }
1180 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001181 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 break;
1183
1184 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1185 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001186 ManualNetworkSelectionArgument selArg =
1187 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001188 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1189 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001190 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1191 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001192 break;
1193
1194 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 if (ar.exception == null) {
1198 request.result = true;
1199 } else {
1200 request.result = false;
1201 loge("setNetworkSelectionModeManual " + ar.exception);
1202 }
1203 notifyRequester(request);
1204 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 break;
1206
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 case CMD_GET_MODEM_ACTIVITY_INFO:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001210 if (defaultPhone != null) {
1211 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001212 } else {
1213 ResultReceiver result = (ResultReceiver) request.argument;
1214 Bundle bundle = new Bundle();
1215 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1216 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1217 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001218 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 break;
1220
1221 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001224 ResultReceiver result = (ResultReceiver) request.argument;
1225
1226 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001228 // Update the last modem activity info and the result of the request.
1229 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1230 if (isModemActivityInfoValid(info)) {
1231 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1232 int[] txTimeMs = info.getTransmitTimeMillis();
1233 int[] lastModemTxTimeMs = mLastModemActivityInfo
1234 .getTransmitTimeMillis();
1235 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1236 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1237 }
1238 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1239 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1240 + mLastModemActivityInfo.getSleepTimeMillis());
1241 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1242 + mLastModemActivityInfo.getIdleTimeMillis());
1243 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1244 mLastModemActivityInfo.setReceiveTimeMillis(
1245 info.getReceiveTimeMillis()
1246 + mLastModemActivityInfo.getReceiveTimeMillis());
1247 }
1248 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1249 mLastModemActivityInfo.getSleepTimeMillis(),
1250 mLastModemActivityInfo.getIdleTimeMillis(),
1251 mLastModemActivityInfo.getTransmitTimeMillis(),
1252 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 } else {
1254 if (ar.result == null) {
1255 loge("queryModemActivityInfo: Empty response");
1256 } else if (ar.exception instanceof CommandException) {
1257 loge("queryModemActivityInfo: CommandException: " +
1258 ar.exception);
1259 } else {
1260 loge("queryModemActivityInfo: Unknown exception");
1261 }
1262 }
sqian1a1be542020-03-05 11:37:28 -08001263 Bundle bundle = new Bundle();
1264 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1265 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001266 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 break;
1268
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 case CMD_SET_ALLOWED_CARRIERS:
1270 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001271 CarrierRestrictionRules argument =
1272 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001274 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001275 break;
1276
1277 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
1280 if (ar.exception == null && ar.result != null) {
1281 request.result = ar.result;
1282 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001283 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1284 if (ar.exception instanceof CommandException) {
1285 loge("setAllowedCarriers: CommandException: " + ar.exception);
1286 CommandException.Error error =
1287 ((CommandException) (ar.exception)).getCommandError();
1288 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1289 request.result =
1290 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1291 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 } else {
1293 loge("setAllowedCarriers: Unknown exception");
1294 }
1295 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001296 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 break;
1298
1299 case CMD_GET_ALLOWED_CARRIERS:
1300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001302 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 break;
1304
1305 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 if (ar.exception == null && ar.result != null) {
1309 request.result = ar.result;
1310 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001311 request.result = new IllegalStateException(
1312 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001313 if (ar.result == null) {
1314 loge("getAllowedCarriers: Empty response");
1315 } else if (ar.exception instanceof CommandException) {
1316 loge("getAllowedCarriers: CommandException: " +
1317 ar.exception);
1318 } else {
1319 loge("getAllowedCarriers: Unknown exception");
1320 }
1321 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 break;
1324
Nathan Haroldb3014052017-01-25 15:57:32 -08001325 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null && ar.result != null) {
1329 request.result = ar.result;
1330 } else {
1331 request.result = new IllegalArgumentException(
1332 "Failed to retrieve Forbidden Plmns");
1333 if (ar.result == null) {
1334 loge("getForbiddenPlmns: Empty response");
1335 } else {
1336 loge("getForbiddenPlmns: Unknown exception");
1337 }
1338 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001339 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001340 break;
1341
1342 case CMD_GET_FORBIDDEN_PLMNS:
1343 request = (MainThreadRequest) msg.obj;
1344 uiccCard = getUiccCardFromRequest(request);
1345 if (uiccCard == null) {
1346 loge("getForbiddenPlmns() UiccCard is null");
1347 request.result = new IllegalArgumentException(
1348 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001349 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001350 break;
1351 }
1352 Integer appType = (Integer) request.argument;
1353 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1354 if (uiccApp == null) {
1355 loge("getForbiddenPlmns() no app with specified type -- "
1356 + appType);
1357 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001358 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001359 break;
1360 } else {
1361 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1362 + " specified type -- " + appType);
1363 }
1364 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1365 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1366 onCompleted);
1367 break;
1368
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001369 case CMD_SWITCH_SLOTS:
1370 request = (MainThreadRequest) msg.obj;
1371 int[] physicalSlots = (int[]) request.argument;
1372 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1373 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1374 break;
1375
1376 case EVENT_SWITCH_SLOTS_DONE:
1377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001380 notifyRequester(request);
1381 break;
1382 case CMD_GET_NETWORK_SELECTION_MODE:
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1385 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1386 break;
1387
1388 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 if (ar.exception != null) {
1392 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1393 } else {
1394 int mode = ((int[]) ar.result)[0];
1395 if (mode == 0) {
1396 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1397 } else {
1398 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1399 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001400 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001401 notifyRequester(request);
1402 break;
1403 case CMD_GET_CDMA_ROAMING_MODE:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1406 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1407 break;
1408 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception != null) {
1412 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1413 } else {
1414 request.result = ((int[]) ar.result)[0];
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_CDMA_ROAMING_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1421 int mode = (int) request.argument;
1422 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1423 break;
1424 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1425 ar = (AsyncResult) msg.obj;
1426 request = (MainThreadRequest) ar.userObj;
1427 request.result = ar.exception == null;
1428 notifyRequester(request);
1429 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001430 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1433 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1434 break;
1435 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
1438 if (ar.exception != null) {
1439 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1440 } else {
1441 request.result = ((int[]) ar.result)[0];
1442 }
1443 notifyRequester(request);
1444 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1448 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001449 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1450 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001451 break;
1452 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 request.result = ar.exception == null;
1456 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001457 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 case CMD_GET_ALL_CELL_INFO:
1459 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001461 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001462 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 case EVENT_GET_ALL_CELL_INFO_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001466 // If a timeout occurs, the response will be null
1467 request.result = (ar.exception == null && ar.result != null)
1468 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 synchronized (request) {
1470 request.notifyAll();
1471 }
1472 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001473 case CMD_REQUEST_CELL_INFO_UPDATE:
1474 request = (MainThreadRequest) msg.obj;
1475 request.phone.requestCellInfoUpdate(request.workSource,
1476 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1477 break;
1478 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1482 try {
1483 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001485 cb.onError(
1486 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1487 ar.exception.getClass().getName(),
1488 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001489 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001490 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001491 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001492 } else {
1493 // use the result as returned
1494 cb.onCellInfo((List<CellInfo>) ar.result);
1495 }
1496 } catch (RemoteException re) {
1497 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1498 }
1499 break;
Sarah Chincc055732020-11-18 13:39:35 -08001500 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 request = (MainThreadRequest) msg.obj;
1502 WorkSource ws = (WorkSource) request.argument;
1503 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001504 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 break;
Sarah Chincc055732020-11-18 13:39:35 -08001506 }
1507 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = ar.result;
1512 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001513 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001514 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001515 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001516 }
1517
1518 synchronized (request) {
1519 request.notifyAll();
1520 }
1521 break;
Sarah Chincc055732020-11-18 13:39:35 -08001522 }
chen xu6dac5ab2018-10-26 17:39:23 -07001523 case CMD_MODEM_REBOOT:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001526 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001527 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001528 case EVENT_CMD_MODEM_REBOOT_DONE:
1529 handleNullReturnEvent(msg, "rebootModem");
1530 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001531 case CMD_REQUEST_ENABLE_MODEM:
1532 request = (MainThreadRequest) msg.obj;
1533 boolean enable = (boolean) request.argument;
1534 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001535 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001536 PhoneConfigurationManager.getInstance()
1537 .enablePhone(request.phone, enable, onCompleted);
1538 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001539 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001543 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001544 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001545 if ((boolean) request.result) {
1546 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1547 updateModemStateMetrics();
1548 } else {
1549 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1550 + ar.exception);
1551 }
1552 notifyRequester(request);
1553 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001554 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001555 case CMD_GET_MODEM_STATUS:
1556 request = (MainThreadRequest) msg.obj;
1557 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1558 PhoneConfigurationManager.getInstance()
1559 .getPhoneStatusFromModem(request.phone, onCompleted);
1560 break;
1561 case EVENT_GET_MODEM_STATUS_DONE:
1562 ar = (AsyncResult) msg.obj;
1563 request = (MainThreadRequest) ar.userObj;
1564 int id = request.phone.getPhoneId();
1565 if (ar.exception == null && ar.result != null) {
1566 request.result = ar.result;
1567 //update the cache as modem status has changed
1568 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1569 (boolean) request.result);
1570 } else {
1571 // Return true if modem status cannot be retrieved. For most cases,
1572 // modem status is on. And for older version modems, GET_MODEM_STATUS
1573 // and disable modem are not supported. Modem is always on.
1574 // TODO: this should be fixed in R to support a third
1575 // status UNKNOWN b/131631629
1576 request.result = true;
1577 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1578 + ar.exception);
1579 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001580 notifyRequester(request);
1581 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001582 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1583 request = (MainThreadRequest) msg.obj;
1584 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1585 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1586 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1587 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1588 break;
1589 }
1590 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1594 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1595 args.second.accept(ar.exception == null);
1596 notifyRequester(request);
1597 break;
1598 }
Sarah Chincc055732020-11-18 13:39:35 -08001599 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1600 request = (MainThreadRequest) msg.obj;
1601 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1602 Phone phone = getPhoneFromRequest(request);
1603 if (phone != null) {
1604 phone.getSystemSelectionChannels(onCompleted);
1605 } else {
1606 loge("getSystemSelectionChannels: No phone object");
1607 request.result = new ArrayList<RadioAccessSpecifier>();
1608 notifyRequester(request);
1609 }
1610 break;
1611 }
1612 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1613 ar = (AsyncResult) msg.obj;
1614 request = (MainThreadRequest) ar.userObj;
1615 if (ar.exception == null && ar.result != null) {
1616 request.result = ar.result;
1617 } else {
1618 request.result = new IllegalArgumentException(
1619 "Failed to retrieve system selection channels");
1620 if (ar.result == null) {
1621 loge("getSystemSelectionChannels: Empty response");
1622 } else {
1623 loge("getSystemSelectionChannels: Unknown exception");
1624 }
1625 }
1626 notifyRequester(request);
1627 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001628 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception == null && ar.result != null) {
1632 request.result = ar.result;
1633 } else {
1634 request.result = -1;
1635 loge("Failed to set Forbidden Plmns");
1636 if (ar.result == null) {
1637 loge("setForbidenPlmns: Empty response");
1638 } else if (ar.exception != null) {
1639 loge("setForbiddenPlmns: Exception: " + ar.exception);
1640 request.result = -1;
1641 } else {
1642 loge("setForbiddenPlmns: Unknown exception");
1643 }
1644 }
1645 notifyRequester(request);
1646 break;
1647 case CMD_SET_FORBIDDEN_PLMNS:
1648 request = (MainThreadRequest) msg.obj;
1649 uiccCard = getUiccCardFromRequest(request);
1650 if (uiccCard == null) {
1651 loge("setForbiddenPlmns: UiccCard is null");
1652 request.result = -1;
1653 notifyRequester(request);
1654 break;
1655 }
1656 Pair<Integer, List<String>> setFplmnsArgs =
1657 (Pair<Integer, List<String>>) request.argument;
1658 appType = setFplmnsArgs.first;
1659 List<String> fplmns = setFplmnsArgs.second;
1660 uiccApp = uiccCard.getApplicationByType(appType);
1661 if (uiccApp == null) {
1662 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1663 request.result = -1;
1664 loge("Failed to get UICC App");
1665 notifyRequester(request);
1666 } else {
1667 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1668 ((SIMRecords) uiccApp.getIccRecords())
1669 .setForbiddenPlmns(onCompleted, fplmns);
1670 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001671 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001672 case CMD_ERASE_MODEM_CONFIG:
1673 request = (MainThreadRequest) msg.obj;
1674 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1675 defaultPhone.eraseModemConfig(onCompleted);
1676 break;
1677 case EVENT_ERASE_MODEM_CONFIG_DONE:
1678 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001679 break;
zoey chenf95ca592019-12-30 16:11:23 +08001680
1681 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1684 Pair<String, String> changed = (Pair<String, String>) request.argument;
1685 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1686 changed.first, changed.second, onCompleted);
1687 break;
1688 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception == null) {
1692 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001693 // If the operation is successful, update the PIN storage
1694 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1695 int phoneId = getPhoneFromRequest(request).getPhoneId();
1696 UiccController.getInstance().getPinStorage()
1697 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001698 } else {
1699 request.result = msg.arg1;
1700 }
1701 notifyRequester(request);
1702 break;
1703
Michele Berionned9fbae52020-11-13 02:36:59 +00001704 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1707 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1708 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1709 enabled.first, enabled.second, onCompleted);
1710 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001711 }
zoey chenf95ca592019-12-30 16:11:23 +08001712 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception == null) {
1716 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001717 // If the operation is successful, update the PIN storage
1718 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1719 int phoneId = getPhoneFromRequest(request).getPhoneId();
1720 if (enabled.first) {
1721 UiccController.getInstance().getPinStorage()
1722 .storePin(enabled.second, phoneId);
1723 } else {
1724 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1725 }
zoey chenf95ca592019-12-30 16:11:23 +08001726 } else {
1727 request.result = msg.arg1;
1728 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001729
1730
zoey chenf95ca592019-12-30 16:11:23 +08001731 notifyRequester(request);
1732 break;
1733
Peter Wangdafb9ac2020-01-15 14:13:38 -08001734 case MSG_NOTIFY_USER_ACTIVITY:
1735 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001736 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001737 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1738 getDefaultPhone().getContext().sendBroadcastAsUser(
1739 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1740 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001741
1742 case CMD_SET_DATA_THROTTLING: {
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1745 DataThrottlingRequest dataThrottlingRequest =
1746 (DataThrottlingRequest) request.argument;
1747 Phone phone = getPhoneFromRequest(request);
1748 if (phone != null) {
1749 phone.setDataThrottling(onCompleted,
1750 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1751 dataThrottlingRequest.getCompletionDurationMillis());
1752 } else {
1753 loge("setDataThrottling: No phone object");
1754 request.result =
1755 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1756 notifyRequester(request);
1757 }
1758
1759 break;
1760 }
1761 case EVENT_SET_DATA_THROTTLING_DONE:
1762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764
1765 if (ar.exception == null) {
1766 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1767 } else if (ar.exception instanceof CommandException) {
1768 loge("setDataThrottling: CommandException: " + ar.exception);
1769 CommandException.Error error =
1770 ((CommandException) (ar.exception)).getCommandError();
1771
1772 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1773 request.result = TelephonyManager
1774 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1775 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1776 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1777 } else {
1778 request.result =
1779 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1780 }
1781 } else {
1782 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1783 }
1784 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1785 notifyRequester(request);
1786 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001787
1788 case CMD_SET_SIM_POWER: {
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1791 request = (MainThreadRequest) msg.obj;
1792 int stateToSet =
1793 ((Pair<Integer, IIntegerConsumer>)
1794 request.argument).first;
1795 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1796 break;
1797 }
1798 case EVENT_SET_SIM_POWER_DONE: {
1799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801 IIntegerConsumer callback =
1802 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1803 if (ar.exception != null) {
1804 loge("setSimPower exception: " + ar.exception);
1805 int errorCode = TelephonyManager.CallForwardingInfoCallback
1806 .RESULT_ERROR_UNKNOWN;
1807 if (ar.exception instanceof CommandException) {
1808 CommandException.Error error =
1809 ((CommandException) (ar.exception)).getCommandError();
1810 if (error == CommandException.Error.SIM_ERR) {
1811 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1812 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1813 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1814 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1815 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1816 } else {
1817 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1818 }
1819 }
1820 try {
1821 callback.accept(errorCode);
1822 } catch (RemoteException e) {
1823 // Ignore if the remote process is no longer available to call back.
1824 Log.w(LOG_TAG, "setSimPower: callback not available.");
1825 }
1826 } else {
1827 try {
1828 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1829 } catch (RemoteException e) {
1830 // Ignore if the remote process is no longer available to call back.
1831 Log.w(LOG_TAG, "setSimPower: callback not available.");
1832 }
1833 }
1834 break;
1835 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001836 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1837 request = (MainThreadRequest) msg.obj;
1838
1839 final Phone phone = getPhoneFromRequest(request);
1840 if (phone == null || phone.getServiceStateTracker() == null) {
1841 request.result = new IllegalStateException("Phone or SST is null");
1842 notifyRequester(request);
1843 break;
1844 }
1845
1846 Pair<Integer, SignalStrengthUpdateRequest> pair =
1847 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1848 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1849 request);
1850 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1851 request.subId, pair.first /*callingUid*/,
1852 pair.second /*request*/, onCompleted);
1853 break;
1854 }
1855 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1856 ar = (AsyncResult) msg.obj;
1857 request = (MainThreadRequest) ar.userObj;
1858 // request.result will be the exception of ar if present, true otherwise.
1859 // Be cautious not to leave result null which will wait() forever
1860 request.result = ar.exception != null ? ar.exception : true;
1861 notifyRequester(request);
1862 break;
1863 }
1864 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1865 request = (MainThreadRequest) msg.obj;
1866
1867 Phone phone = getPhoneFromRequest(request);
1868 if (phone == null || phone.getServiceStateTracker() == null) {
1869 request.result = new IllegalStateException("Phone or SST is null");
1870 notifyRequester(request);
1871 break;
1872 }
1873
1874 Pair<Integer, SignalStrengthUpdateRequest> pair =
1875 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1876 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1877 request);
1878 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1879 request.subId, pair.first /*callingUid*/,
1880 pair.second /*request*/, onCompleted);
1881 break;
1882 }
1883 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 request.result = ar.exception != null ? ar.exception : true;
1887 notifyRequester(request);
1888 break;
1889 }
Jordan Liud5366d92020-11-24 14:50:34 -08001890
Michele Berionned9fbae52020-11-13 02:36:59 +00001891 case CMD_PREPARE_UNATTENDED_REBOOT:
1892 request = (MainThreadRequest) msg.obj;
1893 request.result =
1894 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1895 notifyRequester(request);
1896 break;
1897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 default:
1899 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1900 break;
1901 }
1902 }
Jake Hambye994d462014-02-03 13:10:13 -08001903
Pengquan Menga1bb6272018-09-06 09:59:22 -07001904 private void notifyRequester(MainThreadRequest request) {
1905 synchronized (request) {
1906 request.notifyAll();
1907 }
1908 }
1909
Jake Hambye994d462014-02-03 13:10:13 -08001910 private void handleNullReturnEvent(Message msg, String command) {
1911 AsyncResult ar = (AsyncResult) msg.obj;
1912 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1913 if (ar.exception == null) {
1914 request.result = true;
1915 } else {
1916 request.result = false;
1917 if (ar.exception instanceof CommandException) {
1918 loge(command + ": CommandException: " + ar.exception);
1919 } else {
1920 loge(command + ": Unknown exception");
1921 }
1922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001923 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
1927 /**
1928 * Posts the specified command to be executed on the main thread,
1929 * waits for the request to complete, and returns the result.
1930 * @see #sendRequestAsync
1931 */
1932 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001933 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1934 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001935 }
1936
1937 /**
1938 * Posts the specified command to be executed on the main thread,
1939 * waits for the request to complete, and returns the result.
1940 * @see #sendRequestAsync
1941 */
1942 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1943 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001944 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001945 }
1946
1947 /**
1948 * Posts the specified command to be executed on the main thread,
1949 * waits for the request to complete, and returns the result.
1950 * @see #sendRequestAsync
1951 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001952 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001953 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1954 }
1955
1956 /**
1957 * Posts the specified command to be executed on the main thread,
1958 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1959 * if not timeout or null otherwise.
1960 * @see #sendRequestAsync
1961 */
1962 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1963 long timeoutInMs) {
1964 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001965 }
1966
1967 /**
1968 * Posts the specified command to be executed on the main thread,
1969 * waits for the request to complete, and returns the result.
1970 * @see #sendRequestAsync
1971 */
Nathan Harold92bed182018-10-12 18:16:49 -07001972 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001973 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001974 }
1975
1976 /**
1977 * Posts the specified command to be executed on the main thread,
1978 * waits for the request to complete, and returns the result.
1979 * @see #sendRequestAsync
1980 */
1981 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001982 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1983 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001984 }
1985
1986 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001987 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1988 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1989 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001990 * @see #sendRequestAsync
1991 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001992 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1993 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1995 throw new RuntimeException("This method will deadlock if called from the main thread.");
1996 }
1997
Nathan Harold92bed182018-10-12 18:16:49 -07001998 MainThreadRequest request = null;
1999 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2000 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2001 } else if (phone != null) {
2002 request = new MainThreadRequest(argument, phone, workSource);
2003 } else {
2004 request = new MainThreadRequest(argument, subId, workSource);
2005 }
2006
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 Message msg = mMainThreadHandler.obtainMessage(command, request);
2008 msg.sendToTarget();
2009
Rambo Wang0f050d82021-02-12 11:43:36 -08002010
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 if (timeoutInMs >= 0) {
2013 // Wait for at least timeoutInMs before returning null request result
2014 long now = SystemClock.elapsedRealtime();
2015 long deadline = now + timeoutInMs;
2016 while (request == null && now < deadline) {
2017 try {
2018 request.wait(deadline - now);
2019 } catch (InterruptedException e) {
2020 // Do nothing, go back and check if request is completed or timeout
2021 } finally {
2022 now = SystemClock.elapsedRealtime();
2023 }
2024 }
2025 } else {
2026 // Wait for the request to complete
2027 while (request.result == null) {
2028 try {
2029 request.wait();
2030 } catch (InterruptedException e) {
2031 // Do nothing, go back and wait until the request is complete
2032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034 }
2035 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002036 if (request.result == null) {
2037 Log.wtf(LOG_TAG,
2038 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 return request.result;
2041 }
2042
2043 /**
2044 * Asynchronous ("fire and forget") version of sendRequest():
2045 * Posts the specified command to be executed on the main thread, and
2046 * returns immediately.
2047 * @see #sendRequest
2048 */
2049 private void sendRequestAsync(int command) {
2050 mMainThreadHandler.sendEmptyMessage(command);
2051 }
2052
2053 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002054 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002055 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002056 */
2057 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002058 sendRequestAsync(command, argument, null, null);
2059 }
2060
2061 /**
2062 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2063 * @see {@link #sendRequest(int,Object)}
2064 */
2065 private void sendRequestAsync(
2066 int command, Object argument, Phone phone, WorkSource workSource) {
2067 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002068 Message msg = mMainThreadHandler.obtainMessage(command, request);
2069 msg.sendToTarget();
2070 }
2071
2072 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 * Initialize the singleton PhoneInterfaceManager instance.
2074 * This is only done once, at startup, from PhoneApp.onCreate().
2075 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002076 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 synchronized (PhoneInterfaceManager.class) {
2078 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002079 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 } else {
2081 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2082 }
2083 return sInstance;
2084 }
2085 }
2086
2087 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002088 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002091 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002092 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2094 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002095 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002096 mTelephonySharedPreferences =
2097 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002098 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002099 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002100 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002101 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002102
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 publish();
2104 }
2105
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002106 private Phone getDefaultPhone() {
2107 Phone thePhone = getPhone(getDefaultSubscription());
2108 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2109 }
2110
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 private void publish() {
2112 if (DBG) log("publish: " + this);
2113
Peter Wangc035ce42020-01-08 21:00:22 -08002114 TelephonyFrameworkInitializer
2115 .getTelephonyServiceManager()
2116 .getTelephonyServiceRegisterer()
2117 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Stuart Scott584921c2015-01-15 17:10:34 -08002120 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002121 if (request.phone != null) {
2122 return request.phone;
2123 } else {
2124 return getPhoneFromSubId(request.subId);
2125 }
2126 }
2127
2128 private Phone getPhoneFromSubId(int subId) {
2129 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2130 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002131 }
2132
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002133 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2134 Phone phone = getPhoneFromRequest(request);
2135 return phone == null ? null :
2136 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2137 }
2138
Wink Saville36469e72014-06-11 15:17:00 -07002139 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002140 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002141 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002144 private void sendEraseModemConfig(Phone phone) {
2145 if (phone != null) {
2146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2147 mApp, phone.getSubId(), "eraseModemConfig");
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2151 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
2155 }
2156 }
2157
Peter Wang050bb052020-01-13 23:33:09 -08002158 private boolean isImsAvailableOnDevice() {
2159 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2160 if (pm == null) {
2161 // For some reason package manger is not available.. This will fail internally anyway,
2162 // so do not throw error and allow.
2163 return true;
2164 }
2165 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2166 }
2167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002169 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002170 }
2171
Wink Savilleb564aae2014-10-23 10:18:09 -07002172 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 if (DBG) log("dial: " + number);
2174 // No permission check needed here: This is just a wrapper around the
2175 // ACTION_DIAL intent, which is available to any app since it puts up
2176 // the UI before it does anything.
2177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 String url = createTelUrl(number);
2181 if (url == null) {
2182 return;
2183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185 // PENDING: should we just silently fail if phone is offhook or ringing?
2186 PhoneConstants.State state = mCM.getState(subId);
2187 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2188 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2189 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2190 mApp.startActivity(intent);
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195 }
2196
2197 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002198 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Wink Savilleb564aae2014-10-23 10:18:09 -07002201 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 if (DBG) log("call: " + number);
2203
2204 // This is just a wrapper around the ACTION_CALL intent, but we still
2205 // need to do a permission check since we're calling startActivity()
2206 // from the context of the phone app.
2207 enforceCallPermission();
2208
Jordan Liu1617b712019-07-10 15:06:26 -07002209 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 != AppOpsManager.MODE_ALLOWED) {
2211 return;
2212 }
2213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 String url = createTelUrl(number);
2217 if (url == null) {
2218 return;
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221 boolean isValid = false;
2222 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2223 if (slist != null) {
2224 for (SubscriptionInfo subInfoRecord : slist) {
2225 if (subInfoRecord.getSubscriptionId() == subId) {
2226 isValid = true;
2227 break;
2228 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002229 }
Wink Saville08874612014-08-31 19:19:58 -07002230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 if (!isValid) {
2232 return;
2233 }
Wink Saville08874612014-08-31 19:19:58 -07002234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2236 intent.putExtra(SUBSCRIPTION_KEY, subId);
2237 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2238 mApp.startActivity(intent);
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
2241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
Wink Savilleb564aae2014-10-23 10:18:09 -07002244 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002245 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002246 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2247 }
2248
Wink Savilleb564aae2014-10-23 10:18:09 -07002249 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002250 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002259 Phone phone = getPhone(subId);
2260 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 checkSimPin.start();
2262 return checkSimPin.unlockSim(null, pin);
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002273 Phone phone = getPhone(subId);
2274 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 checkSimPuk.start();
2276 return checkSimPuk.unlockSim(puk, pin);
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
2282 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002283 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 * a synchronous one.
2285 */
2286 private static class UnlockSim extends Thread {
2287
2288 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002289 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290
2291 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002292 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2293 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294
2295 // For replies from SimCard interface
2296 private Handler mHandler;
2297
2298 // For async handler to identify request type
2299 private static final int SUPPLY_PIN_COMPLETE = 100;
2300
Michele Berionned9fbae52020-11-13 02:36:59 +00002301 UnlockSim(int phoneId, IccCard simCard) {
2302 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 mSimCard = simCard;
2304 }
2305
2306 @Override
2307 public void run() {
2308 Looper.prepare();
2309 synchronized (UnlockSim.this) {
2310 mHandler = new Handler() {
2311 @Override
2312 public void handleMessage(Message msg) {
2313 AsyncResult ar = (AsyncResult) msg.obj;
2314 switch (msg.what) {
2315 case SUPPLY_PIN_COMPLETE:
2316 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2317 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002318 mRetryCount = msg.arg1;
2319 if (ar.exception != null) {
2320 if (ar.exception instanceof CommandException &&
2321 ((CommandException)(ar.exception)).getCommandError()
2322 == CommandException.Error.PASSWORD_INCORRECT) {
2323 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002324 } //When UiccCardApp dispose,handle message and return exception
2325 else if (ar.exception instanceof CommandException &&
2326 ((CommandException) (ar.exception)).getCommandError()
2327 == CommandException.Error.ABORTED) {
2328 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002329 } else {
2330 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2331 }
2332 } else {
2333 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mDone = true;
2336 UnlockSim.this.notifyAll();
2337 }
2338 break;
2339 }
2340 }
2341 };
2342 UnlockSim.this.notifyAll();
2343 }
2344 Looper.loop();
2345 }
2346
2347 /*
2348 * Use PIN or PUK to unlock SIM card
2349 *
2350 * If PUK is null, unlock SIM card with PIN
2351 *
2352 * If PUK is not null, unlock SIM card with PUK and set PIN code
2353 */
Wink Saville9de0f752013-10-22 19:04:03 -07002354 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355
2356 while (mHandler == null) {
2357 try {
2358 wait();
2359 } catch (InterruptedException e) {
2360 Thread.currentThread().interrupt();
2361 }
2362 }
2363 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2364
2365 if (puk == null) {
2366 mSimCard.supplyPin(pin, callback);
2367 } else {
2368 mSimCard.supplyPuk(puk, pin, callback);
2369 }
2370
2371 while (!mDone) {
2372 try {
2373 Log.d(LOG_TAG, "wait for done");
2374 wait();
2375 } catch (InterruptedException e) {
2376 // Restore the interrupted status
2377 Thread.currentThread().interrupt();
2378 }
2379 }
2380 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002381 int[] resultArray = new int[2];
2382 resultArray[0] = mResult;
2383 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002384
2385 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2386 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2387 }
2388
Wink Saville9de0f752013-10-22 19:04:03 -07002389 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391 }
2392
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002393 /**
2394 * This method has been removed due to privacy and stability concerns.
2395 */
2396 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002398 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2399 return;
Wink Saville36469e72014-06-11 15:17:00 -07002400 }
2401
Nathan Harold1f889d82020-06-04 17:05:26 -07002402 @Override
2403 public void updateServiceLocationWithPackageName(String callingPackage) {
2404 mApp.getSystemService(AppOpsManager.class)
2405 .checkPackage(Binder.getCallingUid(), callingPackage);
2406
Nathan Haroldf096d982020-11-18 17:18:06 -08002407 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002408 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2409 // Callers targeting S have no business invoking this method.
2410 return;
2411 }
2412
2413 LocationAccessPolicy.LocationPermissionResult locationResult =
2414 LocationAccessPolicy.checkLocationPermission(mApp,
2415 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2416 .setCallingPackage(callingPackage)
2417 .setCallingFeatureId(null)
2418 .setCallingPid(Binder.getCallingPid())
2419 .setCallingUid(Binder.getCallingUid())
2420 .setMethod("updateServiceLocation")
2421 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2422 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2423 .build());
2424 // Apps that lack location permission have no business calling this method;
2425 // however, because no permission was declared in the public API, denials must
2426 // all be "soft".
2427 switch (locationResult) {
2428 case DENIED_HARD: /* fall through */
2429 case DENIED_SOFT:
2430 return;
2431 }
2432
2433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002436 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002438 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002445 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 @Override
2447 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002448 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002449 }
2450
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002451
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002452 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002453 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2454 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2455 callingFeatureId);
2456 }
2457
2458 @Deprecated
2459 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002461 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2462 }
2463
2464 @Override
2465 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2466 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002468 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 return false;
2470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 return isRadioOnForSubscriber(subId);
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
2477 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 }
2479
2480 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 final Phone phone = getPhone(subId);
2484 if (phone != null) {
2485 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2486 } else {
2487 return false;
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493
2494 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002495 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
Wink Saville36469e72014-06-11 15:17:00 -07002497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 final Phone phone = getPhone(subId);
2504 if (phone != null) {
2505 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Wink Saville36469e72014-06-11 15:17:00 -07002510 }
2511
2512 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002513 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002514 }
2515
Wink Savilleb564aae2014-10-23 10:18:09 -07002516 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 final Phone phone = getPhone(subId);
2522 if (phone == null) {
2523 return false;
2524 }
2525 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2526 toggleRadioOnOffForSubscriber(subId);
2527 }
2528 return true;
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
Wink Saville36469e72014-06-11 15:17:00 -07002533
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002534 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002535 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002536 /*
2537 * If any of the Radios are available, it will need to be
2538 * shutdown. So return true if any Radio is available.
2539 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2543 Phone phone = PhoneFactory.getPhone(i);
2544 if (phone != null && phone.isRadioAvailable()) return true;
2545 }
2546 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2547 return false;
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002550 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002551 }
2552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002554 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 enforceModifyPermission();
2556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2560 logv("Shutting down Phone " + i);
2561 shutdownRadioUsingPhoneId(i);
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002565 }
2566 }
2567
2568 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002569 Phone phone = PhoneFactory.getPhone(phoneId);
2570 if (phone != null && phone.isRadioAvailable()) {
2571 phone.shutdownRadio();
2572 }
2573 }
2574
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2581 if (defaultPhone != null) {
2582 defaultPhone.setRadioPower(turnOn);
2583 return true;
2584 } else {
2585 loge("There's no default phone.");
2586 return false;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002590 }
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
Wink Savilleb564aae2014-10-23 10:18:09 -07002593 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 final Phone phone = getPhone(subId);
2599 if (phone != null) {
2600 phone.setRadioPower(turnOn);
2601 return true;
2602 } else {
2603 return false;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
Wink Saville36469e72014-06-11 15:17:00 -07002610 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 public boolean enableDataConnectivity() {
2613 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 int subId = mSubscriptionController.getDefaultDataSubId();
2618 final Phone phone = getPhone(subId);
2619 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002620 phone.getDataEnabledSettings().setDataEnabled(
2621 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 return true;
2623 } else {
2624 return false;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Wink Saville36469e72014-06-11 15:17:00 -07002631 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 public boolean disableDataConnectivity() {
2634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 int subId = mSubscriptionController.getDefaultDataSubId();
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002641 phone.getDataEnabledSettings().setDataEnabled(
2642 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 return true;
2644 } else {
2645 return false;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002653 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002658 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 } else {
2660 return false;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
2667 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002668 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002669 }
2670
pkanwarae03a6b2016-11-06 20:37:09 -08002671 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 enforceCallPermission();
2673
2674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2677 return;
2678 }
2679 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2680 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
pkanwar32d516d2016-10-14 19:37:38 -07002684 };
2685
Wink Savilleb564aae2014-10-23 10:18:09 -07002686 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2692 return false;
2693 }
2694 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002701 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002702 }
2703
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002704 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 Phone phone = PhoneFactory.getPhone(slotIndex);
2708 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2709 PhoneConstantConversions.convertCallState(phone.getState());
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 }
2714
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002716 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002717 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2718 }
2719
2720 @Override
2721 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002724 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 if (phone != null) {
2726 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2727 } else {
2728 return PhoneConstantConversions.convertDataState(
2729 PhoneConstants.DataState.DISCONNECTED);
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
2735
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002737 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002738 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2739 }
2740
2741 @Override
2742 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 final long identity = Binder.clearCallingIdentity();
2744 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 if (phone != null) {
2747 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2748 } else {
2749 return TelephonyManager.DATA_ACTIVITY_NONE;
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
2755
2756 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002757 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002759 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002760
2761 LocationAccessPolicy.LocationPermissionResult locationResult =
2762 LocationAccessPolicy.checkLocationPermission(mApp,
2763 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2764 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002765 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002766 .setCallingPid(Binder.getCallingPid())
2767 .setCallingUid(Binder.getCallingUid())
2768 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002769 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002770 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2771 .build());
2772 switch (locationResult) {
2773 case DENIED_HARD:
2774 throw new SecurityException("Not allowed to access cell location");
2775 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002776 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2777 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002784 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002785 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Svetoslav64fad262015-04-14 14:35:21 -07002789 }
2790
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 @Override
Jack Yu01425032020-02-22 19:38:58 -08002792 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002793 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2794 // registered cell info, so return a NULL country instead.
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002797 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2798 // Get default phone in this case.
2799 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2800 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002801 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002803 if (phone == null) return "";
2804 ServiceStateTracker sst = phone.getServiceStateTracker();
2805 if (sst == null) return "";
2806 LocaleTracker lt = sst.getLocaleTracker();
2807 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002808 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002812 }
2813
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002814 /**
2815 * This method was removed due to potential issues caused by performing partial
2816 * updates of service state, and lack of a credible use case.
2817 *
2818 * This has the ability to break the telephony implementation by disabling notification of
2819 * changes in device connectivity. DO NOT USE THIS!
2820 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 public void enableLocationUpdates() {
2823 mApp.enforceCallingOrSelfPermission(
2824 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 }
2826
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002827 /**
2828 * This method was removed due to potential issues caused by performing partial
2829 * updates of service state, and lack of a credible use case.
2830 *
2831 * This has the ability to break the telephony implementation by disabling notification of
2832 * changes in device connectivity. DO NOT USE THIS!
2833 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 @Override
2835 public void disableLocationUpdates() {
2836 mApp.enforceCallingOrSelfPermission(
2837 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
2840 @Override
2841 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002842 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2843 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002844 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002845 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2846 throw new SecurityException(
2847 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2848 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002849
Jordan Liu1617b712019-07-10 15:06:26 -07002850 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2852 return null;
2853 }
Svetoslav64fad262015-04-14 14:35:21 -07002854
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002855 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002857 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002858 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859
Nathan Haroldf180aac2018-06-01 18:43:55 -07002860 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2861 for (CellInfo ci : info) {
2862 if (ci instanceof CellInfoGsm) {
2863 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2864 } else if (ci instanceof CellInfoWcdma) {
2865 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002868 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002871 private List<CellInfo> getCachedCellInfo() {
2872 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2873 for (Phone phone : PhoneFactory.getPhones()) {
2874 List<CellInfo> info = phone.getAllCellInfo();
2875 if (info != null) cellInfos.addAll(info);
2876 }
2877 return cellInfos;
2878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879
2880 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002881 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002883 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002884
2885 LocationAccessPolicy.LocationPermissionResult locationResult =
2886 LocationAccessPolicy.checkLocationPermission(mApp,
2887 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2888 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002889 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002890 .setCallingPid(Binder.getCallingPid())
2891 .setCallingUid(Binder.getCallingUid())
2892 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002893 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002894 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2895 .build());
2896 switch (locationResult) {
2897 case DENIED_HARD:
2898 throw new SecurityException("Not allowed to access cell info");
2899 case DENIED_SOFT:
2900 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
Nathan Haroldf096d982020-11-18 17:18:06 -08002903 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002904 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2905 return getCachedCellInfo();
2906 }
2907
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002908 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002909 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2913 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002914 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002915 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 if (info != null) cellInfos.addAll(info);
2917 }
2918 return cellInfos;
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
2922 }
2923
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002924 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2926 String callingFeatureId) {
2927 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2928 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 }
2930
2931 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002932 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2933 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002934 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002935 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002936 }
2937
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002938 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2939 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002940 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002941 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002942
2943 LocationAccessPolicy.LocationPermissionResult locationResult =
2944 LocationAccessPolicy.checkLocationPermission(mApp,
2945 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2946 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002948 .setCallingPid(Binder.getCallingPid())
2949 .setCallingUid(Binder.getCallingUid())
2950 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002951 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2952 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002953 .build());
2954 switch (locationResult) {
2955 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002956 if (TelephonyPermissions
2957 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002958 // Safetynet logging for b/154934934
2959 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2960 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 throw new SecurityException("Not allowed to access cell info");
2962 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002963 if (TelephonyPermissions
2964 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002965 // Safetynet logging for b/154934934
2966 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2967 }
Nathan Harold5320c422019-05-09 10:26:08 -07002968 try {
2969 cb.onCellInfo(new ArrayList<CellInfo>());
2970 } catch (RemoteException re) {
2971 // Drop without consequences
2972 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002973 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002974 }
2975
Nathan Harolda939a962019-05-09 10:13:47 -07002976
2977 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002978 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2979
2980 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2981 }
2982
2983 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002985 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002994 }
2995
Shishir Agrawala9f32182016-04-12 12:00:16 -07002996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002998 Phone phone = PhoneFactory.getPhone(slotIndex);
2999 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003000 return null;
3001 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003002 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003003 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003004 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003005 return null;
3006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 return phone.getImei();
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003014 }
3015
3016 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003017 public String getTypeAllocationCodeForSlot(int slotIndex) {
3018 Phone phone = PhoneFactory.getPhone(slotIndex);
3019 String tac = null;
3020 if (phone != null) {
3021 String imei = phone.getImei();
3022 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3023 }
3024 return tac;
3025 }
3026
3027 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003028 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003029 Phone phone = PhoneFactory.getPhone(slotIndex);
3030 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003031 return null;
3032 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033
Jeff Davidson913390f2018-02-23 17:11:49 -08003034 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003035 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003036 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003037 return null;
3038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 return phone.getMeid();
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Jack Yu2af8d712017-03-15 17:14:14 -07003046 }
3047
3048 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003049 public String getManufacturerCodeForSlot(int slotIndex) {
3050 Phone phone = PhoneFactory.getPhone(slotIndex);
3051 String manufacturerCode = null;
3052 if (phone != null) {
3053 String meid = phone.getMeid();
3054 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3055 }
3056 return manufacturerCode;
3057 }
3058
3059 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003060 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3061 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003062 Phone phone = PhoneFactory.getPhone(slotIndex);
3063 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 return null;
3065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003066 int subId = phone.getSubId();
3067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003068 mApp, subId, callingPackage, callingFeatureId,
3069 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003070 return null;
3071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 return phone.getDeviceSvn();
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003079 }
3080
fionaxu43304da2017-11-27 22:51:16 -08003081 @Override
3082 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 final Phone phone = getPhone(subId);
3086 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
fionaxu43304da2017-11-27 22:51:16 -08003090 }
3091
3092 @Override
3093 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 return phone == null ? null : phone.getCarrierName();
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
fionaxu43304da2017-11-27 22:51:16 -08003101 }
3102
calvinpanffe225e2018-11-01 19:43:06 +08003103 @Override
chen xu0026ca62019-03-06 15:28:50 -08003104 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003109 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
3113 }
3114
3115 @Override
chen xu0026ca62019-03-06 15:28:50 -08003116 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003120 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
chen xu651eec72018-11-11 19:03:44 -08003126 @Override
chen xu864e11c2018-12-06 22:10:03 -08003127 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3128 if (!isSubscriptionMccMnc) {
3129 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3130 }
chen xu651eec72018-11-11 19:03:44 -08003131 final Phone phone = PhoneFactory.getPhone(slotIndex);
3132 if (phone == null) {
3133 return TelephonyManager.UNKNOWN_CARRIER_ID;
3134 }
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
3141 }
3142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 //
3144 // Internal helper methods.
3145 //
3146
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003147 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3149 *
3150 * @throws SecurityException if the caller does not have the required permission
3151 */
3152 private void enforceModifyPermission() {
3153 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3154 }
3155
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003156 /**
3157 * Make sure the caller is system.
3158 *
3159 * @throws SecurityException if the caller is not system.
3160 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003161 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003162 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3163 throw new SecurityException("Caller must be system");
3164 }
3165 }
3166
Shuo Qianf2b2df42019-11-13 17:43:31 -08003167 private void enforceActiveEmergencySessionPermission() {
3168 mApp.enforceCallingOrSelfPermission(
3169 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3170 }
3171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 /**
3173 * Make sure the caller has the CALL_PHONE permission.
3174 *
3175 * @throws SecurityException if the caller does not have the required permission
3176 */
3177 private void enforceCallPermission() {
3178 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3179 }
3180
paulhu423b5f22019-08-23 19:17:33 +08003181 private void enforceSettingsPermission() {
3182 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003183 }
3184
Michele Berionned9fbae52020-11-13 02:36:59 +00003185 private void enforceRebootPermission() {
3186 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3187 }
3188
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 private String createTelUrl(String number) {
3190 if (TextUtils.isEmpty(number)) {
3191 return null;
3192 }
3193
Jake Hambye994d462014-02-03 13:10:13 -08003194 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Ihab Awadf9e92732013-12-05 18:02:52 -08003197 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3199 }
3200
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003201 private static void logv(String msg) {
3202 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3203 }
3204
Ihab Awadf9e92732013-12-05 18:02:52 -08003205 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3207 }
3208
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003209 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003211 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003212 }
3213
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003215 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 final Phone phone = PhoneFactory.getPhone(slotIndex);
3219 if (phone == null) {
3220 return PhoneConstants.PHONE_TYPE_NONE;
3221 } else {
3222 return phone.getPhoneType();
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003227 }
3228
3229 /**
3230 * Returns the CDMA ERI icon index to display
3231 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003232 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003233 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3234 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3235 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003239 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3240 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003242 mApp, subId, callingPackage, callingFeatureId,
3243 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003244 return -1;
3245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 final Phone phone = getPhone(subId);
3250 if (phone != null) {
3251 return phone.getCdmaEriIconIndex();
3252 } else {
3253 return -1;
3254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 }
3259
3260 /**
3261 * Returns the CDMA ERI icon mode,
3262 * 0 - ON
3263 * 1 - FLASHING
3264 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003265 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003266 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3267 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3268 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003269 }
3270
Sanket Padawe356d7632015-06-22 14:03:32 -07003271 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003272 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3273 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003275 mApp, subId, callingPackage, callingFeatureId,
3276 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003277 return -1;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 final Phone phone = getPhone(subId);
3283 if (phone != null) {
3284 return phone.getCdmaEriIconMode();
3285 } else {
3286 return -1;
3287 }
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291 }
3292
3293 /**
3294 * Returns the CDMA ERI text,
3295 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003296 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003297 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3298 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3299 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003300 }
3301
Sanket Padawe356d7632015-06-22 14:03:32 -07003302 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003303 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3304 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003306 mApp, subId, callingPackage, callingFeatureId,
3307 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003308 return null;
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 final Phone phone = getPhone(subId);
3314 if (phone != null) {
3315 return phone.getCdmaEriText();
3316 } else {
3317 return null;
3318 }
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003322 }
3323
3324 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003325 * Returns the CDMA MDN.
3326 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003327 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003328 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 return phone.getLine1Number();
3337 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003338 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 return null;
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003343 }
3344 }
3345
3346 /**
3347 * Returns the CDMA MIN.
3348 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003350 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 final Phone phone = getPhone(subId);
3357 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3358 return phone.getCdmaMin();
3359 } else {
3360 return null;
3361 }
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003364 }
3365 }
3366
Hall Liud892bec2018-11-30 14:51:45 -08003367 @Override
3368 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3369 INumberVerificationCallback callback, String callingPackage) {
3370 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3371 != PERMISSION_GRANTED) {
3372 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3373 }
3374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3375
3376 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3377 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003378 throw new SecurityException("Calling package must be configured in the device config: "
3379 + "calling package: " + callingPackage
3380 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003381 }
3382
3383 if (range == null) {
3384 throw new NullPointerException("Range must be non-null");
3385 }
3386
3387 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003388 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003389
3390 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3391 }
3392
Junda Liuca05d5d2014-08-14 22:36:34 -07003393 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 * Returns true if CDMA provisioning needs to run.
3395 */
3396 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
3404
3405 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003406 * Sets the voice mail number of a given subId.
3407 */
3408 @Override
3409 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003410 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3411 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3416 new Pair<String, String>(alphaTag, number), new Integer(subId));
3417 return success;
3418 } finally {
3419 Binder.restoreCallingIdentity(identity);
3420 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003421 }
3422
Ta-wei Yen87c49842016-05-13 21:19:52 -07003423 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003424 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3425 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003426 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3427 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003428 if (!TextUtils.equals(callingPackage, systemDialer)) {
3429 throw new SecurityException("caller must be system dialer");
3430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003431
3432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3435 if (phoneAccountHandle == null) {
3436 return null;
3437 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003441 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003442 }
3443
3444 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003445 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3446 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003449 mApp, subId, callingPackage, callingFeatureId,
3450 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003451 return null;
3452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003454 final long identity = Binder.clearCallingIdentity();
3455 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003456 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003457 } finally {
3458 Binder.restoreCallingIdentity(identity);
3459 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003460 }
3461
3462 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003463 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3464 VisualVoicemailSmsFilterSettings settings) {
3465 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003470 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471 } finally {
3472 Binder.restoreCallingIdentity(identity);
3473 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003474 }
3475
3476 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003477 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003483 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003487 }
3488
3489 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003490 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3491 String callingPackage, int subId) {
3492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003497 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498 } finally {
3499 Binder.restoreCallingIdentity(identity);
3500 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003501 }
3502
3503 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003504 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003510 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003514 }
3515
3516 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003517 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3518 String callingAttributionTag, int subId, String number, int port, String text,
3519 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003521 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003522 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003523 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003524 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3525 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003526 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003527
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003528 /**
fionaxu0152e512016-11-14 13:36:14 -08003529 * Sets the voice activation state of a given subId.
3530 */
3531 @Override
3532 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3534 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 final Phone phone = getPhone(subId);
3539 if (phone != null) {
3540 phone.setVoiceActivationState(activationState);
3541 } else {
3542 loge("setVoiceActivationState fails with invalid subId: " + subId);
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003546 }
3547 }
3548
3549 /**
3550 * Sets the data activation state of a given subId.
3551 */
3552 @Override
3553 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3555 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = getPhone(subId);
3560 if (phone != null) {
3561 phone.setDataActivationState(activationState);
3562 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003563 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003567 }
3568 }
3569
3570 /**
3571 * Returns the voice activation state of a given subId.
3572 */
3573 @Override
3574 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
fionaxu0152e512016-11-14 13:36:14 -08003577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 if (phone != null) {
3581 return phone.getVoiceActivationState();
3582 } else {
3583 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003587 }
3588 }
3589
3590 /**
3591 * Returns the data activation state of a given subId.
3592 */
3593 @Override
3594 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
fionaxu0152e512016-11-14 13:36:14 -08003597 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 if (phone != null) {
3601 return phone.getDataActivationState();
3602 } else {
3603 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3604 }
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003607 }
3608 }
3609
3610 /**
Wink Saville36469e72014-06-11 15:17:00 -07003611 * Returns the unread count of voicemails for a subId
3612 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003613 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003614 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3615 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003617 mApp, subId, callingPackage, callingFeatureId,
3618 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003619 return 0;
3620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 final Phone phone = getPhone(subId);
3624 if (phone != null) {
3625 return phone.getVoiceMessageCount();
3626 } else {
3627 return 0;
3628 }
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 }
3633
3634 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003635 * returns true, if the device is in a state where both voice and data
3636 * are supported simultaneously. This can change based on location or network condition.
3637 */
3638 @Override
3639 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 final Phone phone = getPhone(subId);
3643 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003647 }
3648
3649 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003650 * Send the dialer code if called from the current default dialer or the caller has
3651 * carrier privilege.
3652 * @param inputCode The dialer code to send
3653 */
3654 @Override
3655 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003658 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3659 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003660 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003661 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
fionaxu235cc5e2017-03-06 22:25:57 -08003671 }
3672
Pengquan Menga1bb6272018-09-06 09:59:22 -07003673 @Override
3674 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003675 TelephonyPermissions
3676 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3677 mApp, subId, "getNetworkSelectionMode");
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 if (!isActiveSubscription(subId)) {
3681 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3682 }
3683 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003687 }
3688
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003690 public boolean isInEmergencySmsMode() {
3691 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 for (Phone phone : PhoneFactory.getPhones()) {
3695 if (phone.isInEmergencySmsMode()) {
3696 return true;
3697 }
3698 }
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 return false;
3703 }
3704
shilu366312e2019-12-17 09:28:10 -08003705 /**
3706 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3707 * @param subId The subscription to use to check the configuration.
3708 * @param c The callback that will be used to send the result.
3709 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003710 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003711 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3712 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003713 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3714 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003715
Brad Ebinger77b832e2019-10-17 17:03:22 -07003716 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3718 "IMS not available on device.");
3719 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 final long token = Binder.clearCallingIdentity();
3721 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(token);
3729 }
3730 }
3731
shilu366312e2019-12-17 09:28:10 -08003732 /**
3733 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3734 * @param subId The subscription to use to check the configuration.
3735 * @param c The callback that will be used to send the result.
3736 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003738 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003739 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3740 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3742 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3743 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003744 final long token = Binder.clearCallingIdentity();
3745 try {
3746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3747 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3748 .removeRegistrationCallbackForSubscription(c, subId);
3749 } catch (ImsException e) {
3750 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3751 + "is inactive, ignoring unregister.");
3752 // If the subscription is no longer active, just return, since the callback
3753 // will already have been removed internally.
3754 } finally {
3755 Binder.restoreCallingIdentity(token);
3756 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 }
3758
Brad Ebinger774ba362019-10-22 17:36:18 -07003759 /**
3760 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3761 */
3762 @Override
3763 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3764 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3765 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3766 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3767 "IMS not available on device.");
3768 }
3769 final long token = Binder.clearCallingIdentity();
3770 try {
3771 Phone phone = getPhone(subId);
3772 if (phone == null) {
3773 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3774 + subId + "'");
3775 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3776 }
3777 phone.getImsRegistrationState(regState -> {
3778 try {
3779 consumer.accept((regState == null)
3780 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3781 } catch (RemoteException e) {
3782 // Ignore if the remote process is no longer available to call back.
3783 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3784 }
3785 });
3786 } finally {
3787 Binder.restoreCallingIdentity(token);
3788 }
3789 }
3790
3791 /**
3792 * Get the transport type for the IMS service registration state.
3793 */
3794 @Override
3795 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003796 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3797 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003798 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3799 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3800 "IMS not available on device.");
3801 }
3802 final long token = Binder.clearCallingIdentity();
3803 try {
3804 Phone phone = getPhone(subId);
3805 if (phone == null) {
3806 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3807 + subId + "'");
3808 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3809 }
3810 phone.getImsRegistrationTech(regTech -> {
3811 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3812 int regTechConverted = (regTech == null)
3813 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3814 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3815 regTechConverted);
3816 try {
3817 consumer.accept(regTechConverted);
3818 } catch (RemoteException e) {
3819 // Ignore if the remote process is no longer available to call back.
3820 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3821 }
3822 });
3823 } finally {
3824 Binder.restoreCallingIdentity(token);
3825 }
3826 }
3827
shilu366312e2019-12-17 09:28:10 -08003828 /**
3829 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3830 * @param subId The subscription to use to check the configuration.
3831 * @param c The callback that will be used to send the result.
3832 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003834 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3835 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003836 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3837 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003838 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3839 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3840 "IMS not available on device.");
3841 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3843 final long token = Binder.clearCallingIdentity();
3844 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003845 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003847 } catch (ImsException e) {
3848 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 } finally {
3850 Binder.restoreCallingIdentity(token);
3851 }
3852 }
3853
shilu366312e2019-12-17 09:28:10 -08003854 /**
3855 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3856 * @param subId The subscription to use to check the configuration.
3857 * @param c The callback that will be used to send the result.
3858 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003860 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003861 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3862 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3864 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3865 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003866
3867 final long token = Binder.clearCallingIdentity();
3868 try {
3869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003871 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003872 } catch (ImsException e) {
3873 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3874 + "is inactive, ignoring unregister.");
3875 // If the subscription is no longer active, just return, since the callback
3876 // will already have been removed internally.
3877 } finally {
3878 Binder.restoreCallingIdentity(token);
3879 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 }
3881
3882 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003883 public boolean isCapable(int subId, int capability, int regTech) {
3884 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3886 final long token = Binder.clearCallingIdentity();
3887 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003890 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3892 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003893 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003894 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3895 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 } finally {
3897 Binder.restoreCallingIdentity(token);
3898 }
3899 }
3900
3901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003902 public boolean isAvailable(int subId, int capability, int regTech) {
3903 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 final long token = Binder.clearCallingIdentity();
3905 try {
3906 Phone phone = getPhone(subId);
3907 if (phone == null) return false;
3908 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003909 } catch (com.android.ims.ImsException e) {
3910 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3911 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 } finally {
3913 Binder.restoreCallingIdentity(token);
3914 }
3915 }
3916
Brad Ebinger77b832e2019-10-17 17:03:22 -07003917 /**
3918 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3919 * subscription.
3920 * @param subId The subscription to use to check the configuration.
3921 * @param callback The callback that will be used to send the result.
3922 * @param capability The MmTelFeature capability that will be used to send the result.
3923 * @param transportType The transport type of the MmTelFeature capability.
3924 */
3925 @Override
3926 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3927 int transportType) {
3928 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3929 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3931 "IMS not available on device.");
3932 }
3933 final long token = Binder.clearCallingIdentity();
3934 try {
3935 int slotId = getSlotIndex(subId);
3936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3937 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3938 + subId + "'");
3939 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3940 }
3941 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3942 transportType, aBoolean -> {
3943 try {
3944 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3945 } catch (RemoteException e) {
3946 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3947 + "running. Ignore");
3948 }
3949 });
3950 } finally {
3951 Binder.restoreCallingIdentity(token);
3952 }
3953 }
3954
shilu366312e2019-12-17 09:28:10 -08003955 /**
3956 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3957 * @param subId The subscription to use to check the configuration.
3958 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 @Override
3960 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003961 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3962 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003963
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3965 final long token = Binder.clearCallingIdentity();
3966 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003969 } catch (ImsException e) {
3970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 } finally {
3972 Binder.restoreCallingIdentity(token);
3973 }
3974 }
3975
3976 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003977 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003979 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003985 } catch (ImsException e) {
3986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
3990 }
3991
shilu366312e2019-12-17 09:28:10 -08003992 /**
3993 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3994 * @param subId The subscription to use to check the configuration.
3995 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003997 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003998 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3999 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004003 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4004 } catch (ImsException e) {
4005 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
4009 }
4010
4011 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004012 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004014 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004019 } catch (ImsException e) {
4020 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
4024 }
4025
shilu366312e2019-12-17 09:28:10 -08004026 /**
4027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4028 * @param subId The subscription to use to check the configuration.
4029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 @Override
4031 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004032 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4033 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004037 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
4044 }
4045
4046 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004047 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004049 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004053 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004054 } catch (ImsException e) {
4055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
4059 }
4060
shilu366312e2019-12-17 09:28:10 -08004061 /**
4062 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4063 * @param subId The subscription to use to check the configuration.
4064 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 @Override
4066 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004067 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4068 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004074 } catch (ImsException e) {
4075 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
4079 }
4080
4081 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004082 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004084 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004088 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004090 } catch (ImsException e) {
4091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
4095 }
4096
4097 @Override
4098 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4100 "setVoWiFiNonPersistent");
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004105 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004106 } catch (ImsException e) {
4107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112
shilu366312e2019-12-17 09:28:10 -08004113 /**
4114 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4115 * @param subId The subscription to use to check the configuration.
4116 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 @Override
4118 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004119 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4120 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004124 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 } catch (ImsException e) {
4127 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
4131 }
4132
4133 @Override
4134 public void setVoWiFiModeSetting(int subId, int mode) {
4135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4136 "setVoWiFiModeSetting");
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
4150 public int getVoWiFiRoamingModeSetting(int subId) {
4151 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004155 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004157 } catch (ImsException e) {
4158 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 }
4163
4164 @Override
4165 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4167 "setVoWiFiRoamingModeSetting");
4168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004171 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004172 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004173 } catch (ImsException e) {
4174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
4178 }
4179
4180 @Override
4181 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4183 "setRttCapabilityEnabled");
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4188 } catch (ImsException e) {
4189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
4193 }
4194
shilu366312e2019-12-17 09:28:10 -08004195 /**
4196 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4197 * @param subId The subscription to use to check the configuration.
4198 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 @Override
4200 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004201 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4202 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004206 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (ImsException e) {
4209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
4213 }
4214
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004215 @Override
4216 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4217 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004220 if (!isImsAvailableOnDevice()) {
4221 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4222 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004223 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004226 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
4232 }
4233
4234 @Override
4235 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4236 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4237 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004238 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4239 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4240 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004241 try {
4242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004243 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004244 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004245 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004246 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4247 + "is inactive, ignoring unregister.");
4248 // If the subscription is no longer active, just return, since the callback will already
4249 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
allenwtsu99c623b2020-01-03 18:24:23 +08004255
4256 private void checkModifyPhoneStatePermission(int subId, String message) {
4257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4258 message);
4259 }
4260
4261 private boolean isImsProvisioningRequired(int subId, int capability,
4262 boolean isMmtelCapability) {
4263 Phone phone = getPhone(subId);
4264 if (phone == null) {
4265 loge("phone instance null for subid " + subId);
4266 return false;
4267 }
4268 if (isMmtelCapability) {
4269 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4270 return false;
4271 }
4272 } else {
4273 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4274 return false;
4275 }
4276 }
4277 return true;
4278 }
4279
4280 @Override
4281 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4282 boolean isProvisioned) {
4283 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4284
4285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4288 if (!isImsProvisioningRequired(subId, capability, false)) {
4289 return;
4290 }
4291
4292 // this capability requires provisioning, route to the correct API.
4293 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4294 switch (capability) {
4295 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4296 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4297 ims.setEabProvisioned(isProvisioned);
4298 break;
4299 default: {
4300 throw new IllegalArgumentException("Tried to set provisioning for "
4301 + "rcs capability '" + capability + "', which does not require "
4302 + "provisioning.");
4303 }
4304 }
4305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308
4309 }
4310
4311
4312 @Override
4313 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4314 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4318 if (!isImsProvisioningRequired(subId, capability, false)) {
4319 return true;
4320 }
4321
4322 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4323 switch (capability) {
4324 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4325 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4326 return ims.isEabProvisionedOnDevice();
4327
4328 default: {
4329 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4330 + "capability '" + capability + "', which does not require "
4331 + "provisioning.");
4332 }
4333 }
4334
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
4338 }
4339
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004340 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4342 boolean isProvisioned) {
4343 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4344 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4345 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4346 }
allenwtsu99c623b2020-01-03 18:24:23 +08004347 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004351 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004352 return;
4353 }
4354
4355 // this capability requires provisioning, route to the correct API.
4356 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4357 switch (capability) {
4358 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4359 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4360 ims.setVolteProvisioned(isProvisioned);
4361 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4362 ims.setWfcProvisioned(isProvisioned);
4363 }
4364 break;
4365 }
4366 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4367 // There is currently no difference in VT provisioning type.
4368 ims.setVtProvisioned(isProvisioned);
4369 break;
4370 }
4371 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4372 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4373 // change the capability of the feature instead if needed.
4374 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4375 == isProvisioned) {
4376 // No change in provisioning.
4377 return;
4378 }
4379 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4380 try {
4381 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004382 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004383 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4384 + ", Exception" + e.getMessage());
4385 }
4386 break;
4387 }
4388 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004389 throw new IllegalArgumentException("Tried to set provisioning for "
4390 + "MmTel capability '" + capability + "', which does not require "
4391 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004392 }
4393 }
4394
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
4398 }
4399
4400 @Override
4401 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4402 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4403 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4404 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4405 }
4406 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004410 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004411 return true;
4412 }
4413
4414 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4415 switch (capability) {
4416 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4417 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4418 return ims.isVolteProvisionedOnDevice();
4419 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4420 return ims.isWfcProvisionedOnDevice();
4421 }
4422 // This should never happen, since we are checking tech above to make sure it
4423 // is either LTE or IWLAN.
4424 throw new IllegalArgumentException("Invalid radio technology for voice "
4425 + "capability.");
4426 }
4427 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4428 // There is currently no difference in VT provisioning type.
4429 return ims.isVtProvisionedOnDevice();
4430 }
4431 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4432 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4433 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4434 }
4435 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004436 throw new IllegalArgumentException(
4437 "Tried to get provisioning for MmTel capability '" + capability
4438 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004439 }
4440 }
4441
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
4445 }
4446
4447 @Override
4448 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4449 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4450 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4451 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4452 }
4453 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4454 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4455 return (provisionedBits & capability) > 0;
4456 }
4457
4458 @Override
4459 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4460 boolean isProvisioned) {
4461 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4462 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4463 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4464 }
4465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4466 "setProvisioningStatusForCapability");
4467 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4468 // If the current provisioning status for capability already matches isProvisioned,
4469 // do nothing.
4470 if (((provisionedBits & capability) > 0) == isProvisioned) {
4471 return;
4472 }
4473 if (isProvisioned) {
4474 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4475 } else {
4476 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4477 }
4478 }
4479
4480 /**
4481 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4482 * technology. The bitfield should mirror the bitfield defined by
4483 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4484 */
4485 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4486 String key = getMmTelProvisioningKey(subId, tech);
4487 // Default is no capabilities are provisioned.
4488 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4489 }
4490
4491 /**
4492 * Sets the MmTel capability provisioning bitfield (defined by
4493 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4494 * technology specified.
4495 *
4496 * Note: This is a synchronous command and should not be called on UI thread.
4497 */
4498 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4499 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4500 String key = getMmTelProvisioningKey(subId, tech);
4501 editor.putInt(key, newField);
4502 editor.commit();
4503 }
4504
4505 private static String getMmTelProvisioningKey(int subId, int tech) {
4506 // resulting key is provision_ims_mmtel_{subId}_{tech}
4507 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4508 }
4509
4510 /**
4511 * Query CarrierConfig to see if the specified capability requires provisioning for the
4512 * carrier associated with the subscription id.
4513 */
4514 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4515 int capability) {
4516 CarrierConfigManager configManager = new CarrierConfigManager(context);
4517 PersistableBundle c = configManager.getConfigForSubId(subId);
4518 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004519 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4521 false);
4522 boolean requireVoiceVtProvisioning = c.getBoolean(
4523 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4524
4525 // First check to make sure that the capability requires provisioning.
4526 switch (capability) {
4527 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4528 // intentional fallthrough
4529 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4530 if (requireVoiceVtProvisioning) {
4531 // Voice and Video requires provisioning
4532 return true;
4533 }
4534 break;
4535 }
4536 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4537 if (requireUtProvisioning) {
4538 // UT requires provisioning
4539 return true;
4540 }
4541 break;
4542 }
4543 }
4544 return false;
4545 }
4546
allenwtsu99c623b2020-01-03 18:24:23 +08004547 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4548 int capability) {
4549 CarrierConfigManager configManager = new CarrierConfigManager(context);
4550 PersistableBundle c = configManager.getConfigForSubId(subId);
4551
4552 boolean requireRcsProvisioning = c.getBoolean(
4553 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4554
4555 // First check to make sure that the capability requires provisioning.
4556 switch (capability) {
4557 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4558 // intentional fallthrough
4559 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4560 if (requireRcsProvisioning) {
4561 // OPTION or PRESENCE requires provisioning
4562 return true;
4563 }
4564 break;
4565 }
4566 }
4567 return false;
4568 }
4569
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004570 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004571 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4573 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4574 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004575 enforceReadPrivilegedPermission("getImsProvisioningInt");
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004579 int slotId = getSlotIndex(subId);
4580 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4581 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4582 + subId + "' for key:" + key);
4583 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4584 }
4585 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004586 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4588 + subId + "' for key:" + key);
4589 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
4593 }
4594
4595 @Override
4596 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4598 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4599 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 enforceReadPrivilegedPermission("getImsProvisioningString");
4601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004604 int slotId = getSlotIndex(subId);
4605 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4606 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4607 + subId + "' for key:" + key);
4608 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4609 }
4610 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004611 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004612 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4613 + subId + "' for key:" + key);
4614 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
4618 }
4619
4620 @Override
4621 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004622 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4623 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4624 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4626 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004627 final long identity = Binder.clearCallingIdentity();
4628 try {
4629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004630 int slotId = getSlotIndex(subId);
4631 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4632 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4633 + subId + "' for key:" + key);
4634 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4635 }
4636 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004637 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4639 + "' for key:" + key);
4640 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644 }
4645
4646 @Override
4647 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4649 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4650 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4652 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 int slotId = getSlotIndex(subId);
4657 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4658 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4659 + subId + "' for key:" + key);
4660 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4661 }
4662 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004663 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4665 + "' for key:" + key);
4666 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
4670 }
4671
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004672 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 int slotId = SubscriptionManager.getSlotIndex(subId);
4674 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004675 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4676 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004677 }
4678 return slotId;
4679 }
4680
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004681 private int getSlotIndex(int subId) {
4682 int slotId = SubscriptionManager.getSlotIndex(subId);
4683 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4684 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4685 }
4686 return slotId;
4687 }
4688
Wink Saville36469e72014-06-11 15:17:00 -07004689 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004690 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004691 */
4692 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004693 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4694 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004695 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004696 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004697 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004698 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004699 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004700 mApp, subId, callingPackage, callingFeatureId,
4701 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4703 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 final Phone phone = getPhone(subId);
4708 if (phone != null) {
4709 return phone.getServiceState().getDataNetworkType();
4710 } else {
4711 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004716 }
4717
4718 /**
4719 * Returns the data network type
4720 */
4721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004722 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4723 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4724 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004725 }
4726
4727 /**
4728 * Returns the data network type for a subId
4729 */
4730 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004731 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4732 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004734 mApp, subId, callingPackage, callingFeatureId,
4735 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004736 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4737 }
4738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 final Phone phone = getPhone(subId);
4742 if (phone != null) {
4743 return phone.getServiceState().getDataNetworkType();
4744 } else {
4745 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4746 }
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004750 }
4751
4752 /**
Wink Saville36469e72014-06-11 15:17:00 -07004753 * Returns the Voice network type for a subId
4754 */
4755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004756 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4757 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004759 mApp, subId, callingPackage, callingFeatureId,
4760 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004761 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4762 }
4763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 final Phone phone = getPhone(subId);
4767 if (phone != null) {
4768 return phone.getServiceState().getVoiceNetworkType();
4769 } else {
4770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4771 }
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004775 }
4776
4777 /**
4778 * @return true if a ICC card is present
4779 */
4780 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004781 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004782 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4783 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004784 }
4785
4786 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004787 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004788 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004789 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004790 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 final Phone phone = PhoneFactory.getPhone(slotIndex);
4794 if (phone != null) {
4795 return phone.getIccCard().hasIccCard();
4796 } else {
4797 return false;
4798 }
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004802 }
4803
4804 /**
4805 * Return if the current radio is LTE on CDMA. This
4806 * is a tri-state return value as for a period of time
4807 * the mode may be unknown.
4808 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004809 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004810 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004811 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004812 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004813 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004814 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4815 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4816 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004817 }
4818
Sanket Padawe356d7632015-06-22 14:03:32 -07004819 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004820 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4821 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004822 try {
4823 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4824 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004825 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4826 }
4827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 final Phone phone = getPhone(subId);
4831 if (phone == null) {
4832 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4833 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004834 return TelephonyProperties.lte_on_cdma_device()
4835 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 }
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004839 }
Wink Saville36469e72014-06-11 15:17:00 -07004840 }
4841
Wink Saville36469e72014-06-11 15:17:00 -07004842 /**
4843 * {@hide}
4844 * Returns Default subId, 0 in the case of single standby.
4845 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004846 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004847 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004848 }
4849
Shishir Agrawala9f32182016-04-12 12:00:16 -07004850 private int getSlotForDefaultSubscription() {
4851 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4852 }
4853
Wink Savilleb564aae2014-10-23 10:18:09 -07004854 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004855 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004856 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004857
Pengquan Menge92a50d2018-09-21 15:54:48 -07004858 private boolean isActiveSubscription(int subId) {
4859 return mSubscriptionController.isActiveSubId(subId);
4860 }
4861
Ihab Awadf2177b72013-11-25 13:33:23 -08004862 /**
4863 * @see android.telephony.TelephonyManager.WifiCallingChoices
4864 */
4865 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 final long identity = Binder.clearCallingIdentity();
4867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004868 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4870 getWhenToMakeWifiCallsDefaultPreference());
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004874 }
4875
4876 /**
4877 * @see android.telephony.TelephonyManager.WifiCallingChoices
4878 */
4879 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004888 }
4889
Sailesh Nepald1e68152013-12-12 19:08:02 -08004890 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004891 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004892 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004893 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004894
Jordan Liu4c733742019-02-28 12:03:40 -08004895 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4896 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4897 if (phoneId == -1) {
4898 throw new IllegalArgumentException("Given slot index: " + slotIndex
4899 + " does not correspond to an active phone");
4900 }
4901 return PhoneFactory.getPhone(phoneId);
4902 }
4903
Shishir Agrawal566b7612013-10-28 14:41:00 -07004904 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004905 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4906 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4908 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004910 if (DBG) {
4911 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4912 }
4913 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4914 p2);
4915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004916
Jordan Liu4c733742019-02-28 12:03:40 -08004917
4918 @Override
4919 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4920 int slotIndex, String callingPackage, String aid, int p2) {
4921 enforceModifyPermission();
4922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4923 if (DBG) {
4924 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4925 }
4926 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4927 callingPackage, aid, p2);
4928 }
4929
4930 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4931 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 if (TextUtils.equals(ISDR_AID, aid)) {
4935 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4937 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 if (bestComponent == null
4939 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4940 loge("The calling package is not allowed to access ISD-R.");
4941 throw new SecurityException(
4942 "The calling package is not allowed to access ISD-R.");
4943 }
Derek Tan740e1672017-06-27 14:56:27 -07004944 }
Derek Tan740e1672017-06-27 14:56:27 -07004945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004947 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4948 null /* workSource */);
4949 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 return response;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004954 }
4955
4956 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004957 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4959 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004960 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4961 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4962 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004963
Jordan Liu4c733742019-02-28 12:03:40 -08004964 @Override
4965 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4966 enforceModifyPermission();
4967 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4968 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4969 channel);
4970 }
4971
4972 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 final long identity = Binder.clearCallingIdentity();
4974 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 if (channel < 0) {
4976 return false;
4977 }
Jordan Liu4c733742019-02-28 12:03:40 -08004978 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4979 null /* workSource */);
4980 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981 return success;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985 }
4986
4987 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004988 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004989 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4991 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004992 if (DBG) {
4993 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4994 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4995 + p3 + " data=" + data);
4996 }
4997 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4998 command, p1, p2, p3, data);
4999 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005000
Jordan Liu4c733742019-02-28 12:03:40 -08005001 @Override
5002 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5003 int command, int p1, int p2, int p3, String data) {
5004 enforceModifyPermission();
5005 if (DBG) {
5006 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5007 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5008 + p3 + " data=" + data);
5009 }
5010 return iccTransmitApduLogicalChannelWithPermission(
5011 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5012 data);
5013 }
5014
5015 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5016 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 final long identity = Binder.clearCallingIdentity();
5018 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005019 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 return "";
5021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005024 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5025 null /* workSource */);
5026 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 // Append the returned status code to the end of the response payload.
5029 String s = Integer.toHexString(
5030 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5031 if (response.payload != null) {
5032 s = IccUtils.bytesToHexString(response.payload) + s;
5033 }
5034 return s;
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005038 }
Jake Hambye994d462014-02-03 13:10:13 -08005039
Evan Charltonc66da362014-05-16 14:06:40 -07005040 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005041 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5042 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5044 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005046 if (DBG) {
5047 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5048 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5049 }
5050 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5051 cla, command, p1, p2, p3, data);
5052 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005053
Jordan Liu4c733742019-02-28 12:03:40 -08005054 @Override
5055 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5056 int command, int p1, int p2, int p3, String data) {
5057 enforceModifyPermission();
5058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5059 if (DBG) {
5060 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5061 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5062 + " data=" + data);
5063 }
5064
5065 return iccTransmitApduBasicChannelWithPermission(
5066 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5067 p2, p3, data);
5068 }
5069
5070 // open APDU basic channel assuming the caller has sufficient permissions
5071 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5072 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5076 && TextUtils.equals(ISDR_AID, data)) {
5077 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005078 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5079 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 if (bestComponent == null
5081 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5082 loge("The calling package is not allowed to select ISD-R.");
5083 throw new SecurityException(
5084 "The calling package is not allowed to select ISD-R.");
5085 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005086 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005089 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5090 null /* workSource */);
5091 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 // Append the returned status code to the end of the response payload.
5094 String s = Integer.toHexString(
5095 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5096 if (response.payload != null) {
5097 s = IccUtils.bytesToHexString(response.payload) + s;
5098 }
5099 return s;
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005102 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005103 }
5104
5105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005106 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005107 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5109 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 if (DBG) {
5114 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5115 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5116 }
5117
5118 IccIoResult response =
5119 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5120 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5121 subId);
5122
5123 if (DBG) {
5124 log("Exchange SIM_IO [R]" + response);
5125 }
5126
5127 byte[] result = null;
5128 int length = 2;
5129 if (response.payload != null) {
5130 length = 2 + response.payload.length;
5131 result = new byte[length];
5132 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5133 } else {
5134 result = new byte[length];
5135 }
5136
5137 result[length - 1] = (byte) response.sw2;
5138 result[length - 2] = (byte) response.sw1;
5139 return result;
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005142 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005143 }
5144
Nathan Haroldb3014052017-01-25 15:57:32 -08005145 /**
5146 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5147 * on a particular subscription
5148 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005149 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5150 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005152 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005153 return null;
5154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155
5156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 if (appType != TelephonyManager.APPTYPE_USIM
5159 && appType != TelephonyManager.APPTYPE_SIM) {
5160 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5161 return null;
5162 }
5163 Object response = sendRequest(
5164 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5165 if (response instanceof String[]) {
5166 return (String[]) response;
5167 }
yincheng zhaod698b842019-09-06 17:06:54 -07005168 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005170 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005173 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005174 }
5175
yincheng zhaod698b842019-09-06 17:06:54 -07005176 /**
5177 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5178 * subscription.
5179 *
5180 * @param subId the id of the subscription.
5181 * @param appType the uicc app type, must be USIM or SIM.
5182 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5183 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005184 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005185 * @return number of fplmns that is successfully written to the SIM.
5186 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005187 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5188 String callingFeatureId) {
5189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5190 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005191 if (DBG) logv("no permissions for setForbiddenplmns");
5192 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5193 }
5194 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5195 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5196 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5197 }
5198 if (fplmns == null) {
5199 throw new IllegalArgumentException("Fplmn List provided is null");
5200 }
5201 for (String fplmn : fplmns) {
5202 if (!CellIdentity.isValidPlmn(fplmn)) {
5203 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5204 }
5205 }
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
5208 Object response = sendRequest(
5209 CMD_SET_FORBIDDEN_PLMNS,
5210 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5211 subId);
5212 return (int) response;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005219 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5221 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5226 if (response.payload == null) {
5227 return "";
5228 }
Evan Charltonc66da362014-05-16 14:06:40 -07005229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 // Append the returned status code to the end of the response payload.
5231 String s = Integer.toHexString(
5232 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5233 s = IccUtils.bytesToHexString(response.payload) + s;
5234 return s;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Evan Charltonc66da362014-05-16 14:06:40 -07005238 }
5239
Jake Hambye994d462014-02-03 13:10:13 -08005240 /**
5241 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5242 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5243 *
5244 * @param itemID the ID of the item to read
5245 * @return the NV item as a String, or null on error.
5246 */
5247 @Override
5248 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005256 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5258 return value;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Jake Hambye994d462014-02-03 13:10:13 -08005262 }
5263
5264 /**
5265 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5266 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5267 *
5268 * @param itemID the ID of the item to read
5269 * @param itemValue the value to write, as a String
5270 * @return true on success; false on any failure
5271 */
5272 @Override
5273 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5281 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005282 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5284 return success;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Jake Hambye994d462014-02-03 13:10:13 -08005288 }
5289
5290 /**
5291 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5292 * Used for device configuration by some CDMA operators.
5293 *
5294 * @param preferredRoamingList byte array containing the new PRL
5295 * @return true on success; false on any failure
5296 */
5297 @Override
5298 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5305 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5306 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5307 return success;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
Jake Hambye994d462014-02-03 13:10:13 -08005311 }
5312
5313 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005314 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005315 * Used for device configuration by some CDMA operators.
5316 *
chen xu6dac5ab2018-10-26 17:39:23 -07005317 * @param slotIndex - device slot.
5318 *
Jake Hambye994d462014-02-03 13:10:13 -08005319 * @return true on success; false on any failure
5320 */
5321 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005322 public boolean resetModemConfig(int slotIndex) {
5323 Phone phone = PhoneFactory.getPhone(slotIndex);
5324 if (phone != null) {
5325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5326 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327
chen xu6dac5ab2018-10-26 17:39:23 -07005328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5331 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5332 return success;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 }
chen xu6dac5ab2018-10-26 17:39:23 -07005337 return false;
5338 }
5339
5340 /**
5341 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5342 *
5343 * @param slotIndex - device slot.
5344 *
5345 * @return true on success; false on any failure
5346 */
5347 @Override
5348 public boolean rebootModem(int slotIndex) {
5349 Phone phone = PhoneFactory.getPhone(slotIndex);
5350 if (phone != null) {
5351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5352 mApp, phone.getSubId(), "rebootModem");
5353
5354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5357 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5358 return success;
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
5362 }
5363 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005364 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005365
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005366 public String[] getPcscfAddress(String apnType, String callingPackage,
5367 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005368 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5370 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005371 return new String[0];
5372 }
5373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005376 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
Wink Saville36469e72014-06-11 15:17:00 -07005380 }
5381
Brad Ebinger51f743a2017-01-23 13:50:20 -08005382 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005383 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5384 * {@link #disableIms(int)}.
5385 * @param slotIndex device slot.
5386 */
5387 public void resetIms(int slotIndex) {
5388 enforceModifyPermission();
5389
5390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 if (mImsResolver == null) {
5393 // may happen if the does not support IMS.
5394 return;
5395 }
5396 mImsResolver.disableIms(slotIndex);
5397 mImsResolver.enableIms(slotIndex);
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
5401 }
5402
5403 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005404 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5405 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005406 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005407 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005408 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409
5410 final long identity = Binder.clearCallingIdentity();
5411 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005412 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005413 // may happen if the device does not support IMS.
5414 return;
5415 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005416 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005420 }
5421
5422 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005423 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5424 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005425 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005426 public void disableIms(int slotId) {
5427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005431 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005432 // may happen if the device does not support IMS.
5433 return;
5434 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005435 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005439 }
5440
5441 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005442 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5443 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005444 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005445 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005446 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005447 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448
5449 final long identity = Binder.clearCallingIdentity();
5450 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005451 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005452 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5453 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005454 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005455 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005459 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005460 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005461 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5462 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005463 @Override
5464 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005465 enforceModifyPermission();
5466
5467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005470 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
5474 }
5475
5476 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005477 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005478 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005479 */
5480 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005485 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005486 // may happen if the device does not support IMS.
5487 return null;
5488 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005489 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 } finally {
5491 Binder.restoreCallingIdentity(identity);
5492 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005493 }
5494
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005495 /**
5496 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005497 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005498 */
5499 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005504 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005505 // may happen if the device does not support IMS.
5506 return null;
5507 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005508 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005512 }
5513
Brad Ebinger884c07b2018-02-15 16:17:40 -08005514 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005515 * Sets the ImsService Package Name that Telephony will bind to.
5516 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005517 * @param slotIndex the slot ID that the ImsService should bind for.
5518 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005519 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005520 * @param featureTypes An integer array of feature types associated with a packageName.
5521 * @param packageName The name of the package that the current configuration will be replaced
5522 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005523 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005524 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5526 int[] featureTypes, String packageName) {
5527 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5528 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5530 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005531 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 final long identity = Binder.clearCallingIdentity();
5534 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005535 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005536 // may happen if the device does not support IMS.
5537 return false;
5538 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005539 Map<Integer, String> featureConfig = new HashMap<>();
5540 for (int featureType : featureTypes) {
5541 featureConfig.put(featureType, packageName);
5542 }
5543 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5544 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005548 }
5549
5550 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005551 * Clears any carrier ImsService overrides for the slot index specified that were previously
5552 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5553 *
5554 * This should only be used for testing.
5555 *
5556 * @param slotIndex the slot ID that the ImsService should bind for.
5557 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5558 */
5559 @Override
5560 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5561 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5562 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5563 "clearCarrierImsServiceOverride");
5564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5565 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5566 "clearCarrierImsServiceOverride");
5567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 if (mImsResolver == null) {
5571 // may happen if the device does not support IMS.
5572 return false;
5573 }
5574 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
5578 }
5579
5580 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005581 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005582 *
5583 * @param slotId The slot that the ImsService is associated with.
5584 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5585 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005586 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005587 * @return the package name of the ImsService configuration.
5588 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005589 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5590 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005591 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005592 TelephonyPermissions
5593 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5594 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5595 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 final long identity = Binder.clearCallingIdentity();
5598 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005600 // may happen if the device does not support IMS.
5601 return "";
5602 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005603 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005604 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5605 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005609 }
5610
Brad Ebinger77b832e2019-10-17 17:03:22 -07005611 /**
5612 * Get the MmTelFeature state associated with the requested subscription id.
5613 * @param subId The subscription that the MmTelFeature is associated with.
5614 * @param callback A callback with an integer containing the
5615 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5616 */
5617 @Override
5618 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5619 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5620 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5621 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5622 "IMS not available on device.");
5623 }
5624 final long token = Binder.clearCallingIdentity();
5625 try {
5626 int slotId = getSlotIndex(subId);
5627 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5628 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5629 + subId + "'");
5630 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5631 }
5632 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5633 try {
5634 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5635 } catch (RemoteException e) {
5636 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5637 + "Ignore");
5638 }
5639 });
5640 } finally {
5641 Binder.restoreCallingIdentity(token);
5642 }
5643 }
5644
Daniel Brightbb5840b2021-01-12 15:48:18 -08005645 /**
5646 * Sets the ims registration state on all valid {@link Phone}s.
5647 */
5648 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005653 // NOTE: Before S, this method only set the default phone.
5654 for (final Phone phone : PhoneFactory.getPhones()) {
5655 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5656 phone.setImsRegistrationState(registered);
5657 }
5658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Wink Saville36469e72014-06-11 15:17:00 -07005662 }
5663
5664 /**
Stuart Scott54788802015-03-30 13:18:01 -07005665 * Set the network selection mode to automatic.
5666 *
5667 */
5668 @Override
5669 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5671 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
shilufc958392020-01-20 11:36:01 -08005675 if (!isActiveSubscription(subId)) {
5676 return;
5677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005679 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5680 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Stuart Scott54788802015-03-30 13:18:01 -07005684 }
5685
Jack Yud10cdd42020-09-28 20:28:01 -07005686 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005687 * Ask the radio to connect to the input network and change selection mode to manual.
5688 *
5689 * @param subId the id of the subscription.
5690 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5691 * the operator to attach to.
5692 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5693 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5694 * normal network selection next time.
5695 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005696 */
5697 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005698 public boolean setNetworkSelectionModeManual(
5699 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5701 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005702
5703 if (!isActiveSubscription(subId)) {
5704 return false;
5705 }
5706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 final long identity = Binder.clearCallingIdentity();
5708 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005709 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005711 if (DBG) {
5712 log("setNetworkSelectionModeManual: subId: " + subId
5713 + " operator: " + operatorInfo);
5714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005719 }
shilu84f6e8b2019-12-19 13:58:01 -08005720 /**
5721 * Get the manual network selection
5722 *
5723 * @param subId the id of the subscription.
5724 *
5725 * @return the previously saved user selected PLMN
5726 */
5727 @Override
5728 public String getManualNetworkSelectionPlmn(int subId) {
5729 TelephonyPermissions
5730 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5731 mApp, subId, "getManualNetworkSelectionPlmn");
5732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 if (!isActiveSubscription(subId)) {
5736 return "";
5737 }
5738
5739 final Phone phone = getPhone(subId);
5740 if (phone == null) {
5741 return "";
5742 }
5743 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5744 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5745 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005750
5751 /**
5752 * Scans for available networks.
5753 */
5754 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005755 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5758 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005759 LocationAccessPolicy.LocationPermissionResult locationResult =
5760 LocationAccessPolicy.checkLocationPermission(mApp,
5761 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5762 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005763 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005764 .setCallingPid(Binder.getCallingPid())
5765 .setCallingUid(Binder.getCallingUid())
5766 .setMethod("getCellNetworkScanResults")
5767 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5768 .build());
5769 switch (locationResult) {
5770 case DENIED_HARD:
5771 throw new SecurityException("Not allowed to access scan results -- location");
5772 case DENIED_SOFT:
5773 return null;
5774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775
Pengquan Menga1bb6272018-09-06 09:59:22 -07005776 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 try {
5778 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005779 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005784 }
5785
5786 /**
sqian80370722020-01-29 15:02:51 -08005787 * Get the call forwarding info, given the call forwarding reason.
5788 */
5789 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005790 public void getCallForwarding(int subId, int callForwardingReason,
5791 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005792 enforceReadPrivilegedPermission("getCallForwarding");
5793 long identity = Binder.clearCallingIdentity();
5794 try {
5795 if (DBG) {
5796 log("getCallForwarding: subId " + subId
5797 + " callForwardingReason" + callForwardingReason);
5798 }
Hall Liua1acea22020-09-18 19:04:59 -07005799
5800 Phone phone = getPhone(subId);
5801 if (phone == null) {
5802 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005803 callback.onError(
5804 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005805 } catch (RemoteException e) {
5806 // ignore
5807 }
5808 return;
5809 }
5810
5811 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5812 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5813 @Override
5814 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5815 try {
5816 callback.onCallForwardingInfoAvailable(info);
5817 } catch (RemoteException e) {
5818 // ignore
5819 }
5820 }
5821
5822 @Override
5823 public void onError(int error) {
5824 try {
5825 callback.onError(error);
5826 } catch (RemoteException e) {
5827 // ignore
5828 }
5829 }
5830 });
5831 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
5835 }
5836
5837 /**
5838 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5839 * reason, the number to forward, and the timeout before the forwarding is attempted.
5840 */
5841 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005842 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5843 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005844 enforceModifyPermission();
5845 long identity = Binder.clearCallingIdentity();
5846 try {
5847 if (DBG) {
5848 log("setCallForwarding: subId " + subId
5849 + " callForwardingInfo" + callForwardingInfo);
5850 }
Hall Liua1acea22020-09-18 19:04:59 -07005851
5852 Phone phone = getPhone(subId);
5853 if (phone == null) {
5854 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005855 callback.accept(
5856 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005857 } catch (RemoteException e) {
5858 // ignore
5859 }
5860 return;
5861 }
5862
5863 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5864 FunctionalUtils.ignoreRemoteException(callback::accept));
5865
5866 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
5870 }
5871
5872 /**
Hall Liua1acea22020-09-18 19:04:59 -07005873 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005874 */
5875 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005876 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005877 enforceReadPrivilegedPermission("getCallForwarding");
5878 long identity = Binder.clearCallingIdentity();
5879 try {
Hall Liua1acea22020-09-18 19:04:59 -07005880
5881 Phone phone = getPhone(subId);
5882 if (phone == null) {
5883 try {
5884 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5885 } catch (RemoteException e) {
5886 // ignore
5887 }
5888 return;
5889 }
5890
5891 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5892
sqian80370722020-01-29 15:02:51 -08005893 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005894 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
5898 }
5899
5900 /**
Hall Liua1acea22020-09-18 19:04:59 -07005901 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005902 */
5903 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005904 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005905 enforceModifyPermission();
5906 long identity = Binder.clearCallingIdentity();
5907 try {
Hall Liua1acea22020-09-18 19:04:59 -07005908 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5909
5910 Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 try {
5913 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5914 } catch (RemoteException e) {
5915 // ignore
5916 }
5917 return;
5918 }
5919
5920 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5921 FunctionalUtils.ignoreRemoteException(callback::accept));
5922
5923 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 /**
yinxub1bed742017-04-17 11:45:04 -07005930 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005931 *
yinxub1bed742017-04-17 11:45:04 -07005932 * @param subId id of the subscription
5933 * @param request contains the radio access networks with bands/channels to scan
5934 * @param messenger callback messenger for scan results or errors
5935 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005936 * @return the id of the requested scan which can be used to stop the scan.
5937 */
5938 @Override
5939 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005940 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5942 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005943 LocationAccessPolicy.LocationPermissionResult locationResult =
5944 LocationAccessPolicy.checkLocationPermission(mApp,
5945 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5946 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005947 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005948 .setCallingPid(Binder.getCallingPid())
5949 .setCallingUid(Binder.getCallingUid())
5950 .setMethod("requestNetworkScan")
5951 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5952 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005953 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005954 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5955 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005956 if (e != null) {
5957 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5958 throw e;
5959 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005960 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005961 return TelephonyScanManager.INVALID_SCAN_ID;
5962 }
5963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 }
Hall Liu912dfd32019-04-25 14:02:26 -07005965 int callingUid = Binder.getCallingUid();
5966 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005967 final long identity = Binder.clearCallingIdentity();
5968 try {
5969 return mNetworkScanRequestTracker.startNetworkScan(
5970 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005971 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
yinxu504e1392017-04-12 16:03:22 -07005975 }
5976
Hall Liub2ac8ef2019-02-28 15:56:23 -08005977 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005978 NetworkScanRequest request, int subId, String callingPackage) {
5979 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005980 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5981 boolean hasNetworkScanPermission =
5982 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5983 == PERMISSION_GRANTED;
5984
5985 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5986 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5987 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005988 }
5989
5990 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5991 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005992 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5993 return new SecurityException("Specific channels must not be"
5994 + " scanned without location access.");
5995 }
5996 }
5997 }
5998
Hall Liub2ac8ef2019-02-28 15:56:23 -08005999 return null;
6000 }
6001
yinxu504e1392017-04-12 16:03:22 -07006002 /**
6003 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006004 *
6005 * @param subId id of the subscription
6006 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006007 */
6008 @Override
6009 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6011 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
Hall Liu912dfd32019-04-25 14:02:26 -07006013 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final long identity = Binder.clearCallingIdentity();
6015 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006016 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
yinxu504e1392017-04-12 16:03:22 -07006020 }
6021
6022 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006023 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006024 *
SongFerngWang9e060372020-12-21 16:41:52 +08006025 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006026 */
6027 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006028 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006029 TelephonyPermissions
6030 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006031 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032
6033 final long identity = Binder.clearCallingIdentity();
6034 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006035 if (DBG) log("getAllowedNetworkTypesBitmask");
6036 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6037 int networkTypesBitmask = (result != null ? result[0] : -1);
6038 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6039 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006043 }
6044
6045 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006046 * Get the allowed network types for certain reason.
6047 *
6048 * @param subId the id of the subscription.
6049 * @param reason the reason the allowed network type change is taking place
6050 * @return the allowed network types.
6051 */
6052 @Override
6053 public long getAllowedNetworkTypesForReason(int subId,
6054 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6055 TelephonyPermissions
6056 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6057 mApp, subId, "getAllowedNetworkTypesForReason");
6058 final long identity = Binder.clearCallingIdentity();
6059 try {
6060 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
6064 }
6065
6066 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006067 * Enable/Disable E-UTRA-NR Dual Connectivity
6068 * @param subId subscription id of the sim card
6069 * @param nrDualConnectivityState expected NR dual connectivity state
6070 * This can be passed following states
6071 * <ol>
6072 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6073 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6074 * <li>Disable NR dual connectivity and force secondary cell to be released
6075 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6076 * </ol>
6077 * @return operation result.
6078 */
6079 @Override
6080 public int setNrDualConnectivityState(int subId,
6081 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6083 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006084 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006085 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6086 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6087 }
6088
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
6092 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6093 nrDualConnectivityState, subId,
6094 workSource);
6095 if (DBG) log("enableNRDualConnectivity result: " + result);
6096 return result;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
6100 }
6101
6102 /**
6103 * Is E-UTRA-NR Dual Connectivity enabled
6104 * @return true if dual connectivity is enabled else false
6105 */
6106 @Override
6107 public boolean isNrDualConnectivityEnabled(int subId) {
6108 TelephonyPermissions
6109 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6110 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006111 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006112 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6113 return false;
6114 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6116 final long identity = Binder.clearCallingIdentity();
6117 try {
6118 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6119 null, subId, workSource);
6120 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6121 return isEnabled;
6122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
6125 }
6126
6127 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006128 * Set the allowed network types of the device and
6129 * provide the reason triggering the allowed network change.
6130 *
6131 * @param subId the id of the subscription.
6132 * @param reason the reason the allowed network type change is taking place
6133 * @param allowedNetworkTypes the allowed network types.
6134 * @return true on success; false on any failure.
6135 */
6136 @Override
6137 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006138 @TelephonyManager.AllowedNetworkTypesReason int reason,
6139 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6141 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006142 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6143 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6144 return false;
6145 }
6146
6147 if (DBG) {
6148 log("setAllowedNetworkTypesForReason: " + reason
6149 + " value: " + allowedNetworkTypes);
6150 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006151 final long identity = Binder.clearCallingIdentity();
6152 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006153 Boolean success = (Boolean) sendRequest(
6154 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6155 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6156
6157 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6158 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
6162 }
6163
6164 /**
Miaoa84611c2019-03-15 09:21:10 +08006165 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006166 *
Miaoa84611c2019-03-15 09:21:10 +08006167 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006168 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006169 * @hide
6170 */
6171 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006172 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006175 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 try {
Miaoa84611c2019-03-15 09:21:10 +08006177 if (phone != null) {
6178 return phone.hasMatchedTetherApnSetting();
6179 } else {
6180 return false;
6181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 } finally {
6183 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006184 }
Junda Liu475951f2014-11-07 16:45:03 -08006185 }
6186
6187 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006188 * Enable or disable always reporting signal strength changes from radio.
6189 *
6190 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6191 */
6192 @Override
6193 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6194 enforceModifyPermission();
6195 enforceSystemCaller();
6196
6197 final long identity = Binder.clearCallingIdentity();
6198 final Phone phone = getPhone(subId);
6199 try {
6200 if (phone != null) {
6201 if (DBG) {
6202 log("setAlwaysReportSignalStrength: subId=" + subId
6203 + " isEnable=" + isEnable);
6204 }
6205 phone.setAlwaysReportSignalStrength(isEnable);
6206 } else {
6207 loge("setAlwaysReportSignalStrength: no phone found for subId="
6208 + subId);
6209 }
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006216 * Get the user enabled state of Mobile Data.
6217 *
6218 * TODO: remove and use isUserDataEnabled.
6219 * This can't be removed now because some vendor codes
6220 * calls through ITelephony directly while they should
6221 * use TelephonyManager.
6222 *
6223 * @return true on enabled
6224 */
6225 @Override
6226 public boolean getDataEnabled(int subId) {
6227 return isUserDataEnabled(subId);
6228 }
6229
6230 /**
6231 * Get whether mobile data is enabled per user setting.
6232 *
6233 * There are other factors deciding whether mobile data is actually enabled, but they are
6234 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006235 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006236 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006237 *
6238 * @return {@code true} if data is enabled else {@code false}
6239 */
6240 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006241 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006242 try {
6243 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6244 null);
6245 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6247 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 int phoneId = mSubscriptionController.getPhoneId(subId);
6253 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6254 Phone phone = PhoneFactory.getPhone(phoneId);
6255 if (phone != null) {
6256 boolean retVal = phone.isUserDataEnabled();
6257 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6258 return retVal;
6259 } else {
6260 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6261 return false;
6262 }
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006265 }
6266 }
6267
6268 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006269 * Checks if the device is capable of mobile data by considering whether whether the
6270 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6271 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006272 *
Shuo Qian985d1232020-01-08 14:30:06 -08006273 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006274 */
6275 @Override
6276 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006277 try {
6278 try {
6279 mApp.enforceCallingOrSelfPermission(
6280 android.Manifest.permission.ACCESS_NETWORK_STATE,
6281 null);
6282 } catch (Exception e) {
6283 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6284 "isDataEnabled");
6285 }
6286 } catch (Exception e) {
6287 enforceReadPrivilegedPermission("isDataEnabled");
6288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289
6290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 int phoneId = mSubscriptionController.getPhoneId(subId);
6293 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6294 Phone phone = PhoneFactory.getPhone(phoneId);
6295 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006296 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6298 return retVal;
6299 } else {
6300 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6301 return false;
6302 }
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006305 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006306 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006307
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006308 /**
6309 * Check if data is enabled for a specific reason
6310 * @param subId Subscription index
6311 * @param reason the reason the data enable change is taking place
6312 * @return {@code true} if the overall data is enabled; {@code false} if not.
6313 */
6314 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006315 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006316 @TelephonyManager.DataEnabledReason int reason) {
6317 try {
6318 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6319 null);
6320 } catch (Exception e) {
6321 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006322 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006323 }
6324
6325
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 int phoneId = mSubscriptionController.getPhoneId(subId);
6329 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006330 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006331 + " reason=" + reason);
6332 }
6333 Phone phone = PhoneFactory.getPhone(phoneId);
6334 if (phone != null) {
6335 boolean retVal;
6336 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6337 retVal = phone.isUserDataEnabled();
6338 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006339 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006340 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006341 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006342 return retVal;
6343 } else {
6344 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006345 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006346 + subId + " retVal=false");
6347 }
6348 return false;
6349 }
6350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
6353 }
6354
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006355 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006356 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006357 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6358 // Skip the check if it's one of these special uids
6359 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6360 }
6361
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006362 //load access rules from carrier configs, and check those as well: b/139133814
6363 SubscriptionController subController = SubscriptionController.getInstance();
6364 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6365 || subController == null) return privilegeFromSim;
6366
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006367 PackageManager pkgMgr = phone.getContext().getPackageManager();
6368 String[] packages = pkgMgr.getPackagesForUid(uid);
6369
6370 final long identity = Binder.clearCallingIdentity();
6371 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006372 int subId = phone.getSubId();
6373 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6374 // A test override is in place for the privileges for this subId, so don't try to
6375 // read the subscription privileges.
6376 return privilegeFromSim;
6377 }
6378 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006379 SubscriptionManager subManager = (SubscriptionManager)
6380 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6381 for (String pkg : packages) {
6382 if (subManager.canManageSubscription(subInfo, pkg)) {
6383 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6384 }
6385 }
6386 return privilegeFromSim;
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
6390 }
6391
6392 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6393 String pkgName) {
6394 //load access rules from carrier configs, and check those as well: b/139133814
6395 SubscriptionController subController = SubscriptionController.getInstance();
6396 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6397 || subController == null) return privilegeFromSim;
6398
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006401 int subId = phone.getSubId();
6402 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6403 // A test override is in place for the privileges for this subId, so don't try to
6404 // read the subscription privileges.
6405 return privilegeFromSim;
6406 }
6407 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006408 SubscriptionManager subManager = (SubscriptionManager)
6409 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6410 return subManager.canManageSubscription(subInfo, pkgName)
6411 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
6415 }
6416
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006417 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006418 public int getCarrierPrivilegeStatus(int subId) {
6419 final Phone phone = getPhone(subId);
6420 if (phone == null) {
6421 loge("getCarrierPrivilegeStatus: Invalid subId");
6422 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6423 }
6424 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006425 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006426 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006427 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6428 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006429
6430 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6431 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006432 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006433 }
Junda Liu29340342014-07-10 15:23:27 -07006434
6435 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006436 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006437 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006438 final Phone phone = getPhone(subId);
6439 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006440 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006441 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6442 }
6443 UiccProfile profile =
6444 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6445 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006446 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006447 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6448 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006449 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006450 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006451 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006452 }
6453
6454 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006455 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6456 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006457 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006458 }
6459
6460 int phoneId = SubscriptionManager.getPhoneId(subId);
6461 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006462 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006463 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006464 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6465 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006466 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6467 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6468 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006469 }
6470
6471 @Override
6472 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006473 if (TextUtils.isEmpty(pkgName))
6474 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006475 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6476 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6477 UiccCard card = UiccController.getInstance().getUiccCard(i);
6478 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006479 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006480 continue;
6481 }
6482
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006483 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6484 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6485 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006486 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6487 break;
6488 }
6489 }
6490
6491 return result;
Junda Liu29340342014-07-10 15:23:27 -07006492 }
Derek Tan89e89d42014-07-08 17:00:10 -07006493
6494 @Override
Junda Liue64de782015-04-16 17:19:16 -07006495 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6496 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6497 loge("phoneId " + phoneId + " is not valid.");
6498 return null;
6499 }
6500 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006501 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006502 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006503 return null ;
6504 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006505 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006506 }
6507
Amith Yamasani6e118872016-02-19 12:53:51 -08006508 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006509 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006510 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006511 List<String> privilegedPackages = new ArrayList<>();
6512 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006513 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6514 // has UICC in that slot.
6515 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006516 if (card.hasCarrierPrivilegeRules()) {
6517 if (packages == null) {
6518 // Only check packages in user 0 for now
6519 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006520 PackageManager.MATCH_DISABLED_COMPONENTS
6521 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006522 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006523 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006524 }
6525 for (int p = packages.size() - 1; p >= 0; p--) {
6526 PackageInfo pkgInfo = packages.get(p);
6527 if (pkgInfo != null && pkgInfo.packageName != null
6528 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006529 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006530 privilegedPackages.add(pkgInfo.packageName);
6531 }
6532 }
6533 }
6534 }
6535 return privilegedPackages;
6536 }
6537
chen xuf7e9fe82019-05-09 19:31:02 -07006538 @Override
6539 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006540 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6541
6542 final long identity = Binder.clearCallingIdentity();
6543
chen xuf7e9fe82019-05-09 19:31:02 -07006544 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006545 try {
6546 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6547 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6548 }
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006551 }
6552 return privilegedPackages;
6553 }
6554
Wink Savilleb564aae2014-10-23 10:18:09 -07006555 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006556 final Phone phone = getPhone(subId);
6557 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006558 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006559 return null;
6560 }
6561 String iccId = card.getIccId();
6562 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006563 return null;
6564 }
6565 return iccId;
6566 }
6567
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006568 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006569 public void setCallComposerStatus(int subId, int status) {
6570 enforceModifyPermission();
6571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 Phone phone = getPhone(subId);
6575 if (phone != null) {
6576 Phone defaultPhone = phone.getImsPhone();
6577 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6578 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6579 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006580 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6581 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006582 }
6583 }
Shuo Qiand8782462020-12-22 19:10:14 -08006584 } catch (ImsException e) {
6585 throw new ServiceSpecificException(e.getCode());
6586 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006587 Binder.restoreCallingIdentity(identity);
6588 }
6589 }
6590
6591 @Override
6592 public int getCallComposerStatus(int subId) {
6593 enforceReadPrivilegedPermission("getCallComposerStatus");
6594
6595 final long identity = Binder.clearCallingIdentity();
6596 try {
6597 Phone phone = getPhone(subId);
6598 if (phone != null) {
6599 Phone defaultPhone = phone.getImsPhone();
6600 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6601 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6602 return imsPhone.getCallComposerStatus();
6603 }
6604 }
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
6608 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6609 }
6610
6611 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006612 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6613 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006614 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006615 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 final String iccId = getIccId(subId);
6620 final Phone phone = getPhone(subId);
6621 if (phone == null) {
6622 return false;
6623 }
6624 final String subscriberId = phone.getSubscriberId();
6625
6626 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006627 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 + subscriberId + " to " + number);
6629 }
6630
6631 if (TextUtils.isEmpty(iccId)) {
6632 return false;
6633 }
6634
6635 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6636
6637 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6638 if (alphaTag == null) {
6639 editor.remove(alphaTagPrefKey);
6640 } else {
6641 editor.putString(alphaTagPrefKey, alphaTag);
6642 }
6643
6644 // Record both the line number and IMSI for this ICCID, since we need to
6645 // track all merged IMSIs based on line number
6646 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6647 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6648 if (number == null) {
6649 editor.remove(numberPrefKey);
6650 editor.remove(subscriberPrefKey);
6651 } else {
6652 editor.putString(numberPrefKey, number);
6653 editor.putString(subscriberPrefKey, subscriberId);
6654 }
6655
6656 editor.commit();
6657 return true;
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006660 }
Derek Tan7226c842014-07-02 17:42:23 -07006661 }
6662
6663 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006664 public String getLine1NumberForDisplay(int subId, String callingPackage,
6665 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006666 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006668 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006669 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006670 return null;
6671 }
Derek Tan97ebb422014-09-05 16:55:38 -07006672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 String iccId = getIccId(subId);
6676 if (iccId != null) {
6677 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6678 if (DBG_MERGE) {
6679 log("getLine1NumberForDisplay returning "
6680 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6681 }
6682 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6685 return null;
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006688 }
Derek Tan7226c842014-07-02 17:42:23 -07006689 }
6690
6691 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006692 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6693 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006695 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006696 return null;
6697 }
Derek Tan97ebb422014-09-05 16:55:38 -07006698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 String iccId = getIccId(subId);
6702 if (iccId != null) {
6703 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6704 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6705 }
6706 return null;
6707 } finally {
6708 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006709 }
Derek Tan7226c842014-07-02 17:42:23 -07006710 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006711
6712 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006713 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6714 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006715 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6716 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006718 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006719 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006720 return null;
6721 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006722
Jordan Liub49b04b2019-05-06 14:45:15 -07006723 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6724 // the process, where TelephonyManager was instantiated.
6725 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006726 final long identity = Binder.clearCallingIdentity();
6727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006728 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 final TelephonyManager tele = TelephonyManager.from(context);
6730 final SubscriptionManager sub = SubscriptionManager.from(context);
6731
6732 // Figure out what subscribers are currently active
6733 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734
Jordan Liub49b04b2019-05-06 14:45:15 -07006735 // Only consider subs which match the current subId
6736 // This logic can be simplified. See b/131189269 for progress.
6737 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006738 activeSubscriberIds.add(tele.getSubscriberId(subId));
6739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
6741 // First pass, find a number override for an active subscriber
6742 String mergeNumber = null;
6743 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6744 for (String key : prefs.keySet()) {
6745 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6746 final String subscriberId = (String) prefs.get(key);
6747 if (activeSubscriberIds.contains(subscriberId)) {
6748 final String iccId = key.substring(
6749 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6750 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6751 mergeNumber = (String) prefs.get(numberKey);
6752 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006753 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754 + " for active subscriber " + subscriberId);
6755 }
6756 if (!TextUtils.isEmpty(mergeNumber)) {
6757 break;
6758 }
6759 }
6760 }
6761 }
6762
6763 // Shortcut when no active merged subscribers
6764 if (TextUtils.isEmpty(mergeNumber)) {
6765 return null;
6766 }
6767
6768 // Second pass, find all subscribers under that line override
6769 final ArraySet<String> result = new ArraySet<>();
6770 for (String key : prefs.keySet()) {
6771 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6772 final String number = (String) prefs.get(key);
6773 if (mergeNumber.equals(number)) {
6774 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6775 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6776 final String subscriberId = (String) prefs.get(subscriberKey);
6777 if (!TextUtils.isEmpty(subscriberId)) {
6778 result.add(subscriberId);
6779 }
6780 }
6781 }
6782 }
6783
6784 final String[] resultArray = result.toArray(new String[result.size()]);
6785 Arrays.sort(resultArray);
6786 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006787 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6789 }
6790 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006791 } finally {
6792 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006793 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006794 }
6795
6796 @Override
zoey chen38003472019-12-13 17:16:31 +08006797 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6798 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006799
6800 final long identity = Binder.clearCallingIdentity();
6801 try {
6802 final TelephonyManager telephonyManager = mApp.getSystemService(
6803 TelephonyManager.class);
6804 String subscriberId = telephonyManager.getSubscriberId(subId);
6805 if (subscriberId == null) {
6806 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006807 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006808 + subId);
6809 }
6810 return null;
6811 }
6812
6813 final SubscriptionInfo info = SubscriptionController.getInstance()
6814 .getSubscriptionInfo(subId);
6815 final ParcelUuid groupUuid = info.getGroupUuid();
6816 // If it doesn't belong to any group, return just subscriberId of itself.
6817 if (groupUuid == null) {
6818 return new String[]{subscriberId};
6819 }
6820
6821 // Get all subscriberIds from the group.
6822 final List<String> mergedSubscriberIds = new ArrayList<>();
6823 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006824 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006825 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006826 for (SubscriptionInfo subInfo : groupInfos) {
6827 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6828 if (subscriberId != null) {
6829 mergedSubscriberIds.add(subscriberId);
6830 }
6831 }
6832
6833 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6834 } finally {
6835 Binder.restoreCallingIdentity(identity);
6836
6837 }
6838 }
6839
6840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006841 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006842 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844
6845 final long identity = Binder.clearCallingIdentity();
6846 try {
6847 final Phone phone = getPhone(subId);
6848 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6849 } finally {
6850 Binder.restoreCallingIdentity(identity);
6851 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006852 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006853
6854 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006855 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006856 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6857 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006858 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6859 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
6863 final Phone phone = getPhone(subId);
6864 if (phone == null) {
6865 return false;
6866 }
6867 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6868 cdmaNonRoamingList);
6869 } finally {
6870 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006871 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006872 }
6873
6874 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006875 @Deprecated
6876 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6877 enforceModifyPermission();
6878
6879 int returnValue = 0;
6880 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006881 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006882 if(result.exception == null) {
6883 if (result.result != null) {
6884 byte[] responseData = (byte[])(result.result);
6885 if(responseData.length > oemResp.length) {
6886 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6887 responseData.length + "bytes. Buffer Size is " +
6888 oemResp.length + "bytes.");
6889 }
6890 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6891 returnValue = responseData.length;
6892 }
6893 } else {
6894 CommandException ex = (CommandException) result.exception;
6895 returnValue = ex.getCommandError().ordinal();
6896 if(returnValue > 0) returnValue *= -1;
6897 }
6898 } catch (RuntimeException e) {
6899 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6900 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6901 if(returnValue > 0) returnValue *= -1;
6902 }
6903
6904 return returnValue;
6905 }
6906
6907 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006908 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006909 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006910 try {
6911 TelephonyPermissions
6912 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6913 mApp, phone.getSubId(), "getRadioAccessFamily");
6914 } catch (SecurityException e) {
6915 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6916 throw e;
6917 }
chen xub97461a2018-10-26 14:17:57 -07006918 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006919 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006920 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922 final long identity = Binder.clearCallingIdentity();
6923 try {
chen xub97461a2018-10-26 14:17:57 -07006924 TelephonyPermissions
6925 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6926 mApp, phone.getSubId(), "getRadioAccessFamily");
6927 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
chen xub97461a2018-10-26 14:17:57 -07006931 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006932 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006933
6934 @Override
6935 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006936 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006941 ImsManager.getInstance(defaultPhone.getContext(),
6942 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006946 }
6947
6948 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006949 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006950 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6952 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006953 return false;
6954 }
Svet Ganovb320e182015-04-16 12:30:10 -07006955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 // Check the user preference and the system-level IMS setting. Even if the user has
6959 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6960 // In the long run, we may instead need to check if there exists a connection service
6961 // which can support video calling.
6962 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006963 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 return imsManager.isVtEnabledByPlatform()
6965 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6966 && imsManager.isVtEnabledByUser();
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006970 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006971
Andrew Leea1239f22015-03-02 17:44:07 -08006972 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006973 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6974 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006976 mApp, subId, callingPackage, callingFeatureId,
6977 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 return false;
6979 }
6980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 CarrierConfigManager configManager =
6984 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006985 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
6989 }
Andrew Leea1239f22015-03-02 17:44:07 -08006990 }
6991
6992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006993 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006995 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 return false;
6997 }
6998
6999 final long identity = Binder.clearCallingIdentity();
7000 try {
7001 CarrierConfigManager configManager =
7002 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007003 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
Andrew Leea1239f22015-03-02 17:44:07 -08007008 }
7009
Andrew Lee9431b832015-03-09 18:46:45 -07007010 @Override
7011 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007012 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007013 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007014 }
7015
7016 @Override
7017 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007020 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
Andrew Lee9431b832015-03-09 18:46:45 -07007024 }
7025
Hall Liuf6668912018-10-31 17:05:23 -07007026 /**
7027 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7028 * support for the feature and device firmware support.
7029 *
7030 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7031 */
7032 @Override
7033 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007035 final Phone phone = getPhone(subscriptionId);
7036 if (phone == null) {
7037 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7038 return false;
7039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007041 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7043 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007044 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 return isCarrierSupported && isDeviceSupported;
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
Hall Liu98187582018-01-22 19:15:32 -08007049 }
7050
Hall Liuf6668912018-10-31 17:05:23 -07007051 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007052 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7053 * RTT setting, will return true if the device and carrier both support RTT.
7054 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007055 */
7056 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 final long identity = Binder.clearCallingIdentity();
7058 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007059 boolean isRttSupported = isRttSupported(subscriptionId);
7060 boolean isUserRttSettingOn = Settings.Secure.getInt(
7061 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7062 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7063 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7064 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007068 }
7069
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007070 @Deprecated
7071 @Override
7072 public String getDeviceId(String callingPackage) {
7073 return getDeviceIdWithFeature(callingPackage, null);
7074 }
7075
Sanket Padawe7310cc72015-01-14 09:53:20 -08007076 /**
7077 * Returns the unique device ID of phone, for example, the IMEI for
7078 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7079 *
7080 * <p>Requires Permission:
7081 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7082 */
7083 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007084 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007085 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007086 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007087 return null;
7088 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007089 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007090 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007091 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007092 return null;
7093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094
7095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 return phone.getDeviceId();
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
7100 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007101 }
7102
Ping Sunc67b7c22016-03-02 19:16:45 +08007103 /**
7104 * {@hide}
7105 * Returns the IMS Registration Status on a particular subid
7106 *
7107 * @param subId
7108 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007109 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007110 Phone phone = getPhone(subId);
7111 if (phone != null) {
7112 return phone.isImsRegistered();
7113 } else {
7114 return false;
7115 }
7116 }
7117
Santos Cordon7a1885b2015-02-03 11:15:19 -08007118 @Override
7119 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007126 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007127
Tyler Gunnf70ed162019-04-03 15:28:53 -07007128 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007129 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007130 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007132 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007133 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7134 }
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
7141 }
7142
7143 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007144 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007145 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7146 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 Phone phone = getPhone(subscriptionId);
7150 if (phone == null) {
7151 return null;
7152 }
7153 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
7158
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007159 /**
7160 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007161 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007162 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 Phone phone = getPhone(subId);
7166 if (phone != null) {
7167 return phone.isWifiCallingEnabled();
7168 } else {
7169 return false;
7170 }
7171 } finally {
7172 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007173 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007174 }
7175
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007176 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007177 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007178 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007179 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 Phone phone = getPhone(subId);
7183 if (phone != null) {
7184 return phone.isVideoEnabled();
7185 } else {
7186 return false;
7187 }
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007190 }
7191 }
7192
7193 /**
7194 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7195 * defined in {@link ImsRegistrationImplBase}.
7196 */
7197 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 Phone phone = getPhone(subId);
7201 if (phone != null) {
7202 return phone.getImsRegistrationTech();
7203 } else {
7204 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7205 }
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007208 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007209 }
7210
Stuart Scott8eef64f2015-04-08 15:13:54 -07007211 @Override
7212 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007213 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007214 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7215 return;
7216 }
7217
Svet Ganovcc087f82015-05-12 20:35:54 -07007218 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007219
Svet Ganovcc087f82015-05-12 20:35:54 -07007220 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007221 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7222 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007223 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007224 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007225 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007226 setAllowedNetworkTypesForReason(subId,
7227 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7228 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7229 setAllowedNetworkTypesForReason(subId,
7230 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7231 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7232 setAllowedNetworkTypesForReason(subId,
7233 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7234 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Yomna Nassera39e5222021-02-17 03:38:52 +00007235 setAllowedNetworkTypesForReason(subId,
7236 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G,
7237 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007238 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7239 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007240 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007241 // There has been issues when Sms raw table somehow stores orphan
7242 // fragments. They lead to garbled message when new fragments come
7243 // in and combined with those stale ones. In case this happens again,
7244 // user can reset all network settings which will clean up this table.
7245 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007246 // Clean up IMS settings as well here.
7247 int slotId = getSlotIndex(subId);
7248 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7249 ImsManager.getInstance(mApp, slotId).factoryReset();
7250 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007251
7252 // Erase modem config if erase modem on network setting is enabled.
7253 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7254 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7255 if (configValue != null && Boolean.parseBoolean(configValue)) {
7256 sendEraseModemConfig(getDefaultPhone());
7257 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007258 } finally {
7259 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007260 }
7261 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007262
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007263 private void cleanUpSmsRawTable(Context context) {
7264 ContentResolver resolver = context.getContentResolver();
7265 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7266 resolver.delete(uri, null, null);
7267 }
7268
Narayan Kamath1c496c22015-04-16 14:40:19 +01007269 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007270 public String getSimLocaleForSubscriber(int subId) {
7271 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7272 final Phone phone = getPhone(subId);
7273 if (phone == null) {
7274 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007275 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277 final long identity = Binder.clearCallingIdentity();
7278 try {
chen xu5d3637b2019-01-21 23:31:38 -08007279 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007280 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007281 if (info == null) {
7282 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7283 return null;
7284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007285 // Try and fetch the locale from the carrier properties or from the SIM language
7286 // preferences (EF-PL and EF-LI)...
7287 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007289 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7290 if (localeFromDefaultSim != null) {
7291 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7292 if (DBG) log("Using locale from subId: " + subId + " locale: "
7293 + localeFromDefaultSim);
7294 return localeFromDefaultSim.toLanguageTag();
7295 } else {
7296 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 }
7298 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300 // The SIM language preferences only store a language (e.g. fr = French), not an
7301 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7302 // the SIM and carrier preferences does not include a country we add the country
7303 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007304 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007306 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 return mccLocale.toLanguageTag();
7308 }
7309
7310 if (DBG) log("No locale found - returning null");
7311 return null;
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
7314 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007315 }
7316
7317 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007318 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007319 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007320 }
7321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 /**
7323 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7324 */
7325 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007326 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007327 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007328 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007329
Chenjie Yu1ba97252018-01-11 18:16:20 -08007330 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007331 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007332
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007333 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007334 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7335 * representing the state of the modem.
7336 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007337 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7338 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007339 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007340 */
7341 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007342 public void requestModemActivityInfo(ResultReceiver result) {
7343 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
sqian1a1be542020-03-05 11:37:28 -08007348 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 } finally {
7350 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007351 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007352 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007353
Siddharth Rayb8114062018-06-17 15:02:38 -07007354 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7355 // less than total activity duration.
7356 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7357 if (info == null) {
7358 return false;
7359 }
7360 int activityDurationMs =
7361 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7362 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007363 int[] txTimeMs = info.getTransmitTimeMillis();
7364 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7365 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007366 }
7367 return (info.isValid()
7368 && (info.getSleepTimeMillis() <= activityDurationMs)
7369 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007370 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007371 && (totalTxTimeMs <= activityDurationMs));
7372 }
7373
Jack Yu85bd38a2015-11-09 11:34:32 -08007374 /**
7375 * {@hide}
7376 * Returns the service state information on specified subscription.
7377 */
7378 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007379 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7380 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007382 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007383 return null;
7384 }
7385
Hall Liuf19c44f2018-11-27 14:38:17 -08007386 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7387 LocationAccessPolicy.checkLocationPermission(mApp,
7388 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7389 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007390 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007391 .setCallingPid(Binder.getCallingPid())
7392 .setCallingUid(Binder.getCallingUid())
7393 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007394 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7396 .build());
7397
7398 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7399 LocationAccessPolicy.checkLocationPermission(mApp,
7400 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7401 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007402 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007403 .setCallingPid(Binder.getCallingPid())
7404 .setCallingUid(Binder.getCallingUid())
7405 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007406 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007407 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7408 .build());
7409 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7410 boolean hasFinePermission =
7411 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7412 boolean hasCoarsePermission =
7413 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
7416 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007417 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7418 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7419 Rlog.d(LOG_TAG,
7420 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7421 return null;
7422 }
7423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 final Phone phone = getPhone(subId);
7425 if (phone == null) {
7426 return null;
7427 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007428
Hall Liuf19c44f2018-11-27 14:38:17 -08007429 ServiceState ss = phone.getServiceState();
7430
7431 // Scrub out the location info in ServiceState depending on what level of access
7432 // the caller has.
7433 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007434 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7435 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007439 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007440
7441 /**
7442 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7443 *
7444 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7445 * voicemail ringtone.
7446 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7447 * PhoneAccount.
7448 */
7449 @Override
7450 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
7453 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7454 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007462 }
7463
7464 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007465 * Sets the per-account voicemail ringtone.
7466 *
7467 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7468 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7469 *
7470 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7471 * voicemail ringtone.
7472 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7473 * PhoneAccount.
7474 */
7475 @Override
7476 public void setVoicemailRingtoneUri(String callingPackage,
7477 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007480 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7481 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7483 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7484 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7490 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007491 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 }
7493 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007496 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007497 }
7498
7499 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007500 * Returns whether vibration is set for voicemail notification in Phone settings.
7501 *
7502 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7503 * voicemail vibration setting.
7504 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7505 */
7506 @Override
7507 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 final long identity = Binder.clearCallingIdentity();
7509 try {
7510 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7511 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007512 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7516 } finally {
7517 Binder.restoreCallingIdentity(identity);
7518 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007519 }
7520
Youhan Wange64578a2016-05-02 15:32:42 -07007521 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007522 * Sets the per-account voicemail vibration.
7523 *
7524 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7525 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7526 *
7527 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7528 * voicemail vibration setting.
7529 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7530 * specific PhoneAccount.
7531 */
7532 @Override
7533 public void setVoicemailVibrationEnabled(String callingPackage,
7534 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007537 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7538 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7540 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7541 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007542 }
7543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7547 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007548 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 }
7550 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007553 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007554 }
7555
7556 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007557 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7558 *
7559 * @throws SecurityException if the caller does not have the required permission
7560 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007561 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007562 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007563 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007564 }
7565
7566 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007567 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7568 * permission.
7569 *
7570 * @throws SecurityException if the caller does not have the required permission
7571 */
7572 private void enforceSendSmsPermission() {
7573 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7574 }
7575
7576 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007577 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007578 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007579 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007580 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007581 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007585 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 if (componentName == null) {
7587 throw new SecurityException(
7588 "Caller not current active visual voicemail package[null]");
7589 }
7590 String vvmPackage = componentName.getPackageName();
7591 if (!callingPackage.equals(vvmPackage)) {
7592 throw new SecurityException("Caller not current active visual voicemail package["
7593 + vvmPackage + "]");
7594 }
7595 } finally {
7596 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007597 }
7598 }
7599
7600 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007601 * Return the application ID for the app type.
7602 *
7603 * @param subId the subscription ID that this request applies to.
7604 * @param appType the uicc app type.
7605 * @return Application ID for specificied app type, or null if no uicc.
7606 */
7607 @Override
7608 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007609 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007610 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611
7612 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007613 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 if (phone == null) {
7615 return null;
7616 }
7617 String aid = null;
7618 try {
7619 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7620 .getApplicationByType(appType).getAid();
7621 } catch (Exception e) {
7622 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7623 }
7624 return aid;
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007627 }
Youhan Wange64578a2016-05-02 15:32:42 -07007628 }
7629
Youhan Wang4001d252016-05-11 10:29:41 -07007630 /**
7631 * Return the Electronic Serial Number.
7632 *
7633 * @param subId the subscription ID that this request applies to.
7634 * @return ESN or null if error.
7635 */
7636 @Override
7637 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007638 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007639 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640
7641 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007642 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 if (phone == null) {
7644 return null;
7645 }
7646 String esn = null;
7647 try {
7648 esn = phone.getEsn();
7649 } catch (Exception e) {
7650 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7651 }
7652 return esn;
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007655 }
Youhan Wang4001d252016-05-11 10:29:41 -07007656 }
7657
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007658 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007659 * Return the Preferred Roaming List Version.
7660 *
7661 * @param subId the subscription ID that this request applies to.
7662 * @return PRLVersion or null if error.
7663 */
7664 @Override
7665 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007666 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007667 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668
7669 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007670 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 if (phone == null) {
7672 return null;
7673 }
7674 String cdmaPrlVersion = null;
7675 try {
7676 cdmaPrlVersion = phone.getCdmaPrlVersion();
7677 } catch (Exception e) {
7678 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7679 }
7680 return cdmaPrlVersion;
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007683 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007684 }
7685
7686 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007687 * Get snapshot of Telephony histograms
7688 * @return List of Telephony histograms
7689 * @hide
7690 */
7691 @Override
7692 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7694 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 return RIL.getTelephonyRILTimingHistograms();
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007702 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007703
7704 /**
7705 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007706 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7707 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007708 * Require system privileges. In the future we may add this to carrier APIs.
7709 *
Michele Berionne482f8202018-11-27 18:57:59 -08007710 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007711 */
7712 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007713 @TelephonyManager.SetCarrierRestrictionResult
7714 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007715 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007716 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007717
Michele Berionne482f8202018-11-27 18:57:59 -08007718 if (carrierRestrictionRules == null) {
7719 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007720 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 final long identity = Binder.clearCallingIdentity();
7723 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007724 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007725 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007729 }
7730
7731 /**
7732 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007733 * Get the allowed carrier list and the excluded carrier list, including the priority between
7734 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007735 * Require system privileges. In the future we may add this to carrier APIs.
7736 *
Michele Berionne482f8202018-11-27 18:57:59 -08007737 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 */
7739 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007740 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007741 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007742 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743
7744 final long identity = Binder.clearCallingIdentity();
7745 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007746 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7747 if (response instanceof CarrierRestrictionRules) {
7748 return (CarrierRestrictionRules) response;
7749 }
7750 // Response is an Exception of some kind,
7751 // which is signalled to the user as a NULL retval
7752 return null;
7753 } catch (Exception e) {
7754 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7755 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007759 }
7760
fionaxu59545b42016-05-25 15:53:37 -07007761 /**
fionaxu59545b42016-05-25 15:53:37 -07007762 * Action set from carrier signalling broadcast receivers to enable/disable radio
7763 * @param subId the subscription ID that this action applies to.
7764 * @param enabled control enable or disable radio.
7765 * {@hide}
7766 */
7767 @Override
7768 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7769 enforceModifyPermission();
7770 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771
7772 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007773 if (phone == null) {
7774 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7775 return;
7776 }
7777 try {
7778 phone.carrierActionSetRadioEnabled(enabled);
7779 } catch (Exception e) {
7780 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 } finally {
7782 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007783 }
7784 }
7785
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007786 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007787 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7788 * network status based on which carrier apps could apply actions accordingly,
7789 * enable/disable default url handler for example.
7790 *
7791 * @param subId the subscription ID that this action applies to.
7792 * @param report control start/stop reporting the default network status.
7793 * {@hide}
7794 */
7795 @Override
7796 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7797 enforceModifyPermission();
7798 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799
7800 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007801 if (phone == null) {
7802 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7803 return;
7804 }
7805 try {
7806 phone.carrierActionReportDefaultNetworkStatus(report);
7807 } catch (Exception e) {
7808 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 } finally {
7810 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007811 }
7812 }
7813
7814 /**
fionaxud9622282017-07-17 17:51:30 -07007815 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7816 * @param subId the subscription ID that this action applies to.
7817 * {@hide}
7818 */
7819 @Override
7820 public void carrierActionResetAll(int subId) {
7821 enforceModifyPermission();
7822 final Phone phone = getPhone(subId);
7823 if (phone == null) {
7824 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7825 return;
7826 }
7827 try {
7828 phone.carrierActionResetAll();
7829 } catch (Exception e) {
7830 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7831 }
7832 }
7833
7834 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007835 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7836 * bug report is being generated.
7837 */
7838 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007839 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007840 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7841 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007842 writer.println("Permission Denial: can't dump Phone from pid="
7843 + Binder.getCallingPid()
7844 + ", uid=" + Binder.getCallingUid()
7845 + "without permission "
7846 + android.Manifest.permission.DUMP);
7847 return;
7848 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007849 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007850 }
Jack Yueb89b242016-06-22 13:27:47 -07007851
Brad Ebingerdac2f002018-04-03 15:17:52 -07007852 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007853 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7854 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7855 @NonNull String[] args) {
7856 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7857 this, in.getFileDescriptor(), out.getFileDescriptor(),
7858 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007859 }
7860
Jack Yueb89b242016-06-22 13:27:47 -07007861 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007862 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007863 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007864 * @param reason the reason the data enable change is taking place
7865 * @param enabled True if enabling the data, otherwise disabling.
7866 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007867 */
7868 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007869 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007870 boolean enabled) {
7871 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7872 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7873 try {
7874 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007875 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007876 } catch (SecurityException se) {
7877 enforceModifyPermission();
7878 }
7879 } else {
7880 enforceModifyPermission();
7881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882
7883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 Phone phone = getPhone(subId);
7886 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007887 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7888 phone.carrierActionSetMeteredApnsEnabled(enabled);
7889 } else {
7890 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 }
7893 } finally {
7894 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007895 }
7896 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007897
7898 /**
7899 * Get Client request stats
7900 * @return List of Client Request Stats
7901 * @hide
7902 */
7903 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007904 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7905 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007907 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007908 return null;
7909 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007910 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 if (phone != null) {
7915 return phone.getClientRequestStats();
7916 }
7917
7918 return null;
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
7921 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007922 }
7923
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007924 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007925 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007926 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007927 }
Jack Yueb4124c2017-02-16 15:32:43 -08007928
7929 /**
Grace Chen70990072017-03-24 17:21:30 -07007930 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007931 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007932 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007933 * @param state State of SIM (power down, power up, pass through)
7934 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7935 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7936 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007937 *
7938 **/
7939 @Override
Grace Chen70990072017-03-24 17:21:30 -07007940 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007941 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007942 Phone phone = PhoneFactory.getPhone(slotIndex);
7943
vagdeviaf9a5b92018-08-15 16:01:53 -07007944 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 final long identity = Binder.clearCallingIdentity();
7947 try {
7948 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007949 phone.setSimPowerState(state, null, workSource);
7950 }
7951 } finally {
7952 Binder.restoreCallingIdentity(identity);
7953 }
7954 }
7955
7956 /**
7957 * Set SIM card power state.
7958 *
7959 * @param slotIndex SIM slot id.
7960 * @param state State of SIM (power down, power up, pass through)
7961 * @param callback callback to trigger after success or failure
7962 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7963 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7964 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7965 *
7966 **/
7967 @Override
7968 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7969 IIntegerConsumer callback) {
7970 enforceModifyPermission();
7971 Phone phone = PhoneFactory.getPhone(slotIndex);
7972
7973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7974
7975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 if (phone != null) {
7978 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7979 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 }
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007983 }
7984 }
Shuo Qiandd210312017-04-12 22:11:33 +00007985
Tyler Gunn65d45c22017-06-05 11:22:26 -07007986 private boolean isUssdApiAllowed(int subId) {
7987 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007989 if (configManager == null) {
7990 return false;
7991 }
7992 PersistableBundle pb = configManager.getConfigForSubId(subId);
7993 if (pb == null) {
7994 return false;
7995 }
7996 return pb.getBoolean(
7997 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7998 }
7999
Shuo Qiandd210312017-04-12 22:11:33 +00008000 /**
8001 * Check if phone is in emergency callback mode
8002 * @return true if phone is in emergency callback mode
8003 * @param subId sub id
8004 */
goneil9c5f4872017-12-05 14:07:56 -08008005 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008006 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008007 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008008 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 if (phone != null) {
8013 return phone.isInEcm();
8014 } else {
8015 return false;
8016 }
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008019 }
8020 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008021
8022 /**
8023 * Get the current signal strength information for the given subscription.
8024 * Because this information is not updated when the device is in a low power state
8025 * it should not be relied-upon to be current.
8026 * @param subId Subscription index
8027 * @return the most recent cached signal strength info from the modem
8028 */
8029 @Override
8030 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 Phone p = getPhone(subId);
8034 if (p == null) {
8035 return null;
8036 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 return p.getSignalStrength();
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
8041 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008042 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008043
Pengquan Meng77b7f132018-08-22 14:49:57 -07008044 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008045 * Get the current modem radio state for the given slot.
8046 * @param slotIndex slot index.
8047 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008048 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008049 * @return the current radio power state from the modem
8050 */
8051 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008052 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008053 Phone phone = PhoneFactory.getPhone(slotIndex);
8054 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8056 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008057 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8058 }
8059
8060 final long identity = Binder.clearCallingIdentity();
8061 try {
8062 return phone.getRadioPowerState();
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
8066 }
8067 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8068 }
8069
8070 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008071 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8072 *
8073 * <p>Requires one of the following permissions:
8074 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8075 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8076 * privileges.
8077 *
8078 * @param subId subscription id
8079 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8080 * {@code false}.
8081 */
8082 @Override
8083 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008084 try {
8085 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8086 null);
8087 } catch (Exception e) {
8088 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8089 mApp, subId, "isDataRoamingEnabled");
8090 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008091
Pengquan Menga1bb6272018-09-06 09:59:22 -07008092 boolean isEnabled = false;
8093 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008094 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008095 Phone phone = getPhone(subId);
8096 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008097 } finally {
8098 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008099 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008100 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008101 }
8102
8103
8104 /**
8105 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8106 *
8107 * <p> Requires permission:
8108 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8109 * privileges.
8110 *
8111 * @param subId subscription id
8112 * @param isEnabled {@code true} means enable, {@code false} means disable.
8113 */
8114 @Override
8115 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8117 mApp, subId, "setDataRoamingEnabled");
8118
Pengquan Menga1bb6272018-09-06 09:59:22 -07008119 final long identity = Binder.clearCallingIdentity();
8120 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008121 Phone phone = getPhone(subId);
8122 if (phone != null) {
8123 phone.setDataRoamingEnabled(isEnabled);
8124 }
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008127 }
8128 }
8129
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008130 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008131 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008132 TelephonyPermissions
8133 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008134 mApp, subId, "isManualNetworkSelectionAllowed");
8135
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008136 boolean isAllowed = true;
8137 final long identity = Binder.clearCallingIdentity();
8138 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008139 Phone phone = getPhone(subId);
8140 if (phone != null) {
8141 isAllowed = phone.isCspPlmnEnabled();
8142 }
8143 } finally {
8144 Binder.restoreCallingIdentity(identity);
8145 }
8146 return isAllowed;
8147 }
8148
8149 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008150 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008151 // Verify that tha callingPackage belongs to the calling UID
8152 mApp.getSystemService(AppOpsManager.class)
8153 .checkPackage(Binder.getCallingUid(), callingPackage);
8154
Jordan Liu1e142fc2019-04-22 15:10:43 -07008155 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008156 try {
8157 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008158 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008159 } catch (SecurityException e) {
8160 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8161 // has carrier privileges on an active UICC
8162 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8163 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008164 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008165 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008166 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008167
8168 final long identity = Binder.clearCallingIdentity();
8169 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008170 UiccController uiccController = UiccController.getInstance();
8171 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008172 if (hasReadPermission) {
8173 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008174 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008175
8176 // Remove private info if the caller doesn't have access
8177 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8178 for (UiccCardInfo cardInfo : cardInfos) {
8179 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8180 // is available
8181 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8182 if (card == null || card.getUiccProfile() == null) {
8183 // assume no access if the card or profile is unavailable
8184 filteredInfos.add(cardInfo.getUnprivileged());
8185 continue;
8186 }
8187 UiccProfile profile = card.getUiccProfile();
8188 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8189 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8190 filteredInfos.add(cardInfo);
8191 } else {
8192 filteredInfos.add(cardInfo.getUnprivileged());
8193 }
8194 }
8195 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
8199 }
8200
8201 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008202 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008203 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8208 if (slots == null) {
8209 Rlog.i(LOG_TAG, "slots is null.");
8210 return null;
8211 }
8212
8213 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8214 for (int i = 0; i < slots.length; i++) {
8215 UiccSlot slot = slots[i];
8216 if (slot == null) {
8217 continue;
8218 }
8219
Jordan Liu7be7e652019-05-06 18:55:02 +00008220 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 UiccCard card = slot.getUiccCard();
8222 if (card != null) {
8223 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008224 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008225 cardId = slot.getEid();
8226 if (TextUtils.isEmpty(cardId)) {
8227 cardId = slot.getIccId();
8228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 }
8230
Jordan Liu857451f2019-05-09 16:35:35 -07008231 if (cardId != null) {
8232 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8233 // if cardId is an EID, it's all digits so this is fine
8234 cardId = IccUtils.stripTrailingFs(cardId);
8235 }
8236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 int cardState = 0;
8238 switch (slot.getCardState()) {
8239 case CARDSTATE_ABSENT:
8240 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8241 break;
8242 case CARDSTATE_PRESENT:
8243 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8244 break;
8245 case CARDSTATE_ERROR:
8246 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8247 break;
8248 case CARDSTATE_RESTRICTED:
8249 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8250 break;
8251 default:
8252 break;
8253
8254 }
8255
8256 infos[i] = new UiccSlotInfo(
8257 slot.isActive(),
8258 slot.isEuicc(),
8259 cardId,
8260 cardState,
8261 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008262 slot.isExtendedApduSupported(),
8263 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 }
8265 return infos;
8266 } finally {
8267 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008268 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008269 }
8270
8271 @Override
8272 public boolean switchSlots(int[] physicalSlots) {
8273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008281 }
Jack Yu4c988042018-02-27 15:30:01 -08008282
8283 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008284 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 return UiccController.getInstance().getCardIdForDefaultEuicc();
8288 } finally {
8289 Binder.restoreCallingIdentity(identity);
8290 }
8291 }
8292
Pengquan Meng85728fb2018-03-12 16:31:21 -07008293 /**
goneil47ffb6e2018-04-06 15:40:58 -07008294 * A test API to reload the UICC profile.
8295 *
8296 * <p>Requires that the calling app has permission
8297 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8298 * @hide
8299 */
8300 @Override
8301 public void refreshUiccProfile(int subId) {
8302 enforceModifyPermission();
8303
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 Phone phone = getPhone(subId);
8307 if (phone == null) {
8308 return;
8309 }
8310 UiccCard uiccCard = phone.getUiccCard();
8311 if (uiccCard == null) {
8312 return;
8313 }
8314 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8315 if (uiccProfile == null) {
8316 return;
8317 }
8318 uiccProfile.refresh();
8319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
8322 }
8323
8324 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008325 * Returns false if the mobile data is disabled by default, otherwise return true.
8326 */
8327 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008328 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008329 }
8330
8331 /**
8332 * Returns true if the data roaming is enabled by default, i.e the system property
8333 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8334 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8335 */
8336 private boolean getDefaultDataRoamingEnabled(int subId) {
8337 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008339 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008340 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8341 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8342 return isDataRoamingEnabled;
8343 }
8344
8345 /**
8346 * Returns the default network type for the given {@code subId}, if the default network type is
8347 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8348 */
8349 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008350 List<Integer> list = TelephonyProperties.default_network();
8351 int phoneId = mSubscriptionController.getPhoneId(subId);
8352 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8353 return list.get(phoneId);
8354 }
8355 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008356 }
fionaxua13278b2018-03-21 00:08:13 -07008357
8358 @Override
8359 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008360 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 final Phone phone = getPhone(subId);
8366 if (phone == null) {
8367 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8368 return;
8369 }
chen xueaba88a2019-03-15 13:15:10 -07008370 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8371 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008372 if (carrierPrivilegeRules == null) {
8373 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8374 } else {
8375 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 } finally {
8378 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008379 }
fionaxua13278b2018-03-21 00:08:13 -07008380 }
8381
8382 @Override
8383 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008384 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 final Phone phone = getPhone(subId);
8389 if (phone == null) {
8390 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8391 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8392 }
8393 return phone.getCarrierIdListVersion();
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008396 }
fionaxua13278b2018-03-21 00:08:13 -07008397 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008398
8399 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008400 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8401 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008403 mApp, subId, callingPackage, callingFeatureId,
8404 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008405 return -1;
8406 }
8407
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
8410 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008415
8416 @Override
8417 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008418 TelephonyPermissions
8419 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008420 mApp, subId, "getCdmaRoamingMode");
8421
8422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
8428 }
8429
8430 @Override
8431 public boolean setCdmaRoamingMode(int subId, int mode) {
8432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8433 mApp, subId, "setCdmaRoamingMode");
8434
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
8443 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008444 public int getCdmaSubscriptionMode(int subId) {
8445 TelephonyPermissions
8446 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8447 mApp, subId, "getCdmaSubscriptionMode");
8448
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 }
8456
8457 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008458 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8460 mApp, subId, "setCdmaSubscriptionMode");
8461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008469
sqianc5eccab2018-10-19 18:46:41 -07008470 @Override
sqian8c685422019-02-22 15:55:18 -08008471 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008472 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008474 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8475 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008476 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8477 }
8478 final long identity = Binder.clearCallingIdentity();
8479 try {
sqian854d44b2018-12-12 16:48:18 -08008480 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8481 for (Phone phone: PhoneFactory.getPhones()) {
8482 if (phone.getEmergencyNumberTracker() != null
8483 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8484 emergencyNumberListInternal.put(
8485 phone.getSubId(),
8486 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8487 }
sqian11b7a0e2018-12-05 18:48:28 -08008488 }
sqian854d44b2018-12-12 16:48:18 -08008489 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008490 } finally {
8491 Binder.restoreCallingIdentity(identity);
8492 }
sqianc5eccab2018-10-19 18:46:41 -07008493 }
8494
8495 @Override
sqian8c685422019-02-22 15:55:18 -08008496 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008497 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008498 if (!exactMatch) {
8499 TelephonyPermissions
8500 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008501 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008502 }
8503 final long identity = Binder.clearCallingIdentity();
8504 try {
sqian854d44b2018-12-12 16:48:18 -08008505 for (Phone phone: PhoneFactory.getPhones()) {
8506 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008507 && phone.getEmergencyNumberTracker()
8508 .isEmergencyNumber(number, exactMatch)) {
8509 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008510 }
sqian11b7a0e2018-12-05 18:48:28 -08008511 }
8512 return false;
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
8516 }
8517
sqianf4ca7ed2019-01-15 18:32:07 -08008518 /**
8519 * Update emergency number list for test mode.
8520 */
8521 @Override
8522 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8523 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8524 "updateEmergencyNumberListTestMode");
8525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 for (Phone phone: PhoneFactory.getPhones()) {
8529 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8530 if (tracker != null) {
8531 tracker.executeEmergencyNumberTestModeCommand(action, num);
8532 }
8533 }
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
8536 }
8537 }
8538
8539 /**
8540 * Get the full emergency number list for test mode.
8541 */
8542 @Override
8543 public List<String> getEmergencyNumberListTestMode() {
8544 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8545 "getEmergencyNumberListTestMode");
8546
8547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 Set<String> emergencyNumbers = new HashSet<>();
8550 for (Phone phone: PhoneFactory.getPhones()) {
8551 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8552 if (tracker != null) {
8553 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8554 emergencyNumbers.add(num.getNumber());
8555 }
8556 }
8557 }
8558 return new ArrayList<>(emergencyNumbers);
8559 } finally {
8560 Binder.restoreCallingIdentity(identity);
8561 }
8562 }
8563
chen xud6b45bd2018-10-30 22:27:10 -07008564 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008565 public int getEmergencyNumberDbVersion(int subId) {
8566 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 final Phone phone = getPhone(subId);
8571 if (phone == null) {
8572 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8573 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8574 }
8575 return phone.getEmergencyNumberDbVersion();
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
8578 }
8579 }
8580
8581 @Override
8582 public void notifyOtaEmergencyNumberDbInstalled() {
8583 enforceModifyPermission();
8584
8585 final long identity = Binder.clearCallingIdentity();
8586 try {
8587 for (Phone phone: PhoneFactory.getPhones()) {
8588 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8589 if (tracker != null) {
8590 tracker.updateOtaEmergencyNumberDatabase();
8591 }
8592 }
8593 } finally {
8594 Binder.restoreCallingIdentity(identity);
8595 }
8596 }
8597
8598 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008599 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008600 enforceActiveEmergencySessionPermission();
8601
8602 final long identity = Binder.clearCallingIdentity();
8603 try {
8604 for (Phone phone: PhoneFactory.getPhones()) {
8605 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8606 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008607 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8608 }
8609 }
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
8612 }
8613 }
8614
8615 @Override
8616 public void resetOtaEmergencyNumberDbFilePath() {
8617 enforceActiveEmergencySessionPermission();
8618
8619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 for (Phone phone: PhoneFactory.getPhones()) {
8622 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8623 if (tracker != null) {
8624 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008625 }
8626 }
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
8629 }
8630 }
8631
8632 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008633 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8634 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8635 Phone phone = getPhone(subId);
8636 if (phone == null) {
8637 return null;
8638 }
8639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 UiccProfile profile = UiccController.getInstance()
8642 .getUiccProfileForPhone(phone.getPhoneId());
8643 if (profile != null) {
8644 return profile.getCertsFromCarrierPrivilegeAccessRules();
8645 }
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 return null;
8650 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008651
8652 /**
8653 * Enable or disable a modem stack.
8654 */
8655 @Override
8656 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8657 enforceModifyPermission();
8658
8659 final long identity = Binder.clearCallingIdentity();
8660 try {
8661 Phone phone = PhoneFactory.getPhone(slotIndex);
8662 if (phone == null) {
8663 return false;
8664 } else {
8665 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8666 }
8667 } finally {
8668 Binder.restoreCallingIdentity(identity);
8669 }
8670 }
Michelecea4cf22018-12-21 15:00:11 -08008671
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008672 /**
8673 * Whether a modem stack is enabled or not.
8674 */
8675 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008676 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8677 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008678 Phone phone = PhoneFactory.getPhone(slotIndex);
8679 if (phone == null) return false;
8680
8681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008682 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8683 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008684 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8685 }
8686
8687 final long identity = Binder.clearCallingIdentity();
8688 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008689 try {
8690 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8691 } catch (NoSuchElementException ex) {
8692 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8693 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008694 } finally {
8695 Binder.restoreCallingIdentity(identity);
8696 }
8697 }
8698
Michelecea4cf22018-12-21 15:00:11 -08008699 @Override
Michele0ea7d782019-03-19 14:58:42 -07008700 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008701 enforceModifyPermission();
8702
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
8705 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008706 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008707 .commit();
8708 } finally {
8709 Binder.restoreCallingIdentity(identity);
8710 }
8711 }
8712
8713 @Override
Michele0ea7d782019-03-19 14:58:42 -07008714 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008715 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008717 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8718 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008719 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008720 }
Michelecea4cf22018-12-21 15:00:11 -08008721
8722 final long identity = Binder.clearCallingIdentity();
8723 try {
Michele0ea7d782019-03-19 14:58:42 -07008724 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008725 } finally {
8726 Binder.restoreCallingIdentity(identity);
8727 }
8728 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008729
Michele0ea7d782019-03-19 14:58:42 -07008730 @TelephonyManager.IsMultiSimSupportedResult
8731 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008732 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8733 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8734 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008735 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8736 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008737 }
8738 // Check if the hardware supports multisim functionality. If usage of multisim is not
8739 // supported by the modem, indicate that it is restricted.
8740 PhoneCapability staticCapability =
8741 mPhoneConfigurationManager.getStaticPhoneCapability();
8742 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008743 loge("isMultiSimSupportedInternal: no static configuration available");
8744 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008745 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008746 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008747 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8748 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008749 }
8750 // Check if support of multiple SIMs is restricted by carrier
8751 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008752 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008753 }
8754
Michele0ea7d782019-03-19 14:58:42 -07008755 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008756 }
8757
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008758 /**
8759 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008760 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8761 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8762 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008763 * @param numOfSims number of active sims we want to switch to
8764 */
8765 @Override
8766 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008767 if (numOfSims == 1) {
8768 enforceModifyPermission();
8769 } else {
8770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8771 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8772 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008773 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008774
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008775 try {
Michele30b57b22019-03-01 12:01:14 -08008776 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008777 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008778 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8779 return;
8780 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008781 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8782 } finally {
8783 Binder.restoreCallingIdentity(identity);
8784 }
8785 }
8786
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008787 @Override
8788 public boolean isApplicationOnUicc(int subId, int appType) {
8789 enforceReadPrivilegedPermission("isApplicationOnUicc");
8790 Phone phone = getPhone(subId);
8791 if (phone == null) {
8792 return false;
8793 }
8794 final long identity = Binder.clearCallingIdentity();
8795 try {
8796 UiccCard uiccCard = phone.getUiccCard();
8797 if (uiccCard == null) {
8798 return false;
8799 }
8800 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8801 if (uiccProfile == null) {
8802 return false;
8803 }
8804 if (TelephonyManager.APPTYPE_SIM <= appType
8805 && appType <= TelephonyManager.APPTYPE_ISIM) {
8806 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8807 }
8808 return false;
8809 } finally {
8810 Binder.restoreCallingIdentity(identity);
8811 }
8812 }
8813
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008814 /**
chen xub4baa772019-04-03 10:23:41 -07008815 * Get whether making changes to modem configurations will trigger reboot.
8816 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008817 */
8818 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008819 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8820 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008822 mApp, subId, callingPackage, callingFeatureId,
8823 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008824 return false;
8825 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008826 final long identity = Binder.clearCallingIdentity();
8827 try {
8828 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
8833
Nathan Harold29f5f052019-02-15 13:41:57 -08008834 private void updateModemStateMetrics() {
8835 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8836 // TODO: check the state for each modem if the api is ready.
8837 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8838 }
8839
Pengquan Meng3889a572019-01-23 11:16:29 -08008840 @Override
8841 public int[] getSlotsMapping() {
8842 enforceReadPrivilegedPermission("getSlotsMapping");
8843
8844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8847 // All logical slots should have a mapping to a physical slot.
8848 int[] logicalSlotsMapping = new int[phoneCount];
8849 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8850 for (int i = 0; i < slotInfos.length; i++) {
8851 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8852 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8853 }
8854 }
8855 return logicalSlotsMapping;
8856 } finally {
8857 Binder.restoreCallingIdentity(identity);
8858 }
8859 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008860
8861 /**
8862 * Get the IRadio HAL Version
8863 */
8864 @Override
8865 public int getRadioHalVersion() {
8866 Phone phone = getDefaultPhone();
8867 if (phone == null) return -1;
8868 HalVersion hv = phone.getHalVersion();
8869 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8870 return hv.major * 100 + hv.minor;
8871 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008872
8873 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008874 * Get the current calling package name.
8875 * @return the current calling package name
8876 */
8877 @Override
8878 public String getCurrentPackageName() {
8879 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8880 }
8881
8882 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008883 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8884 * corresponding network requests on a subId.
8885 *
8886 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008887 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008888 * 2) APN is un-metered for this subscription, or
8889 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008890 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008891 *
8892 * @return whether data is allowed for a apn type.
8893 *
8894 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008895 */
8896 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008897 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008898 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8899 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008900
8901 // Now that all security checks passes, perform the operation as ourselves.
8902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 Phone phone = getPhone(subId);
8905 if (phone == null) return false;
8906
Jack Yu41407ee2019-05-13 16:54:09 -07008907 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008908 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8909 } finally {
8910 Binder.restoreCallingIdentity(identity);
8911 }
8912 }
8913
8914 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008915 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008916 enforceReadPrivilegedPermission("isApnMetered");
8917
8918 // Now that all security checks passes, perform the operation as ourselves.
8919 final long identity = Binder.clearCallingIdentity();
8920 try {
8921 Phone phone = getPhone(subId);
8922 if (phone == null) return true; // By default return true.
8923
Jack Yu41407ee2019-05-13 16:54:09 -07008924 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008925 } finally {
8926 Binder.restoreCallingIdentity(identity);
8927 }
8928 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008929
8930 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008931 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8932 int subscriptionId, IBooleanConsumer resultCallback) {
8933 enforceModifyPermission();
8934 long token = Binder.clearCallingIdentity();
8935 try {
8936 Phone phone = getPhone(subscriptionId);
8937 if (phone == null) {
8938 try {
8939 if (resultCallback != null) {
8940 resultCallback.accept(false);
8941 }
8942 } catch (RemoteException e) {
8943 // ignore
8944 }
8945 return;
8946 }
8947 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8948 Pair.create(specifiers, (x) -> {
8949 try {
8950 if (resultCallback != null) {
8951 resultCallback.accept(x);
8952 }
8953 } catch (RemoteException e) {
8954 // ignore
8955 }
8956 });
8957 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8958 } finally {
8959 Binder.restoreCallingIdentity(token);
8960 }
8961 }
8962
8963 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008964 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8965 TelephonyPermissions
8966 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8967 mApp, subId, "getSystemSelectionChannels");
8968 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 List<RadioAccessSpecifier> specifiers =
8972 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8973 null, subId, workSource);
8974 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8975 return specifiers;
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
8980
8981 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008982 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008983 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008984 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8985 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8986 if (iccRecords == null) {
8987 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8988 return false;
8989 }
8990 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8991 }
8992
8993 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008994 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8995 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008996 if (callingPackage == null) {
8997 callingPackage = getCurrentPackageName();
8998 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008999 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9000 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009001 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9002 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009003 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9004 }
9005 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9006 Intent intent = new Intent();
9007 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9008 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9009 // Bring up choose default SMS subscription dialog right now
9010 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9011 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9012 mApp.startActivity(intent);
9013 }
chen xud5ca2d52019-05-28 15:20:57 -07009014
9015 @Override
9016 public String getMmsUAProfUrl(int subId) {
9017 //TODO investigate if this API should require proper permission check in R b/133791609
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009020 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9021 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9022 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9023 return carrierUAProfUrl;
9024 }
chen xud5ca2d52019-05-28 15:20:57 -07009025 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9026 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
9029 }
9030 }
9031
9032 @Override
9033 public String getMmsUserAgent(int subId) {
9034 //TODO investigate if this API should require proper permission check in R b/133791609
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009037 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9038 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9039 if (!TextUtils.isEmpty(carrierUserAgent)) {
9040 return carrierUserAgent;
9041 }
chen xud5ca2d52019-05-28 15:20:57 -07009042 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9043 .getString(com.android.internal.R.string.config_mms_user_agent);
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
9047 }
Jack Yub07d4972019-05-28 16:12:25 -07009048
9049 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009050 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9051 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9052
9053 final long identity = Binder.clearCallingIdentity();
9054 try {
9055 Phone phone = getPhone(subscriptionId);
9056 if (phone == null) return false;
9057
9058 switch (policy) {
9059 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9060 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9061 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9062 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9063 default:
9064 throw new IllegalArgumentException(policy + " is not a valid policy");
9065 }
9066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
9069 }
9070
9071 @Override
9072 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9073 boolean enabled) {
9074 enforceModifyPermission();
9075
9076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 Phone phone = getPhone(subscriptionId);
9079 if (phone == null) return;
9080
9081 switch (policy) {
9082 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9083 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9084 break;
9085 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9086 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9087 break;
9088 default:
9089 throw new IllegalArgumentException(policy + " is not a valid policy");
9090 }
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
9095
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009096 /**
Hall Liub48cf452020-09-25 11:13:49 -07009097 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009098 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9099 * otherwise.
9100 */
9101 @Override
9102 public void setCepEnabled(boolean isCepEnabled) {
9103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9108 for (Phone phone : PhoneFactory.getPhones()) {
9109 Phone defaultPhone = phone.getImsPhone();
9110 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9111 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9112 ImsPhoneCallTracker imsPhoneCallTracker =
9113 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9114 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9115 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9116 + imsPhone.getMsisdn());
9117 }
9118 }
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
9121 }
9122 }
allenwtsu46dcc572020-01-08 18:24:03 +08009123
9124 /**
9125 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9126 *
9127 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9128 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9129 * before being read.
9130 */
9131 @Override
9132 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9133 isCompressed) {
9134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9135 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009136 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9137 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9138 }
9139 if (!isImsAvailableOnDevice()) {
9140 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9141 "IMS not available on device.");
9142 }
9143
9144 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009145 try {
Hui Wang068ab862020-10-31 05:12:53 +00009146 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009149 }
9150 }
zoey chenf95ca592019-12-30 16:11:23 +08009151
9152 @Override
9153 public boolean isIccLockEnabled(int subId) {
9154 enforceReadPrivilegedPermission("isIccLockEnabled");
9155
9156 // Now that all security checks passes, perform the operation as ourselves.
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 Phone phone = getPhone(subId);
9160 if (phone != null && phone.getIccCard() != null) {
9161 return phone.getIccCard().getIccLockEnabled();
9162 } else {
9163 return false;
9164 }
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
9169
9170 /**
zoey chene02881a2019-12-30 16:11:23 +08009171 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009172 *
zoey chene02881a2019-12-30 16:11:23 +08009173 * @return an integer representing the status of IccLock enabled or disabled in the following
9174 * three cases:
9175 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9176 * successfully.
9177 * - Positive number and zero for remaining password attempts.
9178 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009179 *
9180 */
9181 @Override
9182 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9183 enforceModifyPermission();
9184
9185 Phone phone = getPhone(subId);
9186 if (phone == null) {
9187 return 0;
9188 }
9189 // Now that all security checks passes, perform the operation as ourselves.
9190 final long identity = Binder.clearCallingIdentity();
9191 try {
9192 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9193 new Pair<Boolean, String>(enabled, password), phone, null);
9194 return attemptsRemaining;
9195
9196 } catch (Exception e) {
9197 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
9201 return 0;
9202 }
9203
9204 /**
9205 * Change the ICC password used in ICC pin lock.
9206 *
zoey chene02881a2019-12-30 16:11:23 +08009207 * @return an integer representing the status of IccLock changed in the following three cases:
9208 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9209 * - Positive number and zero for remaining password attempts.
9210 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009211 *
9212 */
9213 @Override
9214 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9215 enforceModifyPermission();
9216
9217 Phone phone = getPhone(subId);
9218 if (phone == null) {
9219 return 0;
9220 }
9221 // Now that all security checks passes, perform the operation as ourselves.
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9225 new Pair<String, String>(oldPassword, newPassword), phone, null);
9226 return attemptsRemaining;
9227
9228 } catch (Exception e) {
9229 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
9233 return 0;
9234 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009235
Peter Wangdafb9ac2020-01-15 14:13:38 -08009236 /**
9237 * Request for receiving user activity notification
9238 */
9239 @Override
9240 public void requestUserActivityNotification() {
9241 if (!mNotifyUserActivity.get()
9242 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9243 mNotifyUserActivity.set(true);
9244 }
9245 }
9246
9247 /**
9248 * Called when userActivity is signalled in the power manager.
9249 * This is safe to call from any thread, with any window manager locks held or not.
9250 */
9251 @Override
9252 public void userActivity() {
9253 // ***************************************
9254 // * Inherited from PhoneWindowManager *
9255 // ***************************************
9256 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9257 // WITH ITS LOCKS HELD.
9258 //
9259 // This code must be VERY careful about the locks
9260 // it acquires.
9261 // In fact, the current code acquires way too many,
9262 // and probably has lurking deadlocks.
9263
9264 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9265 throw new SecurityException("Only the OS may call notifyUserActivity()");
9266 }
9267
9268 if (mNotifyUserActivity.getAndSet(false)) {
9269 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9270 USER_ACTIVITY_NOTIFICATION_DELAY);
9271 }
9272 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009273
Malcolm Chen884180b2020-04-13 11:59:40 -07009274 @Override
9275 public boolean canConnectTo5GInDsdsMode() {
9276 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9277 }
Jack Yud10cdd42020-09-28 20:28:01 -07009278
9279 @Override
9280 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9281 String callingFeatureId) {
9282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9283 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9284 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9285 }
9286
9287 Phone phone = getPhone(subId);
9288 if (phone == null) {
9289 throw new RuntimeException("phone is not available");
9290 }
9291 // Now that all security checks passes, perform the operation as ourselves.
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 return phone.getEquivalentHomePlmns();
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009299
Hui Wang0866fcc2020-10-12 12:14:23 -07009300 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009301 public boolean isRadioInterfaceCapabilitySupported(
9302 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009303 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009304 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009305 if (radioInterfaceCapabilities == null) {
9306 throw new RuntimeException("radio interface capabilities are not available");
9307 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009308 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009309 }
9310 }
9311
9312 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009313 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9314 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009315 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9316 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9317 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9318 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9319 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009320 if (DBG) {
9321 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9322 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9323 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9324 }
9325
9326 if (!SubscriptionManager.isValidSubscriptionId(subId)
9327 || appType < TelephonyManager.APPTYPE_UNKNOWN
9328 || appType > TelephonyManager.APPTYPE_ISIM
9329 || nafUrl == null || securityProtocol == null || callback == null) {
9330 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9331 if (callback != null) {
9332 try {
9333 callback.onAuthenticationFailure(
9334 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9335 } catch (RemoteException exception) {
9336 log("Fail to notify onAuthenticationFailure due to " + exception);
9337 }
9338 return;
9339 }
9340 }
9341
9342 final long token = Binder.clearCallingIdentity();
9343 try {
9344 getGbaManager(subId).bootstrapAuthenticationRequest(
9345 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9346 forceBootStrapping, callback));
9347 } finally {
9348 Binder.restoreCallingIdentity(token);
9349 }
9350 }
9351
Jack Nudelman24d51a52020-11-24 12:08:04 -08009352 /**
9353 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9354 * requested radio power state will actually be set. See {@link
9355 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9356 *
9357 * @param subId the subscription ID of the phone requesting to set the radio power state.
9358 * @param enable {@code true} if trying to turn radio on.
9359 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9360 * false}.
9361 */
9362 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9363 Phone phone = getPhone(subId);
9364 if (phone != null) {
9365 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9366 return true;
9367 }
9368 return false;
9369 }
9370
9371 private int handleDataThrottlingRequest(int subId,
9372 DataThrottlingRequest dataThrottlingRequest) {
9373 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9374 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9375 if (!setRadioPowerForThermal(subId, true)) {
9376 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9377 }
9378
9379 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9380
9381 int thermalMitigationResult =
9382 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9383 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9384 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9385 }
9386 return thermalMitigationResult;
9387 }
9388
9389 /**
9390 * Thermal mitigation request to control functionalities at modem.
9391 *
9392 * @param subId the id of the subscription.
9393 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9394 *
9395 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9396 */
9397 @Override
9398 @ThermalMitigationResult
9399 public int sendThermalMitigationRequest(
9400 int subId,
9401 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9402 enforceModifyPermission();
9403
9404 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9405 final long identity = Binder.clearCallingIdentity();
9406
9407 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9408 try {
9409 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9410 switch (thermalMitigationAction) {
9411 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9412 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009413 handleDataThrottlingRequest(subId,
9414 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009415 break;
9416 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9417 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9418 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9419 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9420 }
9421
9422 // Ensure that radio is on. If not able to power on due to phone being
9423 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9424 if (!setRadioPowerForThermal(subId, true)) {
9425 thermalMitigationResult =
9426 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9427 break;
9428 }
9429
9430 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9431 false);
9432 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9433 break;
9434 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9435 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9436 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9437 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9438 }
9439
9440 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9441 if (registry != null) {
9442 TelephonyConnectionService service =
9443 registry.getTelephonyConnectionService();
9444 Phone phone = getPhone(subId);
9445 if (phone == null) {
9446 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009447 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009448 break;
9449 }
9450
9451 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009452 != TelephonyManager.CALL_STATE_IDLE
9453 || phone.isInEmergencySmsMode() || phone.isInEcm()
9454 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009455 String errorMessage = "Phone state is not valid. call state = "
9456 + PhoneConstantConversions.convertCallState(phone.getState())
9457 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9458 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9459 errorMessage += service == null
9460 ? " TelephonyConnectionService is null"
9461 : " isEmergencyCallPending = "
9462 + service.isEmergencyCallPending();
9463 Log.e(LOG_TAG, errorMessage);
9464 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009465 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009466 break;
9467 }
9468 } else {
9469 thermalMitigationResult =
9470 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9471 break;
9472 }
9473
9474 // Turn radio off. If not able to power off due to phone being unavailable,
9475 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9476 if (!setRadioPowerForThermal(subId, false)) {
9477 thermalMitigationResult =
9478 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9479 break;
9480 }
9481 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009482 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009483 break;
9484 default:
9485 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9486 + "not exist. Requested action: " + thermalMitigationAction);
9487 }
9488 } catch (IllegalArgumentException e) {
9489 throw e;
9490 } catch (Exception e) {
9491 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9492 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9493 } finally {
9494 Binder.restoreCallingIdentity(identity);
9495 }
9496
9497 if (DBG) {
9498 log("thermalMitigationRequest returning with thermalMitigationResult: "
9499 + thermalMitigationResult);
9500 }
9501
9502 return thermalMitigationResult;
9503 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009504
9505 /**
9506 * Set the GbaService Package Name that Telephony will bind to.
9507 *
9508 * @param subId The sim that the GbaService is associated with.
9509 * @param packageName The name of the package to be replaced with.
9510 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9511 */
9512 @Override
9513 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9514 enforceModifyPermission();
9515
9516 final long identity = Binder.clearCallingIdentity();
9517 try {
9518 return getGbaManager(subId).overrideServicePackage(packageName);
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
9523
9524 /**
9525 * Return the package name of the currently bound GbaService.
9526 *
9527 * @param subId The sim that the GbaService is associated with.
9528 * @return the package name of the GbaService configuration, null if GBA is not supported.
9529 */
9530 @Override
9531 public String getBoundGbaService(int subId) {
9532 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9533
9534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 return getGbaManager(subId).getServicePackage();
9537 } finally {
9538 Binder.restoreCallingIdentity(identity);
9539 }
9540 }
9541
9542 /**
9543 * Set the release time for telephony to unbind GbaService.
9544 *
9545 * @param subId The sim that the GbaService is associated with.
9546 * @param interval The release time to unbind GbaService by millisecond.
9547 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9548 */
9549 @Override
9550 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9551 enforceModifyPermission();
9552
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
9555 return getGbaManager(subId).overrideReleaseTime(interval);
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
9561 /**
9562 * Return the release time for telephony to unbind GbaService.
9563 *
9564 * @param subId The sim that the GbaService is associated with.
9565 * @return The release time to unbind GbaService by millisecond.
9566 */
9567 @Override
9568 public int getGbaReleaseTime(int subId) {
9569 enforceReadPrivilegedPermission("getGbaReleaseTime");
9570
9571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 return getGbaManager(subId).getReleaseTime();
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 private GbaManager getGbaManager(int subId) {
9580 GbaManager instance = GbaManager.getInstance(subId);
9581 if (instance == null) {
9582 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9583 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9584 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9585 }
9586 return instance;
9587 }
Hui Wang068ab862020-10-31 05:12:53 +00009588
9589 /**
9590 * indicate whether the device and the carrier can support
9591 * RCS VoLTE single registration.
9592 */
9593 @Override
9594 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009595 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9596 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9597 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9598 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009599
9600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9601 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9602 }
9603
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
9606 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9607 if (rpm != null) {
9608 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9609 }
9610 return false;
9611 } finally {
9612 Binder.restoreCallingIdentity(identity);
9613 }
9614 }
9615
9616 /**
9617 * Register RCS provisioning callback.
9618 */
9619 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009620 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009621 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009622 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009623 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009624 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9625 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009626
9627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9628 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9629 }
9630 if (!isImsAvailableOnDevice()) {
9631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9632 "IMS not available on device.");
9633 }
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009637 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009638 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009639 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9640 "Service not available for the subscription.");
9641 }
Hui Wang068ab862020-10-31 05:12:53 +00009642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
9646
9647 /**
9648 * Unregister RCS provisioning callback.
9649 */
9650 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009651 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009652 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009653 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009654 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009655 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9656 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009657
9658 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9659 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9660 }
9661 if (!isImsAvailableOnDevice()) {
9662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9663 "IMS not available on device.");
9664 }
9665
9666 final long identity = Binder.clearCallingIdentity();
9667 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009668 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009669 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
9675 /**
9676 * trigger RCS reconfiguration.
9677 */
9678 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009679 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9680 "triggerRcsReconfiguration",
9681 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009682
9683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9684 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9685 }
9686 if (!isImsAvailableOnDevice()) {
9687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9688 "IMS not available on device.");
9689 }
9690
9691 final long identity = Binder.clearCallingIdentity();
9692 try {
9693 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
9699 /**
9700 * Provide the client configuration parameters of the RCS application.
9701 */
9702 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009703 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9704 "setRcsClientConfiguration",
9705 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009706
9707 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9708 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9709 }
9710 if (!isImsAvailableOnDevice()) {
9711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9712 "IMS not available on device.");
9713 }
9714
9715 final long identity = Binder.clearCallingIdentity();
9716
9717 try {
9718 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9719 if (configBinder == null) {
9720 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9721 } else {
9722 configBinder.setRcsClientConfiguration(rcc);
9723 }
9724 } catch (RemoteException e) {
9725 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
9731 /**
Hui Wang19a21872021-02-19 20:45:36 -08009732 * Enables or disables the test mode for RCS VoLTE single registration.
9733 */
9734 @Override
9735 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9737 "setRcsSingleRegistrationTestModeEnabled");
9738
9739 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9740 }
9741
9742 /**
9743 * Gets the test mode for RCS VoLTE single registration.
9744 */
9745 @Override
9746 public boolean getRcsSingleRegistrationTestModeEnabled() {
9747 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9748 "getRcsSingleRegistrationTestModeEnabled");
9749
9750 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9751 }
9752
9753 /**
Hui Wang068ab862020-10-31 05:12:53 +00009754 * Overrides the config of RCS VoLTE single registration enabled for the device.
9755 */
9756 @Override
9757 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9759 "setDeviceSingleRegistrationEnabledOverride");
9760 enforceModifyPermission();
9761
9762 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9763 : Boolean.parseBoolean(enabledStr);
9764 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009765 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009766 }
9767
9768 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009769 * Sends a device to device communication message. Only usable via shell.
9770 * @param message message to send.
9771 * @param value message value.
9772 */
9773 @Override
9774 public void sendDeviceToDeviceMessage(int message, int value) {
9775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9776 "setCarrierSingleRegistrationEnabledOverride");
9777 enforceModifyPermission();
9778
9779 final long identity = Binder.clearCallingIdentity();
9780 try {
9781 TelephonyConnectionService service =
9782 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9783 if (service == null) {
9784 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9785 return;
9786 }
9787 service.sendTestDeviceToDeviceMessage(message, value);
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792
9793
9794 /**
Hui Wang068ab862020-10-31 05:12:53 +00009795 * Gets the config of RCS VoLTE single registration enabled for the device.
9796 */
9797 @Override
9798 public boolean getDeviceSingleRegistrationEnabled() {
9799 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9800 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9801 }
9802
9803 /**
9804 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9805 */
9806 @Override
9807 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9809 "setCarrierSingleRegistrationEnabledOverride");
9810 enforceModifyPermission();
9811
9812 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9813 : Boolean.parseBoolean(enabledStr);
9814 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9815 subId, enabled);
9816 }
9817
9818 /**
9819 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9820 */
9821 @Override
9822 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9823 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9824 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9825 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009826
9827 /**
9828 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9829 * their mobile plan.
9830 */
9831 @Override
9832 public String getMobileProvisioningUrl() {
9833 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9834 final long identity = Binder.clearCallingIdentity();
9835 try {
9836 return getDefaultPhone().getMobileProvisioningUrl();
9837 } finally {
9838 Binder.restoreCallingIdentity(identity);
9839 }
9840 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009841
James.cf Linbcdf8b32021-01-14 16:44:13 +08009842 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009843 * Get the EAB contact from the EAB database.
9844 */
9845 @Override
9846 public String getContactFromEab(String contact) {
9847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9848 enforceModifyPermission();
9849 final long identity = Binder.clearCallingIdentity();
9850 try {
9851 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009858 * Remove the EAB contacts from the EAB database.
9859 */
9860 @Override
9861 public int removeContactFromEab(int subId, String contacts) {
9862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9863 enforceModifyPermission();
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
9866 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
9871
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009872 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009873 public boolean getDeviceUceEnabled() {
9874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9875 final long identity = Binder.clearCallingIdentity();
9876 try {
9877 return mApp.getDeviceUceEnabled();
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
9882
9883 @Override
9884 public void setDeviceUceEnabled(boolean isEnabled) {
9885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9886 final long identity = Binder.clearCallingIdentity();
9887 try {
9888 mApp.setDeviceUceEnabled(isEnabled);
9889 } finally {
9890 Binder.restoreCallingIdentity(identity);
9891 }
9892 }
9893
Brad Ebingerd4c5bde2021-02-12 06:18:28 +00009894 /**
9895 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
9896 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9897 */
9898 // Used for SHELL command only right now.
9899 @Override
9900 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
9901 List<String> featureTags) {
9902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9903 "addUceRegistrationOverrideShell");
9904 final long identity = Binder.clearCallingIdentity();
9905 try {
9906 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
9907 new ArraySet<>(featureTags));
9908 } catch (ImsException e) {
9909 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
9912 }
9913 }
9914
9915 /**
9916 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
9917 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9918 */
9919 // Used for SHELL command only right now.
9920 @Override
9921 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
9922 List<String> featureTags) {
9923 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9924 "removeUceRegistrationOverrideShell");
9925 final long identity = Binder.clearCallingIdentity();
9926 try {
9927 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
9928 new ArraySet<>(featureTags));
9929 } catch (ImsException e) {
9930 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934 }
9935
9936 /**
9937 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
9938 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9939 */
9940 // Used for SHELL command only right now.
9941 @Override
9942 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
9943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9944 "clearUceRegistrationOverrideShell");
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
9947 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
9948 } catch (ImsException e) {
9949 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
9955 /**
9956 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9957 */
9958 // Used for SHELL command only right now.
9959 @Override
9960 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
9961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9962 "getLatestRcsContactUceCapabilityShell");
9963 final long identity = Binder.clearCallingIdentity();
9964 try {
9965 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
9966 } catch (ImsException e) {
9967 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9968 } finally {
9969 Binder.restoreCallingIdentity(identity);
9970 }
9971 }
9972
9973 /**
9974 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
9975 * device does not have an active PUBLISH.
9976 */
9977 // Used for SHELL command only right now.
9978 @Override
9979 public String getLastUcePidfXmlShell(int subId) {
9980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
9981 final long identity = Binder.clearCallingIdentity();
9982 try {
9983 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
9984 } catch (ImsException e) {
9985 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9986 } finally {
9987 Binder.restoreCallingIdentity(identity);
9988 }
9989 }
9990
9991
James.cf Lin4b784aa2021-01-31 03:25:15 +08009992 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009993 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9994 String callingPackage) {
9995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9996 mApp, subId, "setSignalStrengthUpdateRequest");
9997
9998 final int callingUid = Binder.getCallingUid();
9999 // Verify that tha callingPackage belongs to the calling UID
10000 mApp.getSystemService(AppOpsManager.class)
10001 .checkPackage(callingUid, callingPackage);
10002
10003 validateSignalStrengthUpdateRequest(request, callingUid);
10004
10005 final long identity = Binder.clearCallingIdentity();
10006 try {
10007 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10008 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10009
10010 if (result instanceof IllegalStateException) {
10011 throw (IllegalStateException) result;
10012 }
10013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 }
10017
10018 @Override
10019 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10020 String callingPackage) {
10021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10022 mApp, subId, "clearSignalStrengthUpdateRequest");
10023
10024 final int callingUid = Binder.getCallingUid();
10025 // Verify that tha callingPackage belongs to the calling UID
10026 mApp.getSystemService(AppOpsManager.class)
10027 .checkPackage(callingUid, callingPackage);
10028
10029 final long identity = Binder.clearCallingIdentity();
10030 try {
10031 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10032 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10033
10034 if (result instanceof IllegalStateException) {
10035 throw (IllegalStateException) result;
10036 }
10037 } finally {
10038 Binder.restoreCallingIdentity(identity);
10039 }
10040 }
10041
10042 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10043 int callingUid) {
10044 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10045 // phone/system process do not have further restriction on request
10046 return;
10047 }
10048
10049 // Applications has restrictions on how to use the request:
10050 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10051 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10052 // This is not system caller which has been checked above
10053 throw new IllegalArgumentException(
10054 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10055 }
10056
10057 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10058 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10059 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10060 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10061 || info.isEnabled()) {
10062 throw new IllegalArgumentException(
10063 "Only system can set hide fields in SignalThresholdInfo");
10064 }
10065
10066 // Thresholds length for each RAN need in range. This has been validated in
10067 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10068 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10069 final int[] thresholds = info.getThresholds();
10070 Objects.requireNonNull(thresholds);
10071 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10072 || thresholds.length
10073 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10074 throw new IllegalArgumentException(
10075 "thresholds length is out of range: " + thresholds.length);
10076 }
10077 }
10078 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010079
10080 /**
10081 * Prepare TelephonyManager for an unattended reboot. The reboot is
10082 * required to be done shortly after the API is invoked.
10083 */
10084 @Override
10085 @TelephonyManager.PrepareUnattendedRebootResult
10086 public int prepareForUnattendedReboot() {
10087 enforceRebootPermission();
10088
10089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010096}