blob: f093e0624a4987d67381f5001a6e1aaa4930e177 [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;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070070import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070071import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080072import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070073import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080074import android.telephony.CellIdentityCdma;
75import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070077import android.telephony.CellInfoGsm;
78import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070079import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080080import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070081import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070082import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070083import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080084import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070085import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080086import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070087import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080088import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080089import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070090import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800162import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800163import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700164import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700165import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800167import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800168import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800169import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700170import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800171import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700172import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800173import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700174import com.android.internal.telephony.imsphone.ImsPhone;
175import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800176import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900177import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800179import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700182import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800183import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000186import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800187import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700188import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700189import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800190import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700191import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800193import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700194import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700195import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800196import com.android.services.telephony.TelecomAccountRegistry;
197import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800198import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800199
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700200import java.io.FileDescriptor;
201import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800204import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800206import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100207import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700209import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800210import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800211import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800212import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800213import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214
215/**
216 * Implementation of the ITelephony interface.
217 */
Santos Cordon117fee72014-05-16 17:56:12 -0700218public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 private static final String LOG_TAG = "PhoneInterfaceManager";
220 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
221 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223
224 // Message codes used with mMainThreadHandler
225 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700226 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
227 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228 private static final int CMD_OPEN_CHANNEL = 9;
229 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
230 private static final int CMD_CLOSE_CHANNEL = 11;
231 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800232 private static final int CMD_NV_READ_ITEM = 13;
233 private static final int EVENT_NV_READ_ITEM_DONE = 14;
234 private static final int CMD_NV_WRITE_ITEM = 15;
235 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
236 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
237 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700238 private static final int CMD_RESET_MODEM_CONFIG = 19;
239 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800240 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
241 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800242 private static final int CMD_SEND_ENVELOPE = 25;
243 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000244 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
245 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700246 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
247 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
248 private static final int CMD_EXCHANGE_SIM_IO = 31;
249 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800250 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
251 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700252 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
253 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700254 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
255 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700256 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
257 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
258 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
259 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700260 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
261 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
262 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
263 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700264 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800265 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
266 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000267 private static final int CMD_SWITCH_SLOTS = 50;
268 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700269 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
270 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
271 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
272 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
273 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
274 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
275 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
276 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700277 private static final int CMD_GET_ALL_CELL_INFO = 60;
278 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
279 private static final int CMD_GET_CELL_LOCATION = 62;
280 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700281 private static final int CMD_MODEM_REBOOT = 64;
282 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700283 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
284 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800285 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
286 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700287 private static final int CMD_GET_MODEM_STATUS = 70;
288 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700289 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
290 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700291 private static final int CMD_ERASE_MODEM_CONFIG = 74;
292 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800293 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
294 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
295 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
296 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800297 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
298 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800299 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800300 private static final int CMD_GET_CALL_FORWARDING = 83;
301 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
302 private static final int CMD_SET_CALL_FORWARDING = 85;
303 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
304 private static final int CMD_GET_CALL_WAITING = 87;
305 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
306 private static final int CMD_SET_CALL_WAITING = 89;
307 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700308 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
309 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
310 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
311 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700312 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
313 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800314 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
315 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800316 private static final int CMD_SET_DATA_THROTTLING = 99;
317 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800318 private static final int CMD_SET_SIM_POWER = 101;
319 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800320 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
321 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
322 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
323 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800324 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
325 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000326 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800328 // Parameters of select command.
329 private static final int SELECT_COMMAND = 0xA4;
330 private static final int SELECT_P1 = 0x04;
331 private static final int SELECT_P2 = 0;
332 private static final int SELECT_P3 = 0x10;
333
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 /** The singleton instance. */
335 private static PhoneInterfaceManager sInstance;
336
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800339 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700340 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private AppOpsManager mAppOps;
342 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800343 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800344 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700345 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800346 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
Peter Wangdafb9ac2020-01-15 14:13:38 -0800348 /** User Activity */
349 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
351
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700352 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
353
Derek Tan97ebb422014-09-05 16:55:38 -0700354 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
355 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800356 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800357 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700358
Michelecea4cf22018-12-21 15:00:11 -0800359 // String to store multi SIM allowed
360 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
361
Derek Tan740e1672017-06-27 14:56:27 -0700362 // The AID of ISD-R.
363 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
364
yinxub1bed742017-04-17 11:45:04 -0700365 private NetworkScanRequestTracker mNetworkScanRequestTracker;
366
David Kelly5e06a7f2018-03-12 14:10:59 +0000367 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
368 private static final int MANUFACTURER_CODE_LENGTH = 8;
369
Jack Nudelman24d51a52020-11-24 12:08:04 -0800370 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
371
Derek Tan89e89d42014-07-08 17:00:10 -0700372 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700373 * Experiment flag to enable erase modem config on reset network, default value is false
374 */
375 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
376 "reset_network_erase_modem_config_enabled";
377
Rambo Wang0f050d82021-02-12 11:43:36 -0800378 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
379
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700380 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700381 * A request object to use for transmitting data to an ICC.
382 */
383 private static final class IccAPDUArgument {
384 public int channel, cla, command, p1, p2, p3;
385 public String data;
386
387 public IccAPDUArgument(int channel, int cla, int command,
388 int p1, int p2, int p3, String data) {
389 this.channel = channel;
390 this.cla = cla;
391 this.command = command;
392 this.p1 = p1;
393 this.p2 = p2;
394 this.p3 = p3;
395 this.data = data;
396 }
397 }
398
399 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700400 * A request object to use for transmitting data to an ICC.
401 */
402 private static final class ManualNetworkSelectionArgument {
403 public OperatorInfo operatorInfo;
404 public boolean persistSelection;
405
406 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
407 this.operatorInfo = operatorInfo;
408 this.persistSelection = persistSelection;
409 }
410 }
411
412 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
414 * request after sending. The main thread will notify the request when it is complete.
415 */
416 private static final class MainThreadRequest {
417 /** The argument to use for the request */
418 public Object argument;
419 /** The result of the request that is run on the main thread */
420 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800421 // The subscriber id that this request applies to. Defaults to
422 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
423 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Nathan Harold92bed182018-10-12 18:16:49 -0700425 // In cases where subId is unavailable, the caller needs to specify the phone.
426 public Phone phone;
427
vagdeviaf9a5b92018-08-15 16:01:53 -0700428 public WorkSource workSource;
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 public MainThreadRequest(Object argument) {
431 this.argument = argument;
432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800433
Nathan Harold92bed182018-10-12 18:16:49 -0700434 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
435 this.argument = argument;
436 if (phone != null) {
437 this.phone = phone;
438 }
439 this.workSource = workSource;
440 }
441
vagdeviaf9a5b92018-08-15 16:01:53 -0700442 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800444 if (subId != null) {
445 this.subId = subId;
446 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700447 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 }
450
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800451 private static final class IncomingThirdPartyCallArgs {
452 public final ComponentName component;
453 public final String callId;
454 public final String callerDisplayName;
455
456 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
457 String callerDisplayName) {
458 this.component = component;
459 this.callId = callId;
460 this.callerDisplayName = callerDisplayName;
461 }
462 }
463
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 /**
465 * A handler that processes messages on the main thread in the phone process. Since many
466 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
467 * inbound binder threads to the main thread in the phone process. The Binder thread
468 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
469 * on, which will be notified when the operation completes and will contain the result of the
470 * request.
471 *
472 * <p>If a MainThreadRequest object is provided in the msg.obj field,
473 * note that request.result must be set to something non-null for the calling thread to
474 * unblock.
475 */
476 private final class MainThreadHandler extends Handler {
477 @Override
478 public void handleMessage(Message msg) {
479 MainThreadRequest request;
480 Message onCompleted;
481 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800484 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
486 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 case CMD_HANDLE_USSD_REQUEST: {
488 request = (MainThreadRequest) msg.obj;
489 final Phone phone = getPhoneFromRequest(request);
490 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
491 String ussdRequest = ussdObject.first;
492 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700493
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 if (!isUssdApiAllowed(request.subId)) {
495 // Carrier does not support use of this API, return failure.
496 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
497 UssdResponse response = new UssdResponse(ussdRequest, null);
498 Bundle returnData = new Bundle();
499 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
500 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700501
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 request.result = true;
503 notifyRequester(request);
504 return;
505 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700506
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 try {
508 request.result = phone != null
509 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
510 } catch (CallStateException cse) {
511 request.result = false;
512 }
513 // Wake up the requesting thread
514 notifyRequester(request);
515 break;
pkanwar32d516d2016-10-14 19:37:38 -0700516 }
517
Yorke Lee716f67e2015-06-17 15:39:16 -0700518 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 final Phone phone = getPhoneFromRequest(request);
521 request.result = phone != null ?
522 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
523 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800532 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 if (uiccCard == null) {
534 loge("iccTransmitApduLogicalChannel: No UICC");
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
539 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 iccArgument.channel, iccArgument.cla, iccArgument.command,
542 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 break;
546
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 ar = (AsyncResult) msg.obj;
549 request = (MainThreadRequest) ar.userObj;
550 if (ar.exception == null && ar.result != null) {
551 request.result = ar.result;
552 } else {
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
554 if (ar.result == null) {
555 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800556 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800558 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 } else {
560 loge("iccTransmitApduLogicalChannel: Unknown exception");
561 }
562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
568 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800569 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (uiccCard == null) {
571 loge("iccTransmitApduBasicChannel: No UICC");
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
576 request);
577 uiccCard.iccTransmitApduBasicChannel(
578 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
579 iccArgument.p3, iccArgument.data, onCompleted);
580 }
581 break;
582
583 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
586 if (ar.exception == null && ar.result != null) {
587 request.result = ar.result;
588 } else {
589 request.result = new IccIoResult(0x6F, 0, (byte[])null);
590 if (ar.result == null) {
591 loge("iccTransmitApduBasicChannel: Empty response");
592 } else if (ar.exception instanceof CommandException) {
593 loge("iccTransmitApduBasicChannel: CommandException: " +
594 ar.exception);
595 } else {
596 loge("iccTransmitApduBasicChannel: Unknown exception");
597 }
598 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 break;
601
602 case CMD_EXCHANGE_SIM_IO:
603 request = (MainThreadRequest) msg.obj;
604 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800605 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 if (uiccCard == null) {
607 loge("iccExchangeSimIO: No UICC");
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 } else {
611 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
612 request);
613 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
614 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
615 iccArgument.data, onCompleted);
616 }
617 break;
618
619 case EVENT_EXCHANGE_SIM_IO_DONE:
620 ar = (AsyncResult) msg.obj;
621 request = (MainThreadRequest) ar.userObj;
622 if (ar.exception == null && ar.result != null) {
623 request.result = ar.result;
624 } else {
625 request.result = new IccIoResult(0x6f, 0, (byte[])null);
626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 break;
629
Derek Tan4d5e5c12014-02-04 11:54:58 -0800630 case CMD_SEND_ENVELOPE:
631 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800632 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 if (uiccCard == null) {
634 loge("sendEnvelopeWithStatus: No UICC");
635 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 } else {
638 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
639 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
640 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 break;
642
643 case EVENT_SEND_ENVELOPE_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700649 request.result = new IccIoResult(0x6F, 0, (byte[])null);
650 if (ar.result == null) {
651 loge("sendEnvelopeWithStatus: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("sendEnvelopeWithStatus: CommandException: " +
654 ar.exception);
655 } else {
656 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
657 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 break;
661
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 case CMD_OPEN_CHANNEL:
663 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800664 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800665 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 if (uiccCard == null) {
667 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800668 request.result = new IccOpenLogicalChannelResponse(-1,
669 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 } else {
672 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800673 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
674 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case EVENT_OPEN_CHANNEL_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 int[] result = (int[]) ar.result;
684 int channelId = result[0];
685 byte[] selectResponse = null;
686 if (result.length > 1) {
687 selectResponse = new byte[result.length - 1];
688 for (int i = 1; i < result.length; ++i) {
689 selectResponse[i - 1] = (byte) result[i];
690 }
691 }
692 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700693 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 if (ar.result == null) {
696 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 if (ar.exception != null) {
699 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
700 }
701
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700703 if (ar.exception instanceof CommandException) {
704 CommandException.Error error =
705 ((CommandException) (ar.exception)).getCommandError();
706 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700708 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(
713 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700715 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
719 case CMD_CLOSE_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800721 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 if (uiccCard == null) {
723 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900724 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 } else {
727 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
728 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
729 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 break;
731
732 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800733 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
734 break;
735
736 case CMD_NV_READ_ITEM:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
740 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
743 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 ar = (AsyncResult) msg.obj;
745 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800746 if (ar.exception == null && ar.result != null) {
747 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800749 request.result = "";
750 if (ar.result == null) {
751 loge("nvReadItem: Empty response");
752 } else if (ar.exception instanceof CommandException) {
753 loge("nvReadItem: CommandException: " +
754 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800756 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
Jake Hambye994d462014-02-03 13:10:13 -0800762 case CMD_NV_WRITE_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
765 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700767 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800768 break;
769
770 case EVENT_NV_WRITE_ITEM_DONE:
771 handleNullReturnEvent(msg, "nvWriteItem");
772 break;
773
774 case CMD_NV_WRITE_CDMA_PRL:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800777 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
780 case EVENT_NV_WRITE_CDMA_PRL_DONE:
781 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
782 break;
783
chen xu6dac5ab2018-10-26 17:39:23 -0700784 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800785 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700786 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
chen xu6dac5ab2018-10-26 17:39:23 -0700790 case EVENT_RESET_MODEM_CONFIG_DONE:
791 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700794 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
797 request);
798 Phone phone = getPhoneFromRequest(request);
799 if (phone != null) {
800 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
801 } else {
802 loge("isNRDualConnectivityEnabled: No phone object");
803 request.result = false;
804 notifyRequester(request);
805 }
806 break;
807 }
808
809 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 // request.result must be set to something non-null
816 // for the calling thread to unblock
817 if (request.result != null) {
818 request.result = ar.result;
819 } else {
820 request.result = false;
821 }
822 if (ar.result == null) {
823 loge("isNRDualConnectivityEnabled: Empty response");
824 } else if (ar.exception instanceof CommandException) {
825 loge("isNRDualConnectivityEnabled: CommandException: "
826 + ar.exception);
827 } else {
828 loge("isNRDualConnectivityEnabled: Unknown exception");
829 }
830 }
831 notifyRequester(request);
832 break;
833
834 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
837 Phone phone = getPhoneFromRequest(request);
838 if (phone != null) {
839 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
840 request.workSource);
841 } else {
842 loge("enableNrDualConnectivity: No phone object");
843 request.result =
844 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
845 notifyRequester(request);
846 }
847 break;
848 }
849
850 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null) {
854 request.result =
855 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
856 } else {
857 request.result =
858 TelephonyManager
859 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
860 if (ar.exception instanceof CommandException) {
861 CommandException.Error error =
862 ((CommandException) (ar.exception)).getCommandError();
863 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
864 request.result =
865 TelephonyManager
866 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000867 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
868 request.result =
869 TelephonyManager
870 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700871 }
872 loge("enableNrDualConnectivity" + ": CommandException: "
873 + ar.exception);
874 } else {
875 loge("enableNrDualConnectivity" + ": Unknown exception");
876 }
877 }
878 notifyRequester(request);
879 break;
880 }
881
SongFerngWang9e060372020-12-21 16:41:52 +0800882 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800883 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800884 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
885 request);
886 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 break;
888
SongFerngWang9e060372020-12-21 16:41:52 +0800889 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result; // Integer
894 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530895 // request.result must be set to something non-null
896 // for the calling thread to unblock
897 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800899 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800901 loge("getAllowedNetworkTypesBitmask: CommandException: "
902 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800904 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 break;
909
SongFerngWang9e060372020-12-21 16:41:52 +0800910 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800912 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
913 request);
914 Pair<Integer, Long> reasonWithNetworkTypes =
915 (Pair<Integer, Long>) request.argument;
916 getPhoneFromRequest(request).setAllowedNetworkTypes(
917 reasonWithNetworkTypes.first,
918 reasonWithNetworkTypes.second,
919 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 break;
921
SongFerngWang9e060372020-12-21 16:41:52 +0800922 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
923 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 break;
925
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000926 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
927 request = (MainThreadRequest)msg.obj;
928 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800929 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000930 break;
931
932 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
933 ar = (AsyncResult)msg.obj;
934 request = (MainThreadRequest)ar.userObj;
935 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700936 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000937 break;
938
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800939 case CMD_SET_VOICEMAIL_NUMBER:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
942 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800943 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
944 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800945 break;
946
947 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
948 handleNullReturnEvent(msg, "setVoicemailNumber");
949 break;
950
Stuart Scott54788802015-03-30 13:18:01 -0700951 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
954 request);
955 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
956 break;
957
958 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
959 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
960 break;
961
Shishir Agrawal302c8692015-06-19 13:49:39 -0700962 case CMD_PERFORM_NETWORK_SCAN:
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
965 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
966 break;
967
Hall Liua1acea22020-09-18 19:04:59 -0700968 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700971 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
972 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
973 request.argument;
974 int callForwardingReason = args.first;
975 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800976 break;
Hall Liua1acea22020-09-18 19:04:59 -0700977 }
978 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700981 TelephonyManager.CallForwardingInfoCallback callback =
982 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
983 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800984 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700985 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800986 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
987 for (CallForwardInfo callForwardInfo : callForwardInfos) {
988 // Service Class is a bit mask per 3gpp 27.007. Search for
989 // any service for voice call.
990 if ((callForwardInfo.serviceClass
991 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700992 callForwardingInfo = new CallForwardingInfo(true,
993 callForwardInfo.reason,
994 callForwardInfo.number,
995 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800996 break;
997 }
998 }
999 // Didn't find a call forward info for voice call.
1000 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001001 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1002 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001003 }
Hall Liua1acea22020-09-18 19:04:59 -07001004 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001005 } else {
1006 if (ar.result == null) {
1007 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1008 }
1009 if (ar.exception != null) {
1010 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1011 }
Hall Liuae527aa2020-09-29 17:10:18 -07001012 int errorCode = TelephonyManager
1013 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001014 if (ar.exception instanceof CommandException) {
1015 CommandException.Error error =
1016 ((CommandException) (ar.exception)).getCommandError();
1017 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001020 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001021 errorCode = TelephonyManager
1022 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001023 }
1024 }
Hall Liua1acea22020-09-18 19:04:59 -07001025 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001026 }
sqian80370722020-01-29 15:02:51 -08001027 break;
Hall Liua1acea22020-09-18 19:04:59 -07001028 }
sqian80370722020-01-29 15:02:51 -08001029
Hall Liua1acea22020-09-18 19:04:59 -07001030 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001033 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001034 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001035 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1036 request.argument).first;
1037 request.phone.setCallForwardingOption(
1038 callForwardingInfoToSet.isEnabled()
1039 ? CommandsInterface.CF_ACTION_ENABLE
1040 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001041 callForwardingInfoToSet.getReason(),
1042 callForwardingInfoToSet.getNumber(),
1043 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1044 break;
Hall Liua1acea22020-09-18 19:04:59 -07001045 }
sqian80370722020-01-29 15:02:51 -08001046
Hall Liua1acea22020-09-18 19:04:59 -07001047 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001050 Consumer<Integer> callback =
1051 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1052 request.argument).second;
1053 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001054 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001055 int errorCode = TelephonyManager.CallForwardingInfoCallback
1056 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001057 if (ar.exception instanceof CommandException) {
1058 CommandException.Error error =
1059 ((CommandException) (ar.exception)).getCommandError();
1060 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001061 errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001063 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001064 errorCode = TelephonyManager.CallForwardingInfoCallback
1065 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001066 }
1067 }
1068 callback.accept(errorCode);
1069 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001070 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001071 }
sqian80370722020-01-29 15:02:51 -08001072 break;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
sqian80370722020-01-29 15:02:51 -08001074
Hall Liua1acea22020-09-18 19:04:59 -07001075 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1078 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1079 break;
Hall Liua1acea22020-09-18 19:04:59 -07001080 }
sqian80370722020-01-29 15:02:51 -08001081
Hall Liua1acea22020-09-18 19:04:59 -07001082 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001085 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001086 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1087 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001088 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001089 // Service Class is a bit mask per 3gpp 27.007.
1090 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001091 if (callForwardResults.length > 1
1092 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001093 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001094 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001095 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1096 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001097 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001098 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001099 }
1100 } else {
1101 if (ar.result == null) {
1102 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1103 }
1104 if (ar.exception != null) {
1105 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1106 }
1107 if (ar.exception instanceof CommandException) {
1108 CommandException.Error error =
1109 ((CommandException) (ar.exception)).getCommandError();
1110 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1111 callForwardingStatus =
1112 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1113 }
1114 }
1115 }
Hall Liua1acea22020-09-18 19:04:59 -07001116 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001117 break;
Hall Liua1acea22020-09-18 19:04:59 -07001118 }
sqian80370722020-01-29 15:02:51 -08001119
Hall Liua1acea22020-09-18 19:04:59 -07001120 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001121 request = (MainThreadRequest) msg.obj;
1122 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001123 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1124 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001125 break;
Hall Liua1acea22020-09-18 19:04:59 -07001126 }
sqian80370722020-01-29 15:02:51 -08001127
Hall Liua1acea22020-09-18 19:04:59 -07001128 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001131 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1132 Consumer<Integer> callback =
1133 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1134 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001135 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001136 if (ar.exception instanceof CommandException) {
1137 CommandException.Error error =
1138 ((CommandException) (ar.exception)).getCommandError();
1139 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1140 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1141 } else {
1142 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1143 }
1144 } else {
1145 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1146 }
1147 } else {
1148 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1149 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001150 }
sqian80370722020-01-29 15:02:51 -08001151 break;
Hall Liua1acea22020-09-18 19:04:59 -07001152 }
sqian80370722020-01-29 15:02:51 -08001153
Shishir Agrawal302c8692015-06-19 13:49:39 -07001154 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
1157 CellNetworkScanResult cellScanResult;
1158 if (ar.exception == null && ar.result != null) {
1159 cellScanResult = new CellNetworkScanResult(
1160 CellNetworkScanResult.STATUS_SUCCESS,
1161 (List<OperatorInfo>) ar.result);
1162 } else {
1163 if (ar.result == null) {
1164 loge("getCellNetworkScanResults: Empty response");
1165 }
1166 if (ar.exception != null) {
1167 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1168 }
1169 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1170 if (ar.exception instanceof CommandException) {
1171 CommandException.Error error =
1172 ((CommandException) (ar.exception)).getCommandError();
1173 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1174 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1175 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1176 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1177 }
1178 }
1179 cellScanResult = new CellNetworkScanResult(errorCode, null);
1180 }
1181 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001182 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001183 break;
1184
1185 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1186 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001187 ManualNetworkSelectionArgument selArg =
1188 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1190 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001191 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1192 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 break;
1194
1195 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 if (ar.exception == null) {
1199 request.result = true;
1200 } else {
1201 request.result = false;
1202 loge("setNetworkSelectionModeManual " + ar.exception);
1203 }
1204 notifyRequester(request);
1205 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001206 break;
1207
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001208 case CMD_GET_MODEM_ACTIVITY_INFO:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001211 if (defaultPhone != null) {
1212 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001213 } else {
1214 ResultReceiver result = (ResultReceiver) request.argument;
1215 Bundle bundle = new Bundle();
1216 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1217 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1218 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001219 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 break;
1221
1222 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001225 ResultReceiver result = (ResultReceiver) request.argument;
1226
1227 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001229 // Update the last modem activity info and the result of the request.
1230 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1231 if (isModemActivityInfoValid(info)) {
1232 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1233 int[] txTimeMs = info.getTransmitTimeMillis();
1234 int[] lastModemTxTimeMs = mLastModemActivityInfo
1235 .getTransmitTimeMillis();
1236 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1237 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1238 }
1239 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1240 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1241 + mLastModemActivityInfo.getSleepTimeMillis());
1242 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1243 + mLastModemActivityInfo.getIdleTimeMillis());
1244 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1245 mLastModemActivityInfo.setReceiveTimeMillis(
1246 info.getReceiveTimeMillis()
1247 + mLastModemActivityInfo.getReceiveTimeMillis());
1248 }
1249 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1250 mLastModemActivityInfo.getSleepTimeMillis(),
1251 mLastModemActivityInfo.getIdleTimeMillis(),
1252 mLastModemActivityInfo.getTransmitTimeMillis(),
1253 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001254 } else {
1255 if (ar.result == null) {
1256 loge("queryModemActivityInfo: Empty response");
1257 } else if (ar.exception instanceof CommandException) {
1258 loge("queryModemActivityInfo: CommandException: " +
1259 ar.exception);
1260 } else {
1261 loge("queryModemActivityInfo: Unknown exception");
1262 }
1263 }
sqian1a1be542020-03-05 11:37:28 -08001264 Bundle bundle = new Bundle();
1265 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1266 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001267 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001268 break;
1269
Meng Wang1a7c35a2016-05-05 20:56:15 -07001270 case CMD_SET_ALLOWED_CARRIERS:
1271 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001272 CarrierRestrictionRules argument =
1273 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001274 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001275 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 break;
1277
1278 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1279 ar = (AsyncResult) msg.obj;
1280 request = (MainThreadRequest) ar.userObj;
1281 if (ar.exception == null && ar.result != null) {
1282 request.result = ar.result;
1283 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001284 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1285 if (ar.exception instanceof CommandException) {
1286 loge("setAllowedCarriers: CommandException: " + ar.exception);
1287 CommandException.Error error =
1288 ((CommandException) (ar.exception)).getCommandError();
1289 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1290 request.result =
1291 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1292 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 } else {
1294 loge("setAllowedCarriers: Unknown exception");
1295 }
1296 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001297 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 break;
1299
1300 case CMD_GET_ALLOWED_CARRIERS:
1301 request = (MainThreadRequest) msg.obj;
1302 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001303 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 break;
1305
1306 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
1309 if (ar.exception == null && ar.result != null) {
1310 request.result = ar.result;
1311 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001312 request.result = new IllegalStateException(
1313 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001314 if (ar.result == null) {
1315 loge("getAllowedCarriers: Empty response");
1316 } else if (ar.exception instanceof CommandException) {
1317 loge("getAllowedCarriers: CommandException: " +
1318 ar.exception);
1319 } else {
1320 loge("getAllowedCarriers: Unknown exception");
1321 }
1322 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001323 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001324 break;
1325
Nathan Haroldb3014052017-01-25 15:57:32 -08001326 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1327 ar = (AsyncResult) msg.obj;
1328 request = (MainThreadRequest) ar.userObj;
1329 if (ar.exception == null && ar.result != null) {
1330 request.result = ar.result;
1331 } else {
1332 request.result = new IllegalArgumentException(
1333 "Failed to retrieve Forbidden Plmns");
1334 if (ar.result == null) {
1335 loge("getForbiddenPlmns: Empty response");
1336 } else {
1337 loge("getForbiddenPlmns: Unknown exception");
1338 }
1339 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001340 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001341 break;
1342
1343 case CMD_GET_FORBIDDEN_PLMNS:
1344 request = (MainThreadRequest) msg.obj;
1345 uiccCard = getUiccCardFromRequest(request);
1346 if (uiccCard == null) {
1347 loge("getForbiddenPlmns() UiccCard is null");
1348 request.result = new IllegalArgumentException(
1349 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001351 break;
1352 }
1353 Integer appType = (Integer) request.argument;
1354 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1355 if (uiccApp == null) {
1356 loge("getForbiddenPlmns() no app with specified type -- "
1357 + appType);
1358 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 break;
1361 } else {
1362 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1363 + " specified type -- " + appType);
1364 }
1365 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1366 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1367 onCompleted);
1368 break;
1369
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001370 case CMD_SWITCH_SLOTS:
1371 request = (MainThreadRequest) msg.obj;
1372 int[] physicalSlots = (int[]) request.argument;
1373 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1374 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1375 break;
1376
1377 case EVENT_SWITCH_SLOTS_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001381 notifyRequester(request);
1382 break;
1383 case CMD_GET_NETWORK_SELECTION_MODE:
1384 request = (MainThreadRequest) msg.obj;
1385 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1386 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1387 break;
1388
1389 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 if (ar.exception != null) {
1393 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1394 } else {
1395 int mode = ((int[]) ar.result)[0];
1396 if (mode == 0) {
1397 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1398 } else {
1399 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1400 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001401 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001402 notifyRequester(request);
1403 break;
1404 case CMD_GET_CDMA_ROAMING_MODE:
1405 request = (MainThreadRequest) msg.obj;
1406 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1407 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1408 break;
1409 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 if (ar.exception != null) {
1413 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1414 } else {
1415 request.result = ((int[]) ar.result)[0];
1416 }
1417 notifyRequester(request);
1418 break;
1419 case CMD_SET_CDMA_ROAMING_MODE:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1422 int mode = (int) request.argument;
1423 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1424 break;
1425 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 request.result = ar.exception == null;
1429 notifyRequester(request);
1430 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001431 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1434 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1435 break;
1436 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 if (ar.exception != null) {
1440 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1441 } else {
1442 request.result = ((int[]) ar.result)[0];
1443 }
1444 notifyRequester(request);
1445 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001446 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1449 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001450 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1451 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001452 break;
1453 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 request.result = ar.exception == null;
1457 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001458 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 case CMD_GET_ALL_CELL_INFO:
1460 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001462 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001464 case EVENT_GET_ALL_CELL_INFO_DONE:
1465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001467 // If a timeout occurs, the response will be null
1468 request.result = (ar.exception == null && ar.result != null)
1469 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 synchronized (request) {
1471 request.notifyAll();
1472 }
1473 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001474 case CMD_REQUEST_CELL_INFO_UPDATE:
1475 request = (MainThreadRequest) msg.obj;
1476 request.phone.requestCellInfoUpdate(request.workSource,
1477 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1478 break;
1479 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1483 try {
1484 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001485 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001486 cb.onError(
1487 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1488 ar.exception.getClass().getName(),
1489 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001490 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001491 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001492 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 } else {
1494 // use the result as returned
1495 cb.onCellInfo((List<CellInfo>) ar.result);
1496 }
1497 } catch (RemoteException re) {
1498 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1499 }
1500 break;
Sarah Chincc055732020-11-18 13:39:35 -08001501 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 request = (MainThreadRequest) msg.obj;
1503 WorkSource ws = (WorkSource) request.argument;
1504 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001505 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001506 break;
Sarah Chincc055732020-11-18 13:39:35 -08001507 }
1508 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception == null) {
1512 request.result = ar.result;
1513 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001514 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001515 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001516 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001517 }
1518
1519 synchronized (request) {
1520 request.notifyAll();
1521 }
1522 break;
Sarah Chincc055732020-11-18 13:39:35 -08001523 }
chen xu6dac5ab2018-10-26 17:39:23 -07001524 case CMD_MODEM_REBOOT:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001527 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001528 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001529 case EVENT_CMD_MODEM_REBOOT_DONE:
1530 handleNullReturnEvent(msg, "rebootModem");
1531 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001532 case CMD_REQUEST_ENABLE_MODEM:
1533 request = (MainThreadRequest) msg.obj;
1534 boolean enable = (boolean) request.argument;
1535 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001536 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001537 PhoneConfigurationManager.getInstance()
1538 .enablePhone(request.phone, enable, onCompleted);
1539 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001540 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001544 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001545 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001546 if ((boolean) request.result) {
1547 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1548 updateModemStateMetrics();
1549 } else {
1550 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1551 + ar.exception);
1552 }
1553 notifyRequester(request);
1554 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001555 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001556 case CMD_GET_MODEM_STATUS:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1559 PhoneConfigurationManager.getInstance()
1560 .getPhoneStatusFromModem(request.phone, onCompleted);
1561 break;
1562 case EVENT_GET_MODEM_STATUS_DONE:
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 int id = request.phone.getPhoneId();
1566 if (ar.exception == null && ar.result != null) {
1567 request.result = ar.result;
1568 //update the cache as modem status has changed
1569 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1570 (boolean) request.result);
1571 } else {
1572 // Return true if modem status cannot be retrieved. For most cases,
1573 // modem status is on. And for older version modems, GET_MODEM_STATUS
1574 // and disable modem are not supported. Modem is always on.
1575 // TODO: this should be fixed in R to support a third
1576 // status UNKNOWN b/131631629
1577 request.result = true;
1578 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1579 + ar.exception);
1580 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001581 notifyRequester(request);
1582 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001583 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1586 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1587 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1588 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1589 break;
1590 }
1591 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1592 ar = (AsyncResult) msg.obj;
1593 request = (MainThreadRequest) ar.userObj;
1594 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1595 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1596 args.second.accept(ar.exception == null);
1597 notifyRequester(request);
1598 break;
1599 }
Sarah Chincc055732020-11-18 13:39:35 -08001600 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1601 request = (MainThreadRequest) msg.obj;
1602 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1603 Phone phone = getPhoneFromRequest(request);
1604 if (phone != null) {
1605 phone.getSystemSelectionChannels(onCompleted);
1606 } else {
1607 loge("getSystemSelectionChannels: No phone object");
1608 request.result = new ArrayList<RadioAccessSpecifier>();
1609 notifyRequester(request);
1610 }
1611 break;
1612 }
1613 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 if (ar.exception == null && ar.result != null) {
1617 request.result = ar.result;
1618 } else {
1619 request.result = new IllegalArgumentException(
1620 "Failed to retrieve system selection channels");
1621 if (ar.result == null) {
1622 loge("getSystemSelectionChannels: Empty response");
1623 } else {
1624 loge("getSystemSelectionChannels: Unknown exception");
1625 }
1626 }
1627 notifyRequester(request);
1628 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001629 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null && ar.result != null) {
1633 request.result = ar.result;
1634 } else {
1635 request.result = -1;
1636 loge("Failed to set Forbidden Plmns");
1637 if (ar.result == null) {
1638 loge("setForbidenPlmns: Empty response");
1639 } else if (ar.exception != null) {
1640 loge("setForbiddenPlmns: Exception: " + ar.exception);
1641 request.result = -1;
1642 } else {
1643 loge("setForbiddenPlmns: Unknown exception");
1644 }
1645 }
1646 notifyRequester(request);
1647 break;
1648 case CMD_SET_FORBIDDEN_PLMNS:
1649 request = (MainThreadRequest) msg.obj;
1650 uiccCard = getUiccCardFromRequest(request);
1651 if (uiccCard == null) {
1652 loge("setForbiddenPlmns: UiccCard is null");
1653 request.result = -1;
1654 notifyRequester(request);
1655 break;
1656 }
1657 Pair<Integer, List<String>> setFplmnsArgs =
1658 (Pair<Integer, List<String>>) request.argument;
1659 appType = setFplmnsArgs.first;
1660 List<String> fplmns = setFplmnsArgs.second;
1661 uiccApp = uiccCard.getApplicationByType(appType);
1662 if (uiccApp == null) {
1663 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1664 request.result = -1;
1665 loge("Failed to get UICC App");
1666 notifyRequester(request);
1667 } else {
1668 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1669 ((SIMRecords) uiccApp.getIccRecords())
1670 .setForbiddenPlmns(onCompleted, fplmns);
1671 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001672 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001673 case CMD_ERASE_MODEM_CONFIG:
1674 request = (MainThreadRequest) msg.obj;
1675 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1676 defaultPhone.eraseModemConfig(onCompleted);
1677 break;
1678 case EVENT_ERASE_MODEM_CONFIG_DONE:
1679 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001680 break;
zoey chenf95ca592019-12-30 16:11:23 +08001681
1682 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1685 Pair<String, String> changed = (Pair<String, String>) request.argument;
1686 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1687 changed.first, changed.second, onCompleted);
1688 break;
1689 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
1692 if (ar.exception == null) {
1693 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001694 // If the operation is successful, update the PIN storage
1695 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1696 int phoneId = getPhoneFromRequest(request).getPhoneId();
1697 UiccController.getInstance().getPinStorage()
1698 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001699 } else {
1700 request.result = msg.arg1;
1701 }
1702 notifyRequester(request);
1703 break;
1704
Michele Berionned9fbae52020-11-13 02:36:59 +00001705 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1708 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1709 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1710 enabled.first, enabled.second, onCompleted);
1711 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001712 }
zoey chenf95ca592019-12-30 16:11:23 +08001713 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception == null) {
1717 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001718 // If the operation is successful, update the PIN storage
1719 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1720 int phoneId = getPhoneFromRequest(request).getPhoneId();
1721 if (enabled.first) {
1722 UiccController.getInstance().getPinStorage()
1723 .storePin(enabled.second, phoneId);
1724 } else {
1725 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1726 }
zoey chenf95ca592019-12-30 16:11:23 +08001727 } else {
1728 request.result = msg.arg1;
1729 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001730
1731
zoey chenf95ca592019-12-30 16:11:23 +08001732 notifyRequester(request);
1733 break;
1734
Peter Wangdafb9ac2020-01-15 14:13:38 -08001735 case MSG_NOTIFY_USER_ACTIVITY:
1736 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001737 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001738 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1739 getDefaultPhone().getContext().sendBroadcastAsUser(
1740 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1741 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001742
1743 case CMD_SET_DATA_THROTTLING: {
1744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1746 DataThrottlingRequest dataThrottlingRequest =
1747 (DataThrottlingRequest) request.argument;
1748 Phone phone = getPhoneFromRequest(request);
1749 if (phone != null) {
1750 phone.setDataThrottling(onCompleted,
1751 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1752 dataThrottlingRequest.getCompletionDurationMillis());
1753 } else {
1754 loge("setDataThrottling: No phone object");
1755 request.result =
1756 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1757 notifyRequester(request);
1758 }
1759
1760 break;
1761 }
1762 case EVENT_SET_DATA_THROTTLING_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765
1766 if (ar.exception == null) {
1767 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1768 } else if (ar.exception instanceof CommandException) {
1769 loge("setDataThrottling: CommandException: " + ar.exception);
1770 CommandException.Error error =
1771 ((CommandException) (ar.exception)).getCommandError();
1772
1773 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1774 request.result = TelephonyManager
1775 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1776 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1777 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1778 } else {
1779 request.result =
1780 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1781 }
1782 } else {
1783 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1784 }
1785 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1786 notifyRequester(request);
1787 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001788
1789 case CMD_SET_SIM_POWER: {
1790 request = (MainThreadRequest) msg.obj;
1791 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1792 request = (MainThreadRequest) msg.obj;
1793 int stateToSet =
1794 ((Pair<Integer, IIntegerConsumer>)
1795 request.argument).first;
1796 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1797 break;
1798 }
1799 case EVENT_SET_SIM_POWER_DONE: {
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802 IIntegerConsumer callback =
1803 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1804 if (ar.exception != null) {
1805 loge("setSimPower exception: " + ar.exception);
1806 int errorCode = TelephonyManager.CallForwardingInfoCallback
1807 .RESULT_ERROR_UNKNOWN;
1808 if (ar.exception instanceof CommandException) {
1809 CommandException.Error error =
1810 ((CommandException) (ar.exception)).getCommandError();
1811 if (error == CommandException.Error.SIM_ERR) {
1812 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1813 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1814 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1815 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1816 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1817 } else {
1818 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1819 }
1820 }
1821 try {
1822 callback.accept(errorCode);
1823 } catch (RemoteException e) {
1824 // Ignore if the remote process is no longer available to call back.
1825 Log.w(LOG_TAG, "setSimPower: callback not available.");
1826 }
1827 } else {
1828 try {
1829 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1830 } catch (RemoteException e) {
1831 // Ignore if the remote process is no longer available to call back.
1832 Log.w(LOG_TAG, "setSimPower: callback not available.");
1833 }
1834 }
1835 break;
1836 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001837 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1838 request = (MainThreadRequest) msg.obj;
1839
1840 final Phone phone = getPhoneFromRequest(request);
1841 if (phone == null || phone.getServiceStateTracker() == null) {
1842 request.result = new IllegalStateException("Phone or SST is null");
1843 notifyRequester(request);
1844 break;
1845 }
1846
1847 Pair<Integer, SignalStrengthUpdateRequest> pair =
1848 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1849 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1850 request);
1851 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1852 request.subId, pair.first /*callingUid*/,
1853 pair.second /*request*/, onCompleted);
1854 break;
1855 }
1856 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1857 ar = (AsyncResult) msg.obj;
1858 request = (MainThreadRequest) ar.userObj;
1859 // request.result will be the exception of ar if present, true otherwise.
1860 // Be cautious not to leave result null which will wait() forever
1861 request.result = ar.exception != null ? ar.exception : true;
1862 notifyRequester(request);
1863 break;
1864 }
1865 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1866 request = (MainThreadRequest) msg.obj;
1867
1868 Phone phone = getPhoneFromRequest(request);
1869 if (phone == null || phone.getServiceStateTracker() == null) {
1870 request.result = new IllegalStateException("Phone or SST is null");
1871 notifyRequester(request);
1872 break;
1873 }
1874
1875 Pair<Integer, SignalStrengthUpdateRequest> pair =
1876 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1877 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1878 request);
1879 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1880 request.subId, pair.first /*callingUid*/,
1881 pair.second /*request*/, onCompleted);
1882 break;
1883 }
1884 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1885 ar = (AsyncResult) msg.obj;
1886 request = (MainThreadRequest) ar.userObj;
1887 request.result = ar.exception != null ? ar.exception : true;
1888 notifyRequester(request);
1889 break;
1890 }
Jordan Liud5366d92020-11-24 14:50:34 -08001891
Michele Berionned9fbae52020-11-13 02:36:59 +00001892 case CMD_PREPARE_UNATTENDED_REBOOT:
1893 request = (MainThreadRequest) msg.obj;
1894 request.result =
1895 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1896 notifyRequester(request);
1897 break;
1898
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 default:
1900 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1901 break;
1902 }
1903 }
Jake Hambye994d462014-02-03 13:10:13 -08001904
Pengquan Menga1bb6272018-09-06 09:59:22 -07001905 private void notifyRequester(MainThreadRequest request) {
1906 synchronized (request) {
1907 request.notifyAll();
1908 }
1909 }
1910
Jake Hambye994d462014-02-03 13:10:13 -08001911 private void handleNullReturnEvent(Message msg, String command) {
1912 AsyncResult ar = (AsyncResult) msg.obj;
1913 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1914 if (ar.exception == null) {
1915 request.result = true;
1916 } else {
1917 request.result = false;
1918 if (ar.exception instanceof CommandException) {
1919 loge(command + ": CommandException: " + ar.exception);
1920 } else {
1921 loge(command + ": Unknown exception");
1922 }
1923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001924 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
1928 /**
1929 * Posts the specified command to be executed on the main thread,
1930 * waits for the request to complete, and returns the result.
1931 * @see #sendRequestAsync
1932 */
1933 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001934 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1935 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001936 }
1937
1938 /**
1939 * Posts the specified command to be executed on the main thread,
1940 * waits for the request to complete, and returns the result.
1941 * @see #sendRequestAsync
1942 */
1943 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1944 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001945 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
1948 /**
1949 * Posts the specified command to be executed on the main thread,
1950 * waits for the request to complete, and returns the result.
1951 * @see #sendRequestAsync
1952 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001953 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001954 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1955 }
1956
1957 /**
1958 * Posts the specified command to be executed on the main thread,
1959 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1960 * if not timeout or null otherwise.
1961 * @see #sendRequestAsync
1962 */
1963 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1964 long timeoutInMs) {
1965 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001966 }
1967
1968 /**
1969 * Posts the specified command to be executed on the main thread,
1970 * waits for the request to complete, and returns the result.
1971 * @see #sendRequestAsync
1972 */
Nathan Harold92bed182018-10-12 18:16:49 -07001973 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001974 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001975 }
1976
1977 /**
1978 * Posts the specified command to be executed on the main thread,
1979 * waits for the request to complete, and returns the result.
1980 * @see #sendRequestAsync
1981 */
1982 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001983 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1984 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001985 }
1986
1987 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001988 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1989 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1990 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001991 * @see #sendRequestAsync
1992 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001993 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1994 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1996 throw new RuntimeException("This method will deadlock if called from the main thread.");
1997 }
1998
Nathan Harold92bed182018-10-12 18:16:49 -07001999 MainThreadRequest request = null;
2000 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2001 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2002 } else if (phone != null) {
2003 request = new MainThreadRequest(argument, phone, workSource);
2004 } else {
2005 request = new MainThreadRequest(argument, subId, workSource);
2006 }
2007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 Message msg = mMainThreadHandler.obtainMessage(command, request);
2009 msg.sendToTarget();
2010
Rambo Wang0f050d82021-02-12 11:43:36 -08002011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002013 if (timeoutInMs >= 0) {
2014 // Wait for at least timeoutInMs before returning null request result
2015 long now = SystemClock.elapsedRealtime();
2016 long deadline = now + timeoutInMs;
2017 while (request == null && now < deadline) {
2018 try {
2019 request.wait(deadline - now);
2020 } catch (InterruptedException e) {
2021 // Do nothing, go back and check if request is completed or timeout
2022 } finally {
2023 now = SystemClock.elapsedRealtime();
2024 }
2025 }
2026 } else {
2027 // Wait for the request to complete
2028 while (request.result == null) {
2029 try {
2030 request.wait();
2031 } catch (InterruptedException e) {
2032 // Do nothing, go back and wait until the request is complete
2033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 }
2035 }
2036 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002037 if (request.result == null) {
2038 Log.wtf(LOG_TAG,
2039 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 return request.result;
2042 }
2043
2044 /**
2045 * Asynchronous ("fire and forget") version of sendRequest():
2046 * Posts the specified command to be executed on the main thread, and
2047 * returns immediately.
2048 * @see #sendRequest
2049 */
2050 private void sendRequestAsync(int command) {
2051 mMainThreadHandler.sendEmptyMessage(command);
2052 }
2053
2054 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002055 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002056 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002057 */
2058 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002059 sendRequestAsync(command, argument, null, null);
2060 }
2061
2062 /**
2063 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2064 * @see {@link #sendRequest(int,Object)}
2065 */
2066 private void sendRequestAsync(
2067 int command, Object argument, Phone phone, WorkSource workSource) {
2068 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002069 Message msg = mMainThreadHandler.obtainMessage(command, request);
2070 msg.sendToTarget();
2071 }
2072
2073 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 * Initialize the singleton PhoneInterfaceManager instance.
2075 * This is only done once, at startup, from PhoneApp.onCreate().
2076 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002077 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 synchronized (PhoneInterfaceManager.class) {
2079 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002080 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 } else {
2082 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2083 }
2084 return sInstance;
2085 }
2086 }
2087
2088 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002089 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002092 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002093 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2095 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002096 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002097 mTelephonySharedPreferences =
2098 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002099 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002100 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002101 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002102 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002103
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 publish();
2105 }
2106
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002107 private Phone getDefaultPhone() {
2108 Phone thePhone = getPhone(getDefaultSubscription());
2109 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2110 }
2111
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 private void publish() {
2113 if (DBG) log("publish: " + this);
2114
Peter Wangc035ce42020-01-08 21:00:22 -08002115 TelephonyFrameworkInitializer
2116 .getTelephonyServiceManager()
2117 .getTelephonyServiceRegisterer()
2118 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120
Stuart Scott584921c2015-01-15 17:10:34 -08002121 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002122 if (request.phone != null) {
2123 return request.phone;
2124 } else {
2125 return getPhoneFromSubId(request.subId);
2126 }
2127 }
2128
2129 private Phone getPhoneFromSubId(int subId) {
2130 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2131 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002132 }
2133
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002134 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2135 Phone phone = getPhoneFromRequest(request);
2136 return phone == null ? null :
2137 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2138 }
2139
Wink Saville36469e72014-06-11 15:17:00 -07002140 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002141 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002142 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002145 private void sendEraseModemConfig(Phone phone) {
2146 if (phone != null) {
2147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2148 mApp, phone.getSubId(), "eraseModemConfig");
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2152 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
2156 }
2157 }
2158
Peter Wang050bb052020-01-13 23:33:09 -08002159 private boolean isImsAvailableOnDevice() {
2160 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2161 if (pm == null) {
2162 // For some reason package manger is not available.. This will fail internally anyway,
2163 // so do not throw error and allow.
2164 return true;
2165 }
2166 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2167 }
2168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002170 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002171 }
2172
Wink Savilleb564aae2014-10-23 10:18:09 -07002173 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 if (DBG) log("dial: " + number);
2175 // No permission check needed here: This is just a wrapper around the
2176 // ACTION_DIAL intent, which is available to any app since it puts up
2177 // the UI before it does anything.
2178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 String url = createTelUrl(number);
2182 if (url == null) {
2183 return;
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 // PENDING: should we just silently fail if phone is offhook or ringing?
2187 PhoneConstants.State state = mCM.getState(subId);
2188 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2189 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2191 mApp.startActivity(intent);
2192 }
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196 }
2197
2198 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002199 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002200 }
2201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 if (DBG) log("call: " + number);
2204
2205 // This is just a wrapper around the ACTION_CALL intent, but we still
2206 // need to do a permission check since we're calling startActivity()
2207 // from the context of the phone app.
2208 enforceCallPermission();
2209
Jordan Liu1617b712019-07-10 15:06:26 -07002210 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 != AppOpsManager.MODE_ALLOWED) {
2212 return;
2213 }
2214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 String url = createTelUrl(number);
2218 if (url == null) {
2219 return;
2220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 boolean isValid = false;
2223 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2224 if (slist != null) {
2225 for (SubscriptionInfo subInfoRecord : slist) {
2226 if (subInfoRecord.getSubscriptionId() == subId) {
2227 isValid = true;
2228 break;
2229 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002230 }
Wink Saville08874612014-08-31 19:19:58 -07002231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 if (!isValid) {
2233 return;
2234 }
Wink Saville08874612014-08-31 19:19:58 -07002235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2237 intent.putExtra(SUBSCRIPTION_KEY, subId);
2238 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2239 mApp.startActivity(intent);
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
2242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 }
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002246 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002247 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2248 }
2249
Wink Savilleb564aae2014-10-23 10:18:09 -07002250 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002251 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002252 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2253 }
2254
Wink Savilleb564aae2014-10-23 10:18:09 -07002255 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257
2258 final long identity = Binder.clearCallingIdentity();
2259 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002260 Phone phone = getPhone(subId);
2261 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 checkSimPin.start();
2263 return checkSimPin.unlockSim(null, pin);
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002274 Phone phone = getPhone(subId);
2275 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 checkSimPuk.start();
2277 return checkSimPuk.unlockSim(puk, pin);
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002284 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 * a synchronous one.
2286 */
2287 private static class UnlockSim extends Thread {
2288
2289 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002290 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291
2292 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002293 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2294 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295
2296 // For replies from SimCard interface
2297 private Handler mHandler;
2298
2299 // For async handler to identify request type
2300 private static final int SUPPLY_PIN_COMPLETE = 100;
2301
Michele Berionned9fbae52020-11-13 02:36:59 +00002302 UnlockSim(int phoneId, IccCard simCard) {
2303 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 mSimCard = simCard;
2305 }
2306
2307 @Override
2308 public void run() {
2309 Looper.prepare();
2310 synchronized (UnlockSim.this) {
2311 mHandler = new Handler() {
2312 @Override
2313 public void handleMessage(Message msg) {
2314 AsyncResult ar = (AsyncResult) msg.obj;
2315 switch (msg.what) {
2316 case SUPPLY_PIN_COMPLETE:
2317 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2318 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002319 mRetryCount = msg.arg1;
2320 if (ar.exception != null) {
2321 if (ar.exception instanceof CommandException &&
2322 ((CommandException)(ar.exception)).getCommandError()
2323 == CommandException.Error.PASSWORD_INCORRECT) {
2324 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002325 } //When UiccCardApp dispose,handle message and return exception
2326 else if (ar.exception instanceof CommandException &&
2327 ((CommandException) (ar.exception)).getCommandError()
2328 == CommandException.Error.ABORTED) {
2329 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002330 } else {
2331 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2332 }
2333 } else {
2334 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mDone = true;
2337 UnlockSim.this.notifyAll();
2338 }
2339 break;
2340 }
2341 }
2342 };
2343 UnlockSim.this.notifyAll();
2344 }
2345 Looper.loop();
2346 }
2347
2348 /*
2349 * Use PIN or PUK to unlock SIM card
2350 *
2351 * If PUK is null, unlock SIM card with PIN
2352 *
2353 * If PUK is not null, unlock SIM card with PUK and set PIN code
2354 */
Wink Saville9de0f752013-10-22 19:04:03 -07002355 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356
2357 while (mHandler == null) {
2358 try {
2359 wait();
2360 } catch (InterruptedException e) {
2361 Thread.currentThread().interrupt();
2362 }
2363 }
2364 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2365
2366 if (puk == null) {
2367 mSimCard.supplyPin(pin, callback);
2368 } else {
2369 mSimCard.supplyPuk(puk, pin, callback);
2370 }
2371
2372 while (!mDone) {
2373 try {
2374 Log.d(LOG_TAG, "wait for done");
2375 wait();
2376 } catch (InterruptedException e) {
2377 // Restore the interrupted status
2378 Thread.currentThread().interrupt();
2379 }
2380 }
2381 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002382 int[] resultArray = new int[2];
2383 resultArray[0] = mResult;
2384 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002385
2386 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2387 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2388 }
2389
Wink Saville9de0f752013-10-22 19:04:03 -07002390 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
2392 }
2393
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002394 /**
2395 * This method has been removed due to privacy and stability concerns.
2396 */
2397 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002399 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2400 return;
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Nathan Harold1f889d82020-06-04 17:05:26 -07002403 @Override
2404 public void updateServiceLocationWithPackageName(String callingPackage) {
2405 mApp.getSystemService(AppOpsManager.class)
2406 .checkPackage(Binder.getCallingUid(), callingPackage);
2407
Nathan Haroldf096d982020-11-18 17:18:06 -08002408 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002409 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2410 // Callers targeting S have no business invoking this method.
2411 return;
2412 }
2413
2414 LocationAccessPolicy.LocationPermissionResult locationResult =
2415 LocationAccessPolicy.checkLocationPermission(mApp,
2416 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2417 .setCallingPackage(callingPackage)
2418 .setCallingFeatureId(null)
2419 .setCallingPid(Binder.getCallingPid())
2420 .setCallingUid(Binder.getCallingUid())
2421 .setMethod("updateServiceLocation")
2422 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2423 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2424 .build());
2425 // Apps that lack location permission have no business calling this method;
2426 // however, because no permission was declared in the public API, denials must
2427 // all be "soft".
2428 switch (locationResult) {
2429 case DENIED_HARD: /* fall through */
2430 case DENIED_SOFT:
2431 return;
2432 }
2433
2434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 final long identity = Binder.clearCallingIdentity();
2436 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002437 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002439 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002446 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 @Override
2448 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
2451
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002452
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002454 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2455 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2456 callingFeatureId);
2457 }
2458
2459 @Deprecated
2460 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002461 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002462 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2463 }
2464
2465 @Override
2466 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2467 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002469 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 return false;
2471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 return isRadioOnForSubscriber(subId);
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
2478 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002479 }
2480
2481 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 final Phone phone = getPhone(subId);
2485 if (phone != null) {
2486 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2487 } else {
2488 return false;
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
2495 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
Wink Saville36469e72014-06-11 15:17:00 -07002498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
2504 final Phone phone = getPhone(subId);
2505 if (phone != null) {
2506 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Wink Saville36469e72014-06-11 15:17:00 -07002511 }
2512
2513 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002514 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
2516
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone == null) {
2524 return false;
2525 }
2526 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2527 toggleRadioOnOffForSubscriber(subId);
2528 }
2529 return true;
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 }
Wink Saville36469e72014-06-11 15:17:00 -07002534
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002535 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002536 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002537 /*
2538 * If any of the Radios are available, it will need to be
2539 * shutdown. So return true if any Radio is available.
2540 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2544 Phone phone = PhoneFactory.getPhone(i);
2545 if (phone != null && phone.isRadioAvailable()) return true;
2546 }
2547 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2548 return false;
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002551 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002552 }
2553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002555 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 enforceModifyPermission();
2557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2561 logv("Shutting down Phone " + i);
2562 shutdownRadioUsingPhoneId(i);
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002566 }
2567 }
2568
2569 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002570 Phone phone = PhoneFactory.getPhone(phoneId);
2571 if (phone != null && phone.isRadioAvailable()) {
2572 phone.shutdownRadio();
2573 }
2574 }
2575
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2582 if (defaultPhone != null) {
2583 defaultPhone.setRadioPower(turnOn);
2584 return true;
2585 } else {
2586 loge("There's no default phone.");
2587 return false;
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002591 }
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Wink Savilleb564aae2014-10-23 10:18:09 -07002594 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(subId);
2600 if (phone != null) {
2601 phone.setRadioPower(turnOn);
2602 return true;
2603 } else {
2604 return false;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
Wink Saville36469e72014-06-11 15:17:00 -07002611 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 public boolean enableDataConnectivity() {
2614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 int subId = mSubscriptionController.getDefaultDataSubId();
2619 final Phone phone = getPhone(subId);
2620 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002621 phone.getDataEnabledSettings().setDataEnabled(
2622 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 return true;
2624 } else {
2625 return false;
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Wink Saville36469e72014-06-11 15:17:00 -07002632 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 public boolean disableDataConnectivity() {
2635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 int subId = mSubscriptionController.getDefaultDataSubId();
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002642 phone.getDataEnabledSettings().setDataEnabled(
2643 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 return true;
2645 } else {
2646 return false;
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002654 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002659 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 } else {
2661 return false;
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
2668 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002669 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002670 }
2671
pkanwarae03a6b2016-11-06 20:37:09 -08002672 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673 enforceCallPermission();
2674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2678 return;
2679 }
2680 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2681 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
pkanwar32d516d2016-10-14 19:37:38 -07002685 };
2686
Wink Savilleb564aae2014-10-23 10:18:09 -07002687 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689
2690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2693 return false;
2694 }
2695 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002702 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002703 }
2704
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002705 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 Phone phone = PhoneFactory.getPhone(slotIndex);
2709 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2710 PhoneConstantConversions.convertCallState(phone.getState());
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002717 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002718 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2719 }
2720
2721 @Override
2722 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002725 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 if (phone != null) {
2727 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2728 } else {
2729 return PhoneConstantConversions.convertDataState(
2730 PhoneConstants.DataState.DISCONNECTED);
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002738 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002739 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2740 }
2741
2742 @Override
2743 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 if (phone != null) {
2748 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2749 } else {
2750 return TelephonyManager.DATA_ACTIVITY_NONE;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002758 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002759 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002760 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002761
2762 LocationAccessPolicy.LocationPermissionResult locationResult =
2763 LocationAccessPolicy.checkLocationPermission(mApp,
2764 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2765 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002766 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002767 .setCallingPid(Binder.getCallingPid())
2768 .setCallingUid(Binder.getCallingUid())
2769 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002770 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002771 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2772 .build());
2773 switch (locationResult) {
2774 case DENIED_HARD:
2775 throw new SecurityException("Not allowed to access cell location");
2776 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002777 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2778 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002781 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002785 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002786 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
Svetoslav64fad262015-04-14 14:35:21 -07002790 }
2791
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 @Override
Jack Yu01425032020-02-22 19:38:58 -08002793 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002794 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2795 // registered cell info, so return a NULL country instead.
2796 final long identity = Binder.clearCallingIdentity();
2797 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002798 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2799 // Get default phone in this case.
2800 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2801 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002804 if (phone == null) return "";
2805 ServiceStateTracker sst = phone.getServiceStateTracker();
2806 if (sst == null) return "";
2807 LocaleTracker lt = sst.getLocaleTracker();
2808 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002809 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002813 }
2814
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002815 /**
2816 * This method was removed due to potential issues caused by performing partial
2817 * updates of service state, and lack of a credible use case.
2818 *
2819 * This has the ability to break the telephony implementation by disabling notification of
2820 * changes in device connectivity. DO NOT USE THIS!
2821 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002822 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 public void enableLocationUpdates() {
2824 mApp.enforceCallingOrSelfPermission(
2825 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002828 /**
2829 * This method was removed due to potential issues caused by performing partial
2830 * updates of service state, and lack of a credible use case.
2831 *
2832 * This has the ability to break the telephony implementation by disabling notification of
2833 * changes in device connectivity. DO NOT USE THIS!
2834 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 @Override
2836 public void disableLocationUpdates() {
2837 mApp.enforceCallingOrSelfPermission(
2838 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
2841 @Override
2842 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2844 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002845 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002846 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2847 throw new SecurityException(
2848 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2849 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002850
Jordan Liu1617b712019-07-10 15:06:26 -07002851 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2853 return null;
2854 }
Svetoslav64fad262015-04-14 14:35:21 -07002855
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002856 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002858 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002859 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860
Nathan Haroldf180aac2018-06-01 18:43:55 -07002861 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2862 for (CellInfo ci : info) {
2863 if (ci instanceof CellInfoGsm) {
2864 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2865 } else if (ci instanceof CellInfoWcdma) {
2866 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002869 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 }
2871
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002872 private List<CellInfo> getCachedCellInfo() {
2873 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2874 for (Phone phone : PhoneFactory.getPhones()) {
2875 List<CellInfo> info = phone.getAllCellInfo();
2876 if (info != null) cellInfos.addAll(info);
2877 }
2878 return cellInfos;
2879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880
2881 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002882 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002883 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002884 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002885
2886 LocationAccessPolicy.LocationPermissionResult locationResult =
2887 LocationAccessPolicy.checkLocationPermission(mApp,
2888 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2889 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002891 .setCallingPid(Binder.getCallingPid())
2892 .setCallingUid(Binder.getCallingUid())
2893 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002894 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002895 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2896 .build());
2897 switch (locationResult) {
2898 case DENIED_HARD:
2899 throw new SecurityException("Not allowed to access cell info");
2900 case DENIED_SOFT:
2901 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
Nathan Haroldf096d982020-11-18 17:18:06 -08002904 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002905 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2906 return getCachedCellInfo();
2907 }
2908
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002909 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2914 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002915 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002916 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 if (info != null) cellInfos.addAll(info);
2918 }
2919 return cellInfos;
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923 }
2924
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002925 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002926 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2927 String callingFeatureId) {
2928 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2929 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002930 }
2931
2932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002933 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2934 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002935 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002936 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002937 }
2938
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002939 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2940 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002942 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002943
2944 LocationAccessPolicy.LocationPermissionResult locationResult =
2945 LocationAccessPolicy.checkLocationPermission(mApp,
2946 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2947 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002948 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002949 .setCallingPid(Binder.getCallingPid())
2950 .setCallingUid(Binder.getCallingUid())
2951 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002952 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2953 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002954 .build());
2955 switch (locationResult) {
2956 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002957 if (TelephonyPermissions
2958 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002959 // Safetynet logging for b/154934934
2960 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2961 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 throw new SecurityException("Not allowed to access cell info");
2963 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002964 if (TelephonyPermissions
2965 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002966 // Safetynet logging for b/154934934
2967 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2968 }
Nathan Harold5320c422019-05-09 10:26:08 -07002969 try {
2970 cb.onCellInfo(new ArrayList<CellInfo>());
2971 } catch (RemoteException re) {
2972 // Drop without consequences
2973 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002974 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002975 }
2976
Nathan Harolda939a962019-05-09 10:13:47 -07002977
2978 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002979 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2980
2981 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2982 }
2983
2984 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002986 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
2996
Shishir Agrawala9f32182016-04-12 12:00:16 -07002997 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002998 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002999 Phone phone = PhoneFactory.getPhone(slotIndex);
3000 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003001 return null;
3002 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003003 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003004 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003005 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003006 return null;
3007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 return phone.getImei();
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003015 }
3016
3017 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003018 public String getTypeAllocationCodeForSlot(int slotIndex) {
3019 Phone phone = PhoneFactory.getPhone(slotIndex);
3020 String tac = null;
3021 if (phone != null) {
3022 String imei = phone.getImei();
3023 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3024 }
3025 return tac;
3026 }
3027
3028 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003029 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003030 Phone phone = PhoneFactory.getPhone(slotIndex);
3031 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003032 return null;
3033 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034
Jeff Davidson913390f2018-02-23 17:11:49 -08003035 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003036 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003037 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003038 return null;
3039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040
3041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 return phone.getMeid();
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
Jack Yu2af8d712017-03-15 17:14:14 -07003047 }
3048
3049 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003050 public String getManufacturerCodeForSlot(int slotIndex) {
3051 Phone phone = PhoneFactory.getPhone(slotIndex);
3052 String manufacturerCode = null;
3053 if (phone != null) {
3054 String meid = phone.getMeid();
3055 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3056 }
3057 return manufacturerCode;
3058 }
3059
3060 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003061 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3062 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 Phone phone = PhoneFactory.getPhone(slotIndex);
3064 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003065 return null;
3066 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003067 int subId = phone.getSubId();
3068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003069 mApp, subId, callingPackage, callingFeatureId,
3070 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003071 return null;
3072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 return phone.getDeviceSvn();
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003080 }
3081
fionaxu43304da2017-11-27 22:51:16 -08003082 @Override
3083 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 final Phone phone = getPhone(subId);
3087 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
fionaxu43304da2017-11-27 22:51:16 -08003091 }
3092
3093 @Override
3094 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 final Phone phone = getPhone(subId);
3098 return phone == null ? null : phone.getCarrierName();
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
fionaxu43304da2017-11-27 22:51:16 -08003102 }
3103
calvinpanffe225e2018-11-01 19:43:06 +08003104 @Override
chen xu0026ca62019-03-06 15:28:50 -08003105 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003110 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
3116 @Override
chen xu0026ca62019-03-06 15:28:50 -08003117 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003121 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
chen xu651eec72018-11-11 19:03:44 -08003127 @Override
chen xu864e11c2018-12-06 22:10:03 -08003128 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3129 if (!isSubscriptionMccMnc) {
3130 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3131 }
chen xu651eec72018-11-11 19:03:44 -08003132 final Phone phone = PhoneFactory.getPhone(slotIndex);
3133 if (phone == null) {
3134 return TelephonyManager.UNKNOWN_CARRIER_ID;
3135 }
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
3142 }
3143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 //
3145 // Internal helper methods.
3146 //
3147
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003148 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3150 *
3151 * @throws SecurityException if the caller does not have the required permission
3152 */
3153 private void enforceModifyPermission() {
3154 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3155 }
3156
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003157 /**
3158 * Make sure the caller is system.
3159 *
3160 * @throws SecurityException if the caller is not system.
3161 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003162 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003163 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3164 throw new SecurityException("Caller must be system");
3165 }
3166 }
3167
Shuo Qianf2b2df42019-11-13 17:43:31 -08003168 private void enforceActiveEmergencySessionPermission() {
3169 mApp.enforceCallingOrSelfPermission(
3170 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3171 }
3172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 /**
3174 * Make sure the caller has the CALL_PHONE permission.
3175 *
3176 * @throws SecurityException if the caller does not have the required permission
3177 */
3178 private void enforceCallPermission() {
3179 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3180 }
3181
paulhu423b5f22019-08-23 19:17:33 +08003182 private void enforceSettingsPermission() {
3183 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003184 }
3185
Michele Berionned9fbae52020-11-13 02:36:59 +00003186 private void enforceRebootPermission() {
3187 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3188 }
3189
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 private String createTelUrl(String number) {
3191 if (TextUtils.isEmpty(number)) {
3192 return null;
3193 }
3194
Jake Hambye994d462014-02-03 13:10:13 -08003195 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Ihab Awadf9e92732013-12-05 18:02:52 -08003198 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3200 }
3201
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003202 private static void logv(String msg) {
3203 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3204 }
3205
Ihab Awadf9e92732013-12-05 18:02:52 -08003206 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3208 }
3209
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003210 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003212 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003213 }
3214
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003216 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 final Phone phone = PhoneFactory.getPhone(slotIndex);
3220 if (phone == null) {
3221 return PhoneConstants.PHONE_TYPE_NONE;
3222 } else {
3223 return phone.getPhoneType();
3224 }
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003228 }
3229
3230 /**
3231 * Returns the CDMA ERI icon index to display
3232 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003234 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3235 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3236 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003237 }
3238
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003240 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3241 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003243 mApp, subId, callingPackage, callingFeatureId,
3244 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003245 return -1;
3246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 final Phone phone = getPhone(subId);
3251 if (phone != null) {
3252 return phone.getCdmaEriIconIndex();
3253 } else {
3254 return -1;
3255 }
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
3261 /**
3262 * Returns the CDMA ERI icon mode,
3263 * 0 - ON
3264 * 1 - FLASHING
3265 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003266 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003267 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3268 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3269 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003270 }
3271
Sanket Padawe356d7632015-06-22 14:03:32 -07003272 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003273 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003276 mApp, subId, callingPackage, callingFeatureId,
3277 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003278 return -1;
3279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 final Phone phone = getPhone(subId);
3284 if (phone != null) {
3285 return phone.getCdmaEriIconMode();
3286 } else {
3287 return -1;
3288 }
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
3294 /**
3295 * Returns the CDMA ERI text,
3296 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003298 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3299 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3300 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003301 }
3302
Sanket Padawe356d7632015-06-22 14:03:32 -07003303 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003304 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3305 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003307 mApp, subId, callingPackage, callingFeatureId,
3308 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003309 return null;
3310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 final Phone phone = getPhone(subId);
3315 if (phone != null) {
3316 return phone.getCdmaEriText();
3317 } else {
3318 return null;
3319 }
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 }
3324
3325 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003326 * Returns the CDMA MDN.
3327 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003328 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003329 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3331 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 return phone.getLine1Number();
3338 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 return null;
3341 }
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003344 }
3345 }
3346
3347 /**
3348 * Returns the CDMA MIN.
3349 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003350 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003351 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3353 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 final Phone phone = getPhone(subId);
3358 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3359 return phone.getCdmaMin();
3360 } else {
3361 return null;
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003365 }
3366 }
3367
Hall Liud892bec2018-11-30 14:51:45 -08003368 @Override
3369 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3370 INumberVerificationCallback callback, String callingPackage) {
3371 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3372 != PERMISSION_GRANTED) {
3373 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3374 }
3375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3376
3377 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3378 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003379 throw new SecurityException("Calling package must be configured in the device config: "
3380 + "calling package: " + callingPackage
3381 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003382 }
3383
3384 if (range == null) {
3385 throw new NullPointerException("Range must be non-null");
3386 }
3387
3388 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003389 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003390
3391 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3392 }
3393
Junda Liuca05d5d2014-08-14 22:36:34 -07003394 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395 * Returns true if CDMA provisioning needs to run.
3396 */
3397 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003400 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 }
3405
3406 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003407 * Sets the voice mail number of a given subId.
3408 */
3409 @Override
3410 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003411 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3412 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3417 new Pair<String, String>(alphaTag, number), new Integer(subId));
3418 return success;
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003422 }
3423
Ta-wei Yen87c49842016-05-13 21:19:52 -07003424 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003425 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003427 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3428 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003429 if (!TextUtils.equals(callingPackage, systemDialer)) {
3430 throw new SecurityException("caller must be system dialer");
3431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3436 if (phoneAccountHandle == null) {
3437 return null;
3438 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003442 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003443 }
3444
3445 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003446 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3447 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003450 mApp, subId, callingPackage, callingFeatureId,
3451 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003452 return null;
3453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003455 final long identity = Binder.clearCallingIdentity();
3456 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003461 }
3462
3463 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003464 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3465 VisualVoicemailSmsFilterSettings settings) {
3466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467
3468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003471 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472 } finally {
3473 Binder.restoreCallingIdentity(identity);
3474 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003475 }
3476
3477 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003478 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003484 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003488 }
3489
3490 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003491 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3492 String callingPackage, int subId) {
3493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003498 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499 } finally {
3500 Binder.restoreCallingIdentity(identity);
3501 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003502 }
3503
3504 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003505 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003511 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003515 }
3516
3517 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003518 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3519 String callingAttributionTag, int subId, String number, int port, String text,
3520 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003522 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003523 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003524 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003525 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3526 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003527 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003528
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003529 /**
fionaxu0152e512016-11-14 13:36:14 -08003530 * Sets the voice activation state of a given subId.
3531 */
3532 @Override
3533 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3535 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 phone.setVoiceActivationState(activationState);
3542 } else {
3543 loge("setVoiceActivationState fails with invalid subId: " + subId);
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003547 }
3548 }
3549
3550 /**
3551 * Sets the data activation state of a given subId.
3552 */
3553 @Override
3554 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3556 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone phone = getPhone(subId);
3561 if (phone != null) {
3562 phone.setDataActivationState(activationState);
3563 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003564 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003568 }
3569 }
3570
3571 /**
3572 * Returns the voice activation state of a given subId.
3573 */
3574 @Override
3575 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577
fionaxu0152e512016-11-14 13:36:14 -08003578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 if (phone != null) {
3582 return phone.getVoiceActivationState();
3583 } else {
3584 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003588 }
3589 }
3590
3591 /**
3592 * Returns the data activation state of a given subId.
3593 */
3594 @Override
3595 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597
fionaxu0152e512016-11-14 13:36:14 -08003598 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 if (phone != null) {
3602 return phone.getDataActivationState();
3603 } else {
3604 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3605 }
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003608 }
3609 }
3610
3611 /**
Wink Saville36469e72014-06-11 15:17:00 -07003612 * Returns the unread count of voicemails for a subId
3613 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003615 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3616 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003618 mApp, subId, callingPackage, callingFeatureId,
3619 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003620 return 0;
3621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null) {
3626 return phone.getVoiceMessageCount();
3627 } else {
3628 return 0;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 }
3634
3635 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003636 * returns true, if the device is in a state where both voice and data
3637 * are supported simultaneously. This can change based on location or network condition.
3638 */
3639 @Override
3640 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 final Phone phone = getPhone(subId);
3644 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003648 }
3649
3650 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003651 * Send the dialer code if called from the current default dialer or the caller has
3652 * carrier privilege.
3653 * @param inputCode The dialer code to send
3654 */
3655 @Override
3656 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003659 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3660 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003661 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003662 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
fionaxu235cc5e2017-03-06 22:25:57 -08003672 }
3673
Pengquan Menga1bb6272018-09-06 09:59:22 -07003674 @Override
3675 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003676 TelephonyPermissions
3677 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3678 mApp, subId, "getNetworkSelectionMode");
3679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 if (!isActiveSubscription(subId)) {
3682 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3683 }
3684 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003688 }
3689
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003691 public boolean isInEmergencySmsMode() {
3692 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 for (Phone phone : PhoneFactory.getPhones()) {
3696 if (phone.isInEmergencySmsMode()) {
3697 return true;
3698 }
3699 }
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
3703 return false;
3704 }
3705
shilu366312e2019-12-17 09:28:10 -08003706 /**
3707 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3708 * @param subId The subscription to use to check the configuration.
3709 * @param c The callback that will be used to send the result.
3710 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003711 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003712 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3713 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003714 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3715 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003716
Brad Ebinger77b832e2019-10-17 17:03:22 -07003717 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3719 "IMS not available on device.");
3720 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 final long token = Binder.clearCallingIdentity();
3722 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 } catch (ImsException e) {
3727 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 } finally {
3729 Binder.restoreCallingIdentity(token);
3730 }
3731 }
3732
shilu366312e2019-12-17 09:28:10 -08003733 /**
3734 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3735 * @param subId The subscription to use to check the configuration.
3736 * @param c The callback that will be used to send the result.
3737 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003739 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003740 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3741 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003742 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3743 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3744 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003745 final long token = Binder.clearCallingIdentity();
3746 try {
3747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3748 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3749 .removeRegistrationCallbackForSubscription(c, subId);
3750 } catch (ImsException e) {
3751 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3752 + "is inactive, ignoring unregister.");
3753 // If the subscription is no longer active, just return, since the callback
3754 // will already have been removed internally.
3755 } finally {
3756 Binder.restoreCallingIdentity(token);
3757 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 }
3759
Brad Ebinger774ba362019-10-22 17:36:18 -07003760 /**
3761 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3762 */
3763 @Override
3764 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3765 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3766 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3768 "IMS not available on device.");
3769 }
3770 final long token = Binder.clearCallingIdentity();
3771 try {
3772 Phone phone = getPhone(subId);
3773 if (phone == null) {
3774 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3775 + subId + "'");
3776 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3777 }
3778 phone.getImsRegistrationState(regState -> {
3779 try {
3780 consumer.accept((regState == null)
3781 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3782 } catch (RemoteException e) {
3783 // Ignore if the remote process is no longer available to call back.
3784 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3785 }
3786 });
3787 } finally {
3788 Binder.restoreCallingIdentity(token);
3789 }
3790 }
3791
3792 /**
3793 * Get the transport type for the IMS service registration state.
3794 */
3795 @Override
3796 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003797 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3798 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003799 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3800 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3801 "IMS not available on device.");
3802 }
3803 final long token = Binder.clearCallingIdentity();
3804 try {
3805 Phone phone = getPhone(subId);
3806 if (phone == null) {
3807 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3808 + subId + "'");
3809 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3810 }
3811 phone.getImsRegistrationTech(regTech -> {
3812 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3813 int regTechConverted = (regTech == null)
3814 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3815 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3816 regTechConverted);
3817 try {
3818 consumer.accept(regTechConverted);
3819 } catch (RemoteException e) {
3820 // Ignore if the remote process is no longer available to call back.
3821 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3822 }
3823 });
3824 } finally {
3825 Binder.restoreCallingIdentity(token);
3826 }
3827 }
3828
shilu366312e2019-12-17 09:28:10 -08003829 /**
3830 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3831 * @param subId The subscription to use to check the configuration.
3832 * @param c The callback that will be used to send the result.
3833 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003834 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003835 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3836 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003837 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3838 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003839 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3840 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3841 "IMS not available on device.");
3842 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3844 final long token = Binder.clearCallingIdentity();
3845 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003846 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003848 } catch (ImsException e) {
3849 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 } finally {
3851 Binder.restoreCallingIdentity(token);
3852 }
3853 }
3854
shilu366312e2019-12-17 09:28:10 -08003855 /**
3856 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3857 * @param subId The subscription to use to check the configuration.
3858 * @param c The callback that will be used to send the result.
3859 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003861 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003862 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3863 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3865 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3866 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003867
3868 final long token = Binder.clearCallingIdentity();
3869 try {
3870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3871 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003872 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003873 } catch (ImsException e) {
3874 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3875 + "is inactive, ignoring unregister.");
3876 // If the subscription is no longer active, just return, since the callback
3877 // will already have been removed internally.
3878 } finally {
3879 Binder.restoreCallingIdentity(token);
3880 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 }
3882
3883 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003884 public boolean isCapable(int subId, int capability, int regTech) {
3885 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3887 final long token = Binder.clearCallingIdentity();
3888 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003889 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3893 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003894 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003895 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3896 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 } finally {
3898 Binder.restoreCallingIdentity(token);
3899 }
3900 }
3901
3902 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003903 public boolean isAvailable(int subId, int capability, int regTech) {
3904 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 final long token = Binder.clearCallingIdentity();
3906 try {
3907 Phone phone = getPhone(subId);
3908 if (phone == null) return false;
3909 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003910 } catch (com.android.ims.ImsException e) {
3911 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3912 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(token);
3915 }
3916 }
3917
Brad Ebinger77b832e2019-10-17 17:03:22 -07003918 /**
3919 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3920 * subscription.
3921 * @param subId The subscription to use to check the configuration.
3922 * @param callback The callback that will be used to send the result.
3923 * @param capability The MmTelFeature capability that will be used to send the result.
3924 * @param transportType The transport type of the MmTelFeature capability.
3925 */
3926 @Override
3927 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3928 int transportType) {
3929 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3930 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3932 "IMS not available on device.");
3933 }
3934 final long token = Binder.clearCallingIdentity();
3935 try {
3936 int slotId = getSlotIndex(subId);
3937 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3938 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3939 + subId + "'");
3940 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3941 }
3942 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3943 transportType, aBoolean -> {
3944 try {
3945 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3946 } catch (RemoteException e) {
3947 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3948 + "running. Ignore");
3949 }
3950 });
3951 } finally {
3952 Binder.restoreCallingIdentity(token);
3953 }
3954 }
3955
shilu366312e2019-12-17 09:28:10 -08003956 /**
3957 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3958 * @param subId The subscription to use to check the configuration.
3959 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 @Override
3961 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003962 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3963 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003964
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3966 final long token = Binder.clearCallingIdentity();
3967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
3977 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003978 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003980 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003984 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003986 } catch (ImsException e) {
3987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 } finally {
3989 Binder.restoreCallingIdentity(identity);
3990 }
3991 }
3992
shilu366312e2019-12-17 09:28:10 -08003993 /**
3994 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3995 * @param subId The subscription to use to check the configuration.
3996 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003998 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003999 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4000 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004004 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4005 } catch (ImsException e) {
4006 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
4010 }
4011
4012 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004013 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004015 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004019 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004020 } catch (ImsException e) {
4021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025 }
4026
shilu366312e2019-12-17 09:28:10 -08004027 /**
4028 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4029 * @param subId The subscription to use to check the configuration.
4030 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 @Override
4032 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4034 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004038 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004048 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004050 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 @Override
4067 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004068 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4069 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
4080 }
4081
4082 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004083 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004085 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
4096 }
4097
4098 @Override
4099 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4101 "setVoWiFiNonPersistent");
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004105 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004106 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (ImsException e) {
4108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113
shilu366312e2019-12-17 09:28:10 -08004114 /**
4115 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4116 * @param subId The subscription to use to check the configuration.
4117 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 @Override
4119 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004120 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4121 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004125 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004127 } catch (ImsException e) {
4128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
4132 }
4133
4134 @Override
4135 public void setVoWiFiModeSetting(int subId, int mode) {
4136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4137 "setVoWiFiModeSetting");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
4151 public int getVoWiFiRoamingModeSetting(int subId) {
4152 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
4165 @Override
4166 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4168 "setVoWiFiRoamingModeSetting");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004174 } catch (ImsException e) {
4175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
4179 }
4180
4181 @Override
4182 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4184 "setRttCapabilityEnabled");
4185 final long identity = Binder.clearCallingIdentity();
4186 try {
4187 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4189 } catch (ImsException e) {
4190 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
4194 }
4195
shilu366312e2019-12-17 09:28:10 -08004196 /**
4197 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4198 * @param subId The subscription to use to check the configuration.
4199 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 @Override
4201 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004202 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4203 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 final long identity = Binder.clearCallingIdentity();
4205 try {
4206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004207 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 } catch (ImsException e) {
4210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
4213 }
4214 }
4215
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004216 @Override
4217 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4218 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004221 if (!isImsAvailableOnDevice()) {
4222 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4223 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004224 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004227 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004228 } catch (ImsException e) {
4229 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
4233 }
4234
4235 @Override
4236 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4237 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4238 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004239 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4240 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4241 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004242 try {
4243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004244 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004245 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004246 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004247 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4248 + "is inactive, ignoring unregister.");
4249 // If the subscription is no longer active, just return, since the callback will already
4250 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
allenwtsu99c623b2020-01-03 18:24:23 +08004256
4257 private void checkModifyPhoneStatePermission(int subId, String message) {
4258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4259 message);
4260 }
4261
4262 private boolean isImsProvisioningRequired(int subId, int capability,
4263 boolean isMmtelCapability) {
4264 Phone phone = getPhone(subId);
4265 if (phone == null) {
4266 loge("phone instance null for subid " + subId);
4267 return false;
4268 }
4269 if (isMmtelCapability) {
4270 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4271 return false;
4272 }
4273 } else {
4274 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4275 return false;
4276 }
4277 }
4278 return true;
4279 }
4280
4281 @Override
4282 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4283 boolean isProvisioned) {
4284 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4285
4286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4289 if (!isImsProvisioningRequired(subId, capability, false)) {
4290 return;
4291 }
4292
4293 // this capability requires provisioning, route to the correct API.
4294 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4295 switch (capability) {
4296 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4297 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4298 ims.setEabProvisioned(isProvisioned);
4299 break;
4300 default: {
4301 throw new IllegalArgumentException("Tried to set provisioning for "
4302 + "rcs capability '" + capability + "', which does not require "
4303 + "provisioning.");
4304 }
4305 }
4306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
4309
4310 }
4311
4312
4313 @Override
4314 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4315 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4319 if (!isImsProvisioningRequired(subId, capability, false)) {
4320 return true;
4321 }
4322
4323 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4324 switch (capability) {
4325 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4326 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4327 return ims.isEabProvisionedOnDevice();
4328
4329 default: {
4330 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4331 + "capability '" + capability + "', which does not require "
4332 + "provisioning.");
4333 }
4334 }
4335
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
4339 }
4340
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004341 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004342 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4343 boolean isProvisioned) {
4344 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4345 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4346 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4347 }
allenwtsu99c623b2020-01-03 18:24:23 +08004348 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004352 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 return;
4354 }
4355
4356 // this capability requires provisioning, route to the correct API.
4357 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4358 switch (capability) {
4359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4360 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4361 ims.setVolteProvisioned(isProvisioned);
4362 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4363 ims.setWfcProvisioned(isProvisioned);
4364 }
4365 break;
4366 }
4367 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4368 // There is currently no difference in VT provisioning type.
4369 ims.setVtProvisioned(isProvisioned);
4370 break;
4371 }
4372 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4373 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4374 // change the capability of the feature instead if needed.
4375 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4376 == isProvisioned) {
4377 // No change in provisioning.
4378 return;
4379 }
4380 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4381 try {
4382 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004383 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004384 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4385 + ", Exception" + e.getMessage());
4386 }
4387 break;
4388 }
4389 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004390 throw new IllegalArgumentException("Tried to set provisioning for "
4391 + "MmTel capability '" + capability + "', which does not require "
4392 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004393 }
4394 }
4395
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
4401 @Override
4402 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4403 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4404 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4405 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4406 }
4407 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004411 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004412 return true;
4413 }
4414
4415 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4416 switch (capability) {
4417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4418 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4419 return ims.isVolteProvisionedOnDevice();
4420 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4421 return ims.isWfcProvisionedOnDevice();
4422 }
4423 // This should never happen, since we are checking tech above to make sure it
4424 // is either LTE or IWLAN.
4425 throw new IllegalArgumentException("Invalid radio technology for voice "
4426 + "capability.");
4427 }
4428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4429 // There is currently no difference in VT provisioning type.
4430 return ims.isVtProvisionedOnDevice();
4431 }
4432 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4433 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4434 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4435 }
4436 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004437 throw new IllegalArgumentException(
4438 "Tried to get provisioning for MmTel capability '" + capability
4439 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004440 }
4441 }
4442
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
4448 @Override
4449 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4450 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4451 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4452 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4453 }
4454 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4455 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4456 return (provisionedBits & capability) > 0;
4457 }
4458
4459 @Override
4460 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4461 boolean isProvisioned) {
4462 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4463 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4464 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4465 }
4466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4467 "setProvisioningStatusForCapability");
4468 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4469 // If the current provisioning status for capability already matches isProvisioned,
4470 // do nothing.
4471 if (((provisionedBits & capability) > 0) == isProvisioned) {
4472 return;
4473 }
4474 if (isProvisioned) {
4475 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4476 } else {
4477 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4478 }
4479 }
4480
4481 /**
4482 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4483 * technology. The bitfield should mirror the bitfield defined by
4484 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4485 */
4486 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4487 String key = getMmTelProvisioningKey(subId, tech);
4488 // Default is no capabilities are provisioned.
4489 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4490 }
4491
4492 /**
4493 * Sets the MmTel capability provisioning bitfield (defined by
4494 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4495 * technology specified.
4496 *
4497 * Note: This is a synchronous command and should not be called on UI thread.
4498 */
4499 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4500 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4501 String key = getMmTelProvisioningKey(subId, tech);
4502 editor.putInt(key, newField);
4503 editor.commit();
4504 }
4505
4506 private static String getMmTelProvisioningKey(int subId, int tech) {
4507 // resulting key is provision_ims_mmtel_{subId}_{tech}
4508 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4509 }
4510
4511 /**
4512 * Query CarrierConfig to see if the specified capability requires provisioning for the
4513 * carrier associated with the subscription id.
4514 */
4515 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4516 int capability) {
4517 CarrierConfigManager configManager = new CarrierConfigManager(context);
4518 PersistableBundle c = configManager.getConfigForSubId(subId);
4519 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004520 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4522 false);
4523 boolean requireVoiceVtProvisioning = c.getBoolean(
4524 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4525
4526 // First check to make sure that the capability requires provisioning.
4527 switch (capability) {
4528 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4529 // intentional fallthrough
4530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4531 if (requireVoiceVtProvisioning) {
4532 // Voice and Video requires provisioning
4533 return true;
4534 }
4535 break;
4536 }
4537 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4538 if (requireUtProvisioning) {
4539 // UT requires provisioning
4540 return true;
4541 }
4542 break;
4543 }
4544 }
4545 return false;
4546 }
4547
allenwtsu99c623b2020-01-03 18:24:23 +08004548 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4549 int capability) {
4550 CarrierConfigManager configManager = new CarrierConfigManager(context);
4551 PersistableBundle c = configManager.getConfigForSubId(subId);
4552
4553 boolean requireRcsProvisioning = c.getBoolean(
4554 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4555
4556 // First check to make sure that the capability requires provisioning.
4557 switch (capability) {
4558 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4559 // intentional fallthrough
4560 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4561 if (requireRcsProvisioning) {
4562 // OPTION or PRESENCE requires provisioning
4563 return true;
4564 }
4565 break;
4566 }
4567 }
4568 return false;
4569 }
4570
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004571 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004572 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004573 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4574 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4575 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004576 enforceReadPrivilegedPermission("getImsProvisioningInt");
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 int slotId = getSlotIndex(subId);
4581 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4582 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4583 + subId + "' for key:" + key);
4584 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4585 }
4586 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004587 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004588 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4589 + subId + "' for key:" + key);
4590 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
4594 }
4595
4596 @Override
4597 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4599 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4600 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004601 enforceReadPrivilegedPermission("getImsProvisioningString");
4602 final long identity = Binder.clearCallingIdentity();
4603 try {
4604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 int slotId = getSlotIndex(subId);
4606 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4607 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4608 + subId + "' for key:" + key);
4609 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4610 }
4611 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004612 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004613 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4614 + subId + "' for key:" + key);
4615 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
4619 }
4620
4621 @Override
4622 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4624 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4625 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4627 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 int slotId = getSlotIndex(subId);
4632 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4633 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4634 + subId + "' for key:" + key);
4635 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4636 }
4637 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4640 + "' for key:" + key);
4641 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004642 } finally {
4643 Binder.restoreCallingIdentity(identity);
4644 }
4645 }
4646
4647 @Override
4648 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4650 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4651 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4653 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004654 final long identity = Binder.clearCallingIdentity();
4655 try {
4656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 int slotId = getSlotIndex(subId);
4658 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4659 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4660 + subId + "' for key:" + key);
4661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4662 }
4663 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4666 + "' for key:" + key);
4667 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
4671 }
4672
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 int slotId = SubscriptionManager.getSlotIndex(subId);
4675 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004676 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4677 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004678 }
4679 return slotId;
4680 }
4681
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 private int getSlotIndex(int subId) {
4683 int slotId = SubscriptionManager.getSlotIndex(subId);
4684 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4685 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4686 }
4687 return slotId;
4688 }
4689
Wink Saville36469e72014-06-11 15:17:00 -07004690 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004691 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004692 */
4693 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004694 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4695 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004696 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004697 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004698 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004699 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004700 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004701 mApp, subId, callingPackage, callingFeatureId,
4702 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004703 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4704 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 final Phone phone = getPhone(subId);
4709 if (phone != null) {
4710 return phone.getServiceState().getDataNetworkType();
4711 } else {
4712 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4713 }
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004717 }
4718
4719 /**
4720 * Returns the data network type
4721 */
4722 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004723 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4724 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4725 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004726 }
4727
4728 /**
4729 * Returns the data network type for a subId
4730 */
4731 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004732 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004735 mApp, subId, callingPackage, callingFeatureId,
4736 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004737 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4738 }
4739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 final Phone phone = getPhone(subId);
4743 if (phone != null) {
4744 return phone.getServiceState().getDataNetworkType();
4745 } else {
4746 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4747 }
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004751 }
4752
4753 /**
Wink Saville36469e72014-06-11 15:17:00 -07004754 * Returns the Voice network type for a subId
4755 */
4756 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004757 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4758 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004760 mApp, subId, callingPackage, callingFeatureId,
4761 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4763 }
4764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 final Phone phone = getPhone(subId);
4768 if (phone != null) {
4769 return phone.getServiceState().getVoiceNetworkType();
4770 } else {
4771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4772 }
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004776 }
4777
4778 /**
4779 * @return true if a ICC card is present
4780 */
4781 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004782 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004783 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4784 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004785 }
4786
4787 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004788 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004789 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004790 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004791 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 final long identity = Binder.clearCallingIdentity();
4793 try {
4794 final Phone phone = PhoneFactory.getPhone(slotIndex);
4795 if (phone != null) {
4796 return phone.getIccCard().hasIccCard();
4797 } else {
4798 return false;
4799 }
4800 } finally {
4801 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004802 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004803 }
4804
4805 /**
4806 * Return if the current radio is LTE on CDMA. This
4807 * is a tri-state return value as for a period of time
4808 * the mode may be unknown.
4809 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004810 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004811 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004812 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004813 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004814 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004815 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4816 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4817 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004818 }
4819
Sanket Padawe356d7632015-06-22 14:03:32 -07004820 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004821 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4822 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004823 try {
4824 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4825 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004826 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4827 }
4828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 final Phone phone = getPhone(subId);
4832 if (phone == null) {
4833 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4834 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004835 return TelephonyProperties.lte_on_cdma_device()
4836 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 }
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004840 }
Wink Saville36469e72014-06-11 15:17:00 -07004841 }
4842
Wink Saville36469e72014-06-11 15:17:00 -07004843 /**
4844 * {@hide}
4845 * Returns Default subId, 0 in the case of single standby.
4846 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004847 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004848 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004849 }
4850
Shishir Agrawala9f32182016-04-12 12:00:16 -07004851 private int getSlotForDefaultSubscription() {
4852 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4853 }
4854
Wink Savilleb564aae2014-10-23 10:18:09 -07004855 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004856 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004857 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004858
Pengquan Menge92a50d2018-09-21 15:54:48 -07004859 private boolean isActiveSubscription(int subId) {
4860 return mSubscriptionController.isActiveSubId(subId);
4861 }
4862
Ihab Awadf2177b72013-11-25 13:33:23 -08004863 /**
4864 * @see android.telephony.TelephonyManager.WifiCallingChoices
4865 */
4866 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004869 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4871 getWhenToMakeWifiCallsDefaultPreference());
4872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004875 }
4876
4877 /**
4878 * @see android.telephony.TelephonyManager.WifiCallingChoices
4879 */
4880 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004884 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004889 }
4890
Sailesh Nepald1e68152013-12-12 19:08:02 -08004891 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004892 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004893 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004894 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004895
Jordan Liu4c733742019-02-28 12:03:40 -08004896 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4897 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4898 if (phoneId == -1) {
4899 throw new IllegalArgumentException("Given slot index: " + slotIndex
4900 + " does not correspond to an active phone");
4901 }
4902 return PhoneFactory.getPhone(phoneId);
4903 }
4904
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004906 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4907 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4909 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004911 if (DBG) {
4912 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4913 }
4914 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4915 p2);
4916 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004917
Jordan Liu4c733742019-02-28 12:03:40 -08004918
4919 @Override
4920 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4921 int slotIndex, String callingPackage, String aid, int p2) {
4922 enforceModifyPermission();
4923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4924 if (DBG) {
4925 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4926 }
4927 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4928 callingPackage, aid, p2);
4929 }
4930
4931 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4932 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 if (TextUtils.equals(ISDR_AID, aid)) {
4936 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004937 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4938 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 if (bestComponent == null
4940 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4941 loge("The calling package is not allowed to access ISD-R.");
4942 throw new SecurityException(
4943 "The calling package is not allowed to access ISD-R.");
4944 }
Derek Tan740e1672017-06-27 14:56:27 -07004945 }
Derek Tan740e1672017-06-27 14:56:27 -07004946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004948 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4949 null /* workSource */);
4950 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 return response;
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004955 }
4956
4957 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004958 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004961 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4962 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4963 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004964
Jordan Liu4c733742019-02-28 12:03:40 -08004965 @Override
4966 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4967 enforceModifyPermission();
4968 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4969 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4970 channel);
4971 }
4972
4973 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 final long identity = Binder.clearCallingIdentity();
4975 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 if (channel < 0) {
4977 return false;
4978 }
Jordan Liu4c733742019-02-28 12:03:40 -08004979 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4980 null /* workSource */);
4981 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 return success;
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004986 }
4987
4988 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004989 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004990 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4992 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004993 if (DBG) {
4994 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4995 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4996 + p3 + " data=" + data);
4997 }
4998 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4999 command, p1, p2, p3, data);
5000 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005001
Jordan Liu4c733742019-02-28 12:03:40 -08005002 @Override
5003 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5004 int command, int p1, int p2, int p3, String data) {
5005 enforceModifyPermission();
5006 if (DBG) {
5007 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5008 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5009 + p3 + " data=" + data);
5010 }
5011 return iccTransmitApduLogicalChannelWithPermission(
5012 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5013 data);
5014 }
5015
5016 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5017 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005020 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 return "";
5022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005025 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5026 null /* workSource */);
5027 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 // Append the returned status code to the end of the response payload.
5030 String s = Integer.toHexString(
5031 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5032 if (response.payload != null) {
5033 s = IccUtils.bytesToHexString(response.payload) + s;
5034 }
5035 return s;
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005038 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005039 }
Jake Hambye994d462014-02-03 13:10:13 -08005040
Evan Charltonc66da362014-05-16 14:06:40 -07005041 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005042 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5043 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5045 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005047 if (DBG) {
5048 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5049 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5050 }
5051 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5052 cla, command, p1, p2, p3, data);
5053 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005054
Jordan Liu4c733742019-02-28 12:03:40 -08005055 @Override
5056 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5057 int command, int p1, int p2, int p3, String data) {
5058 enforceModifyPermission();
5059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5060 if (DBG) {
5061 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5062 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5063 + " data=" + data);
5064 }
5065
5066 return iccTransmitApduBasicChannelWithPermission(
5067 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5068 p2, p3, data);
5069 }
5070
5071 // open APDU basic channel assuming the caller has sufficient permissions
5072 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5073 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5077 && TextUtils.equals(ISDR_AID, data)) {
5078 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005079 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5080 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 if (bestComponent == null
5082 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5083 loge("The calling package is not allowed to select ISD-R.");
5084 throw new SecurityException(
5085 "The calling package is not allowed to select ISD-R.");
5086 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005087 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005090 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5091 null /* workSource */);
5092 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 // Append the returned status code to the end of the response payload.
5095 String s = Integer.toHexString(
5096 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5097 if (response.payload != null) {
5098 s = IccUtils.bytesToHexString(response.payload) + s;
5099 }
5100 return s;
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005103 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005104 }
5105
5106 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005107 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005108 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5110 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 if (DBG) {
5115 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5116 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5117 }
5118
5119 IccIoResult response =
5120 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5121 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5122 subId);
5123
5124 if (DBG) {
5125 log("Exchange SIM_IO [R]" + response);
5126 }
5127
5128 byte[] result = null;
5129 int length = 2;
5130 if (response.payload != null) {
5131 length = 2 + response.payload.length;
5132 result = new byte[length];
5133 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5134 } else {
5135 result = new byte[length];
5136 }
5137
5138 result[length - 1] = (byte) response.sw2;
5139 result[length - 2] = (byte) response.sw1;
5140 return result;
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005143 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005144 }
5145
Nathan Haroldb3014052017-01-25 15:57:32 -08005146 /**
5147 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5148 * on a particular subscription
5149 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005150 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5151 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005153 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005154 return null;
5155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156
5157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 if (appType != TelephonyManager.APPTYPE_USIM
5160 && appType != TelephonyManager.APPTYPE_SIM) {
5161 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5162 return null;
5163 }
5164 Object response = sendRequest(
5165 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5166 if (response instanceof String[]) {
5167 return (String[]) response;
5168 }
yincheng zhaod698b842019-09-06 17:06:54 -07005169 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005171 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005174 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005175 }
5176
yincheng zhaod698b842019-09-06 17:06:54 -07005177 /**
5178 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5179 * subscription.
5180 *
5181 * @param subId the id of the subscription.
5182 * @param appType the uicc app type, must be USIM or SIM.
5183 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5184 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005185 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005186 * @return number of fplmns that is successfully written to the SIM.
5187 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005188 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5189 String callingFeatureId) {
5190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5191 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005192 if (DBG) logv("no permissions for setForbiddenplmns");
5193 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5194 }
5195 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5196 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5197 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5198 }
5199 if (fplmns == null) {
5200 throw new IllegalArgumentException("Fplmn List provided is null");
5201 }
5202 for (String fplmn : fplmns) {
5203 if (!CellIdentity.isValidPlmn(fplmn)) {
5204 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5205 }
5206 }
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 Object response = sendRequest(
5210 CMD_SET_FORBIDDEN_PLMNS,
5211 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5212 subId);
5213 return (int) response;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
5217 }
5218
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005220 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5227 if (response.payload == null) {
5228 return "";
5229 }
Evan Charltonc66da362014-05-16 14:06:40 -07005230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 // Append the returned status code to the end of the response payload.
5232 String s = Integer.toHexString(
5233 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5234 s = IccUtils.bytesToHexString(response.payload) + s;
5235 return s;
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Evan Charltonc66da362014-05-16 14:06:40 -07005239 }
5240
Jake Hambye994d462014-02-03 13:10:13 -08005241 /**
5242 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5243 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5244 *
5245 * @param itemID the ID of the item to read
5246 * @return the NV item as a String, or null on error.
5247 */
5248 @Override
5249 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005250 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5252 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253
5254 final long identity = Binder.clearCallingIdentity();
5255 try {
5256 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005257 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5259 return value;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Jake Hambye994d462014-02-03 13:10:13 -08005263 }
5264
5265 /**
5266 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5267 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5268 *
5269 * @param itemID the ID of the item to read
5270 * @param itemValue the value to write, as a String
5271 * @return true on success; false on any failure
5272 */
5273 @Override
5274 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
5279 final long identity = Binder.clearCallingIdentity();
5280 try {
5281 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5282 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005283 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5285 return success;
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Jake Hambye994d462014-02-03 13:10:13 -08005289 }
5290
5291 /**
5292 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5293 * Used for device configuration by some CDMA operators.
5294 *
5295 * @param preferredRoamingList byte array containing the new PRL
5296 * @return true on success; false on any failure
5297 */
5298 @Override
5299 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5301 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302
5303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5306 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5307 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5308 return success;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Jake Hambye994d462014-02-03 13:10:13 -08005312 }
5313
5314 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005315 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005316 * Used for device configuration by some CDMA operators.
5317 *
chen xu6dac5ab2018-10-26 17:39:23 -07005318 * @param slotIndex - device slot.
5319 *
Jake Hambye994d462014-02-03 13:10:13 -08005320 * @return true on success; false on any failure
5321 */
5322 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005323 public boolean resetModemConfig(int slotIndex) {
5324 Phone phone = PhoneFactory.getPhone(slotIndex);
5325 if (phone != null) {
5326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328
chen xu6dac5ab2018-10-26 17:39:23 -07005329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5332 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5333 return success;
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
5336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 }
chen xu6dac5ab2018-10-26 17:39:23 -07005338 return false;
5339 }
5340
5341 /**
5342 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5343 *
5344 * @param slotIndex - device slot.
5345 *
5346 * @return true on success; false on any failure
5347 */
5348 @Override
5349 public boolean rebootModem(int slotIndex) {
5350 Phone phone = PhoneFactory.getPhone(slotIndex);
5351 if (phone != null) {
5352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5353 mApp, phone.getSubId(), "rebootModem");
5354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5358 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5359 return success;
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
5363 }
5364 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005365 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005366
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005367 public String[] getPcscfAddress(String apnType, String callingPackage,
5368 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005369 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5371 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005372 return new String[0];
5373 }
5374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005377 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Wink Saville36469e72014-06-11 15:17:00 -07005381 }
5382
Brad Ebinger51f743a2017-01-23 13:50:20 -08005383 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005384 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5385 * {@link #disableIms(int)}.
5386 * @param slotIndex device slot.
5387 */
5388 public void resetIms(int slotIndex) {
5389 enforceModifyPermission();
5390
5391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 if (mImsResolver == null) {
5394 // may happen if the does not support IMS.
5395 return;
5396 }
5397 mImsResolver.disableIms(slotIndex);
5398 mImsResolver.enableIms(slotIndex);
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
5402 }
5403
5404 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005405 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5406 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005407 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005408 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005409 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005413 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005414 // may happen if the device does not support IMS.
5415 return;
5416 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005417 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005421 }
5422
5423 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005424 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5425 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005426 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005427 public void disableIms(int slotId) {
5428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429
5430 final long identity = Binder.clearCallingIdentity();
5431 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005432 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005433 // may happen if the device does not support IMS.
5434 return;
5435 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005436 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005440 }
5441
5442 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005443 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5444 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005445 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005446 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005447 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005452 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005453 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5454 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005455 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005456 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005460 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005461 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005462 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5463 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005464 @Override
5465 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005466 enforceModifyPermission();
5467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005471 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
5475 }
5476
5477 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005478 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005479 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005480 */
5481 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005486 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005487 // may happen if the device does not support IMS.
5488 return null;
5489 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005494 }
5495
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005496 /**
5497 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005498 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005499 */
5500 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502
5503 final long identity = Binder.clearCallingIdentity();
5504 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005505 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005506 // may happen if the device does not support IMS.
5507 return null;
5508 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005513 }
5514
Brad Ebinger884c07b2018-02-15 16:17:40 -08005515 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005516 * Sets the ImsService Package Name that Telephony will bind to.
5517 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005518 * @param slotIndex the slot ID that the ImsService should bind for.
5519 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005520 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005521 * @param featureTypes An integer array of feature types associated with a packageName.
5522 * @param packageName The name of the package that the current configuration will be replaced
5523 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005524 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005525 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005526 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5527 int[] featureTypes, String packageName) {
5528 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5529 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5531 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005532 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 final long identity = Binder.clearCallingIdentity();
5535 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005536 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005537 // may happen if the device does not support IMS.
5538 return false;
5539 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005540 Map<Integer, String> featureConfig = new HashMap<>();
5541 for (int featureType : featureTypes) {
5542 featureConfig.put(featureType, packageName);
5543 }
5544 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5545 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005549 }
5550
5551 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005552 * Clears any carrier ImsService overrides for the slot index specified that were previously
5553 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5554 *
5555 * This should only be used for testing.
5556 *
5557 * @param slotIndex the slot ID that the ImsService should bind for.
5558 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5559 */
5560 @Override
5561 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5562 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5564 "clearCarrierImsServiceOverride");
5565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5566 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5567 "clearCarrierImsServiceOverride");
5568
5569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 if (mImsResolver == null) {
5572 // may happen if the device does not support IMS.
5573 return false;
5574 }
5575 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
5579 }
5580
5581 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005583 *
5584 * @param slotId The slot that the ImsService is associated with.
5585 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5586 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005587 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005588 * @return the package name of the ImsService configuration.
5589 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005590 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5591 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005592 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005593 TelephonyPermissions
5594 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5595 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5596 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 final long identity = Binder.clearCallingIdentity();
5599 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005600 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005601 // may happen if the device does not support IMS.
5602 return "";
5603 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005604 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005605 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5606 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005610 }
5611
Brad Ebinger77b832e2019-10-17 17:03:22 -07005612 /**
5613 * Get the MmTelFeature state associated with the requested subscription id.
5614 * @param subId The subscription that the MmTelFeature is associated with.
5615 * @param callback A callback with an integer containing the
5616 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5617 */
5618 @Override
5619 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5620 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5621 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5622 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5623 "IMS not available on device.");
5624 }
5625 final long token = Binder.clearCallingIdentity();
5626 try {
5627 int slotId = getSlotIndex(subId);
5628 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5629 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5630 + subId + "'");
5631 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5632 }
5633 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5634 try {
5635 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5636 } catch (RemoteException e) {
5637 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5638 + "Ignore");
5639 }
5640 });
5641 } finally {
5642 Binder.restoreCallingIdentity(token);
5643 }
5644 }
5645
Daniel Brightbb5840b2021-01-12 15:48:18 -08005646 /**
5647 * Sets the ims registration state on all valid {@link Phone}s.
5648 */
5649 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005654 // NOTE: Before S, this method only set the default phone.
5655 for (final Phone phone : PhoneFactory.getPhones()) {
5656 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5657 phone.setImsRegistrationState(registered);
5658 }
5659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
Wink Saville36469e72014-06-11 15:17:00 -07005663 }
5664
5665 /**
Stuart Scott54788802015-03-30 13:18:01 -07005666 * Set the network selection mode to automatic.
5667 *
5668 */
5669 @Override
5670 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
shilufc958392020-01-20 11:36:01 -08005676 if (!isActiveSubscription(subId)) {
5677 return;
5678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005680 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5681 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Stuart Scott54788802015-03-30 13:18:01 -07005685 }
5686
Jack Yud10cdd42020-09-28 20:28:01 -07005687 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005688 * Ask the radio to connect to the input network and change selection mode to manual.
5689 *
5690 * @param subId the id of the subscription.
5691 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5692 * the operator to attach to.
5693 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5694 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5695 * normal network selection next time.
5696 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005697 */
5698 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005699 public boolean setNetworkSelectionModeManual(
5700 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5702 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005703
5704 if (!isActiveSubscription(subId)) {
5705 return false;
5706 }
5707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005710 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005712 if (DBG) {
5713 log("setNetworkSelectionModeManual: subId: " + subId
5714 + " operator: " + operatorInfo);
5715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005720 }
shilu84f6e8b2019-12-19 13:58:01 -08005721 /**
5722 * Get the manual network selection
5723 *
5724 * @param subId the id of the subscription.
5725 *
5726 * @return the previously saved user selected PLMN
5727 */
5728 @Override
5729 public String getManualNetworkSelectionPlmn(int subId) {
5730 TelephonyPermissions
5731 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5732 mApp, subId, "getManualNetworkSelectionPlmn");
5733
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 if (!isActiveSubscription(subId)) {
5737 return "";
5738 }
5739
5740 final Phone phone = getPhone(subId);
5741 if (phone == null) {
5742 return "";
5743 }
5744 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5745 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5746 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005751
5752 /**
5753 * Scans for available networks.
5754 */
5755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005756 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5757 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5759 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005760 LocationAccessPolicy.LocationPermissionResult locationResult =
5761 LocationAccessPolicy.checkLocationPermission(mApp,
5762 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5763 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005764 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005765 .setCallingPid(Binder.getCallingPid())
5766 .setCallingUid(Binder.getCallingUid())
5767 .setMethod("getCellNetworkScanResults")
5768 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5769 .build());
5770 switch (locationResult) {
5771 case DENIED_HARD:
5772 throw new SecurityException("Not allowed to access scan results -- location");
5773 case DENIED_SOFT:
5774 return null;
5775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776
Pengquan Menga1bb6272018-09-06 09:59:22 -07005777 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 try {
5779 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005780 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005785 }
5786
5787 /**
sqian80370722020-01-29 15:02:51 -08005788 * Get the call forwarding info, given the call forwarding reason.
5789 */
5790 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005791 public void getCallForwarding(int subId, int callForwardingReason,
5792 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005793 enforceReadPrivilegedPermission("getCallForwarding");
5794 long identity = Binder.clearCallingIdentity();
5795 try {
5796 if (DBG) {
5797 log("getCallForwarding: subId " + subId
5798 + " callForwardingReason" + callForwardingReason);
5799 }
Hall Liua1acea22020-09-18 19:04:59 -07005800
5801 Phone phone = getPhone(subId);
5802 if (phone == null) {
5803 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005804 callback.onError(
5805 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005806 } catch (RemoteException e) {
5807 // ignore
5808 }
5809 return;
5810 }
5811
5812 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5813 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5814 @Override
5815 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5816 try {
5817 callback.onCallForwardingInfoAvailable(info);
5818 } catch (RemoteException e) {
5819 // ignore
5820 }
5821 }
5822
5823 @Override
5824 public void onError(int error) {
5825 try {
5826 callback.onError(error);
5827 } catch (RemoteException e) {
5828 // ignore
5829 }
5830 }
5831 });
5832 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
5838 /**
5839 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5840 * reason, the number to forward, and the timeout before the forwarding is attempted.
5841 */
5842 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005843 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5844 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005845 enforceModifyPermission();
5846 long identity = Binder.clearCallingIdentity();
5847 try {
5848 if (DBG) {
5849 log("setCallForwarding: subId " + subId
5850 + " callForwardingInfo" + callForwardingInfo);
5851 }
Hall Liua1acea22020-09-18 19:04:59 -07005852
5853 Phone phone = getPhone(subId);
5854 if (phone == null) {
5855 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005856 callback.accept(
5857 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005858 } catch (RemoteException e) {
5859 // ignore
5860 }
5861 return;
5862 }
5863
5864 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5865 FunctionalUtils.ignoreRemoteException(callback::accept));
5866
5867 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
5871 }
5872
5873 /**
Hall Liua1acea22020-09-18 19:04:59 -07005874 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005875 */
5876 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005877 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005878 enforceReadPrivilegedPermission("getCallForwarding");
5879 long identity = Binder.clearCallingIdentity();
5880 try {
Hall Liua1acea22020-09-18 19:04:59 -07005881
5882 Phone phone = getPhone(subId);
5883 if (phone == null) {
5884 try {
5885 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5886 } catch (RemoteException e) {
5887 // ignore
5888 }
5889 return;
5890 }
5891
5892 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5893
sqian80370722020-01-29 15:02:51 -08005894 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005895 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
5899 }
5900
5901 /**
Hall Liua1acea22020-09-18 19:04:59 -07005902 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005903 */
5904 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005905 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005906 enforceModifyPermission();
5907 long identity = Binder.clearCallingIdentity();
5908 try {
Hall Liua1acea22020-09-18 19:04:59 -07005909 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5910
5911 Phone phone = getPhone(subId);
5912 if (phone == null) {
5913 try {
5914 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5915 } catch (RemoteException e) {
5916 // ignore
5917 }
5918 return;
5919 }
5920
5921 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5922 FunctionalUtils.ignoreRemoteException(callback::accept));
5923
5924 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
5928 }
5929
5930 /**
yinxub1bed742017-04-17 11:45:04 -07005931 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005932 *
yinxub1bed742017-04-17 11:45:04 -07005933 * @param subId id of the subscription
5934 * @param request contains the radio access networks with bands/channels to scan
5935 * @param messenger callback messenger for scan results or errors
5936 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005937 * @return the id of the requested scan which can be used to stop the scan.
5938 */
5939 @Override
5940 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005941 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005944 LocationAccessPolicy.LocationPermissionResult locationResult =
5945 LocationAccessPolicy.checkLocationPermission(mApp,
5946 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5947 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005948 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005949 .setCallingPid(Binder.getCallingPid())
5950 .setCallingUid(Binder.getCallingUid())
5951 .setMethod("requestNetworkScan")
5952 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5953 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005954 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005955 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5956 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005957 if (e != null) {
5958 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5959 throw e;
5960 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005961 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005962 return TelephonyScanManager.INVALID_SCAN_ID;
5963 }
5964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 }
Hall Liu912dfd32019-04-25 14:02:26 -07005966 int callingUid = Binder.getCallingUid();
5967 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 return mNetworkScanRequestTracker.startNetworkScan(
5971 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005972 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005973 } finally {
5974 Binder.restoreCallingIdentity(identity);
5975 }
yinxu504e1392017-04-12 16:03:22 -07005976 }
5977
Hall Liub2ac8ef2019-02-28 15:56:23 -08005978 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005979 NetworkScanRequest request, int subId, String callingPackage) {
5980 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005981 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5982 boolean hasNetworkScanPermission =
5983 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5984 == PERMISSION_GRANTED;
5985
5986 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5987 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5988 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005989 }
5990
5991 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5992 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005993 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5994 return new SecurityException("Specific channels must not be"
5995 + " scanned without location access.");
5996 }
5997 }
5998 }
5999
Hall Liub2ac8ef2019-02-28 15:56:23 -08006000 return null;
6001 }
6002
yinxu504e1392017-04-12 16:03:22 -07006003 /**
6004 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006005 *
6006 * @param subId id of the subscription
6007 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006008 */
6009 @Override
6010 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013
Hall Liu912dfd32019-04-25 14:02:26 -07006014 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006017 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
yinxu504e1392017-04-12 16:03:22 -07006021 }
6022
6023 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006024 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006025 *
SongFerngWang9e060372020-12-21 16:41:52 +08006026 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006027 */
6028 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006029 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006030 TelephonyPermissions
6031 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006032 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006036 if (DBG) log("getAllowedNetworkTypesBitmask");
6037 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6038 int networkTypesBitmask = (result != null ? result[0] : -1);
6039 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6040 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006044 }
6045
6046 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006047 * Get the allowed network types for certain reason.
6048 *
6049 * @param subId the id of the subscription.
6050 * @param reason the reason the allowed network type change is taking place
6051 * @return the allowed network types.
6052 */
6053 @Override
6054 public long getAllowedNetworkTypesForReason(int subId,
6055 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang522637d2021-03-02 22:09:29 +08006056 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6057 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006058 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 Sasindrandfd595b2021-03-11 17:38:13 -08006084 if (isRadioInterfaceCapabilitySupported(
6085 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 Sasindrandfd595b2021-03-11 17:38:13 -08006111 if (isRadioInterfaceCapabilitySupported(
6112 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 Sasindran1f812e02020-10-30 13:17:53 -07006128 * get carrier bandwidth per primary and secondary carrier
6129 * @param subId subscription id of the sim card
6130 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6131 */
6132 @Override
6133 public CarrierBandwidth getCarrierBandwidth(int subId) {
6134 TelephonyPermissions
6135 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6136 mApp, subId, "isNRDualConnectivityEnabled");
6137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 CarrierBandwidth carrierBandwidth =
6141 getPhoneFromSubId(subId).getCarrierBandwidth();
6142 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6143 return carrierBandwidth;
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
6147 }
6148
6149 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006150 * Set the allowed network types of the device and
6151 * provide the reason triggering the allowed network change.
6152 *
6153 * @param subId the id of the subscription.
6154 * @param reason the reason the allowed network type change is taking place
6155 * @param allowedNetworkTypes the allowed network types.
6156 * @return true on success; false on any failure.
6157 */
6158 @Override
6159 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006160 @TelephonyManager.AllowedNetworkTypesReason int reason,
6161 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6163 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006164 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6165 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6166 return false;
6167 }
6168
SongFerngWang522637d2021-03-02 22:09:29 +08006169 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6170 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6171
6172
6173 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6174 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6175 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006176 }
SongFerngWang522637d2021-03-02 22:09:29 +08006177
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006178 final long identity = Binder.clearCallingIdentity();
6179 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006180 Boolean success = (Boolean) sendRequest(
6181 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6182 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6183
6184 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6185 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
6189 }
6190
6191 /**
Miaoa84611c2019-03-15 09:21:10 +08006192 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006193 *
Miaoa84611c2019-03-15 09:21:10 +08006194 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006195 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006196 * @hide
6197 */
6198 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006199 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006202 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 try {
Miaoa84611c2019-03-15 09:21:10 +08006204 if (phone != null) {
6205 return phone.hasMatchedTetherApnSetting();
6206 } else {
6207 return false;
6208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006211 }
Junda Liu475951f2014-11-07 16:45:03 -08006212 }
6213
6214 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006215 * Enable or disable always reporting signal strength changes from radio.
6216 *
6217 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6218 */
6219 @Override
6220 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6221 enforceModifyPermission();
6222 enforceSystemCaller();
6223
6224 final long identity = Binder.clearCallingIdentity();
6225 final Phone phone = getPhone(subId);
6226 try {
6227 if (phone != null) {
6228 if (DBG) {
6229 log("setAlwaysReportSignalStrength: subId=" + subId
6230 + " isEnable=" + isEnable);
6231 }
6232 phone.setAlwaysReportSignalStrength(isEnable);
6233 } else {
6234 loge("setAlwaysReportSignalStrength: no phone found for subId="
6235 + subId);
6236 }
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
6240 }
6241
6242 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006243 * Get the user enabled state of Mobile Data.
6244 *
6245 * TODO: remove and use isUserDataEnabled.
6246 * This can't be removed now because some vendor codes
6247 * calls through ITelephony directly while they should
6248 * use TelephonyManager.
6249 *
6250 * @return true on enabled
6251 */
6252 @Override
6253 public boolean getDataEnabled(int subId) {
6254 return isUserDataEnabled(subId);
6255 }
6256
6257 /**
6258 * Get whether mobile data is enabled per user setting.
6259 *
6260 * There are other factors deciding whether mobile data is actually enabled, but they are
6261 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006262 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006263 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006264 *
6265 * @return {@code true} if data is enabled else {@code false}
6266 */
6267 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006268 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006269 try {
6270 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6271 null);
6272 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6274 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276
6277 final long identity = Binder.clearCallingIdentity();
6278 try {
6279 int phoneId = mSubscriptionController.getPhoneId(subId);
6280 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6281 Phone phone = PhoneFactory.getPhone(phoneId);
6282 if (phone != null) {
6283 boolean retVal = phone.isUserDataEnabled();
6284 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6285 return retVal;
6286 } else {
6287 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6288 return false;
6289 }
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006292 }
6293 }
6294
6295 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006296 * Checks if the device is capable of mobile data by considering whether whether the
6297 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6298 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006299 *
Shuo Qian985d1232020-01-08 14:30:06 -08006300 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006301 */
6302 @Override
6303 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006304 try {
6305 try {
6306 mApp.enforceCallingOrSelfPermission(
6307 android.Manifest.permission.ACCESS_NETWORK_STATE,
6308 null);
6309 } catch (Exception e) {
6310 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6311 "isDataEnabled");
6312 }
6313 } catch (Exception e) {
6314 enforceReadPrivilegedPermission("isDataEnabled");
6315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316
6317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 int phoneId = mSubscriptionController.getPhoneId(subId);
6320 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6321 Phone phone = PhoneFactory.getPhone(phoneId);
6322 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006323 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6325 return retVal;
6326 } else {
6327 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6328 return false;
6329 }
6330 } finally {
6331 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006332 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006333 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006334
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006335 /**
6336 * Check if data is enabled for a specific reason
6337 * @param subId Subscription index
6338 * @param reason the reason the data enable change is taking place
6339 * @return {@code true} if the overall data is enabled; {@code false} if not.
6340 */
6341 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006342 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006343 @TelephonyManager.DataEnabledReason int reason) {
6344 try {
6345 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6346 null);
6347 } catch (Exception e) {
6348 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006349 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006350 }
6351
6352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 int phoneId = mSubscriptionController.getPhoneId(subId);
6356 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006357 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006358 + " reason=" + reason);
6359 }
6360 Phone phone = PhoneFactory.getPhone(phoneId);
6361 if (phone != null) {
6362 boolean retVal;
6363 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6364 retVal = phone.isUserDataEnabled();
6365 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006366 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006367 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006368 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006369 return retVal;
6370 } else {
6371 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006372 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006373 + subId + " retVal=false");
6374 }
6375 return false;
6376 }
6377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
6380 }
6381
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006382 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006383 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006384 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6385 // Skip the check if it's one of these special uids
6386 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6387 }
6388
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006389 //load access rules from carrier configs, and check those as well: b/139133814
6390 SubscriptionController subController = SubscriptionController.getInstance();
6391 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6392 || subController == null) return privilegeFromSim;
6393
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006394 PackageManager pkgMgr = phone.getContext().getPackageManager();
6395 String[] packages = pkgMgr.getPackagesForUid(uid);
6396
6397 final long identity = Binder.clearCallingIdentity();
6398 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006399 int subId = phone.getSubId();
6400 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6401 // A test override is in place for the privileges for this subId, so don't try to
6402 // read the subscription privileges.
6403 return privilegeFromSim;
6404 }
6405 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006406 SubscriptionManager subManager = (SubscriptionManager)
6407 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6408 for (String pkg : packages) {
6409 if (subManager.canManageSubscription(subInfo, pkg)) {
6410 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6411 }
6412 }
6413 return privilegeFromSim;
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
6417 }
6418
6419 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6420 String pkgName) {
6421 //load access rules from carrier configs, and check those as well: b/139133814
6422 SubscriptionController subController = SubscriptionController.getInstance();
6423 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6424 || subController == null) return privilegeFromSim;
6425
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006428 int subId = phone.getSubId();
6429 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6430 // A test override is in place for the privileges for this subId, so don't try to
6431 // read the subscription privileges.
6432 return privilegeFromSim;
6433 }
6434 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006435 SubscriptionManager subManager = (SubscriptionManager)
6436 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6437 return subManager.canManageSubscription(subInfo, pkgName)
6438 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006444 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006445 public int getCarrierPrivilegeStatus(int subId) {
6446 final Phone phone = getPhone(subId);
6447 if (phone == null) {
6448 loge("getCarrierPrivilegeStatus: Invalid subId");
6449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6450 }
6451 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006452 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006453 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006454 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6455 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006456
6457 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6458 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006459 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006460 }
Junda Liu29340342014-07-10 15:23:27 -07006461
6462 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006463 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006464 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006465 final Phone phone = getPhone(subId);
6466 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006467 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006468 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6469 }
6470 UiccProfile profile =
6471 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6472 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006473 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006474 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6475 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006476 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006477 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006478 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006479 }
6480
6481 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006482 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6483 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006484 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006485 }
6486
6487 int phoneId = SubscriptionManager.getPhoneId(subId);
6488 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006489 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006490 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006491 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6492 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006493 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6494 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6495 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006496 }
6497
6498 @Override
6499 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006500 if (TextUtils.isEmpty(pkgName))
6501 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006502 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6503 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6504 UiccCard card = UiccController.getInstance().getUiccCard(i);
6505 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006506 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006507 continue;
6508 }
6509
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006510 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6511 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6512 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006513 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6514 break;
6515 }
6516 }
6517
6518 return result;
Junda Liu29340342014-07-10 15:23:27 -07006519 }
Derek Tan89e89d42014-07-08 17:00:10 -07006520
6521 @Override
Junda Liue64de782015-04-16 17:19:16 -07006522 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6523 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6524 loge("phoneId " + phoneId + " is not valid.");
6525 return null;
6526 }
6527 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006528 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006529 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006530 return null ;
6531 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006532 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006533 }
6534
Amith Yamasani6e118872016-02-19 12:53:51 -08006535 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006536 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006537 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006538 List<String> privilegedPackages = new ArrayList<>();
6539 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006540 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6541 // has UICC in that slot.
6542 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006543 if (card.hasCarrierPrivilegeRules()) {
6544 if (packages == null) {
6545 // Only check packages in user 0 for now
6546 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006547 PackageManager.MATCH_DISABLED_COMPONENTS
6548 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006549 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006550 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006551 }
6552 for (int p = packages.size() - 1; p >= 0; p--) {
6553 PackageInfo pkgInfo = packages.get(p);
6554 if (pkgInfo != null && pkgInfo.packageName != null
6555 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006556 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006557 privilegedPackages.add(pkgInfo.packageName);
6558 }
6559 }
6560 }
6561 }
6562 return privilegedPackages;
6563 }
6564
chen xuf7e9fe82019-05-09 19:31:02 -07006565 @Override
6566 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006567 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6568
6569 final long identity = Binder.clearCallingIdentity();
6570
chen xuf7e9fe82019-05-09 19:31:02 -07006571 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006572 try {
6573 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6574 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6575 }
6576 } finally {
6577 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006578 }
6579 return privilegedPackages;
6580 }
6581
Wink Savilleb564aae2014-10-23 10:18:09 -07006582 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006583 final Phone phone = getPhone(subId);
6584 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006585 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006586 return null;
6587 }
6588 String iccId = card.getIccId();
6589 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006590 return null;
6591 }
6592 return iccId;
6593 }
6594
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006595 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006596 public void setCallComposerStatus(int subId, int status) {
6597 enforceModifyPermission();
6598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 Phone phone = getPhone(subId);
6602 if (phone != null) {
6603 Phone defaultPhone = phone.getImsPhone();
6604 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6605 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6606 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006607 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6608 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006609 }
6610 }
Shuo Qiand8782462020-12-22 19:10:14 -08006611 } catch (ImsException e) {
6612 throw new ServiceSpecificException(e.getCode());
6613 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006614 Binder.restoreCallingIdentity(identity);
6615 }
6616 }
6617
6618 @Override
6619 public int getCallComposerStatus(int subId) {
6620 enforceReadPrivilegedPermission("getCallComposerStatus");
6621
6622 final long identity = Binder.clearCallingIdentity();
6623 try {
6624 Phone phone = getPhone(subId);
6625 if (phone != null) {
6626 Phone defaultPhone = phone.getImsPhone();
6627 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6628 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6629 return imsPhone.getCallComposerStatus();
6630 }
6631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6636 }
6637
6638 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006639 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6640 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006641 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006642 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644 final long identity = Binder.clearCallingIdentity();
6645 try {
6646 final String iccId = getIccId(subId);
6647 final Phone phone = getPhone(subId);
6648 if (phone == null) {
6649 return false;
6650 }
6651 final String subscriberId = phone.getSubscriberId();
6652
6653 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006654 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 + subscriberId + " to " + number);
6656 }
6657
6658 if (TextUtils.isEmpty(iccId)) {
6659 return false;
6660 }
6661
6662 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6663
6664 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6665 if (alphaTag == null) {
6666 editor.remove(alphaTagPrefKey);
6667 } else {
6668 editor.putString(alphaTagPrefKey, alphaTag);
6669 }
6670
6671 // Record both the line number and IMSI for this ICCID, since we need to
6672 // track all merged IMSIs based on line number
6673 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6674 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6675 if (number == null) {
6676 editor.remove(numberPrefKey);
6677 editor.remove(subscriberPrefKey);
6678 } else {
6679 editor.putString(numberPrefKey, number);
6680 editor.putString(subscriberPrefKey, subscriberId);
6681 }
6682
6683 editor.commit();
6684 return true;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006687 }
Derek Tan7226c842014-07-02 17:42:23 -07006688 }
6689
6690 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006691 public String getLine1NumberForDisplay(int subId, String callingPackage,
6692 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006693 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006695 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006696 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006697 return null;
6698 }
Derek Tan97ebb422014-09-05 16:55:38 -07006699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 String iccId = getIccId(subId);
6703 if (iccId != null) {
6704 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6705 if (DBG_MERGE) {
6706 log("getLine1NumberForDisplay returning "
6707 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6708 }
6709 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6712 return null;
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006715 }
Derek Tan7226c842014-07-02 17:42:23 -07006716 }
6717
6718 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006719 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6720 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006722 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006723 return null;
6724 }
Derek Tan97ebb422014-09-05 16:55:38 -07006725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 final long identity = Binder.clearCallingIdentity();
6727 try {
6728 String iccId = getIccId(subId);
6729 if (iccId != null) {
6730 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6731 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6732 }
6733 return null;
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006736 }
Derek Tan7226c842014-07-02 17:42:23 -07006737 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006738
6739 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006740 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6741 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006742 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6743 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006745 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006746 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006747 return null;
6748 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006749
Jordan Liub49b04b2019-05-06 14:45:15 -07006750 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6751 // the process, where TelephonyManager was instantiated.
6752 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006753 final long identity = Binder.clearCallingIdentity();
6754 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006755 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 final TelephonyManager tele = TelephonyManager.from(context);
6757 final SubscriptionManager sub = SubscriptionManager.from(context);
6758
6759 // Figure out what subscribers are currently active
6760 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761
Jordan Liub49b04b2019-05-06 14:45:15 -07006762 // Only consider subs which match the current subId
6763 // This logic can be simplified. See b/131189269 for progress.
6764 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006765 activeSubscriberIds.add(tele.getSubscriberId(subId));
6766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767
6768 // First pass, find a number override for an active subscriber
6769 String mergeNumber = null;
6770 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6771 for (String key : prefs.keySet()) {
6772 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6773 final String subscriberId = (String) prefs.get(key);
6774 if (activeSubscriberIds.contains(subscriberId)) {
6775 final String iccId = key.substring(
6776 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6777 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6778 mergeNumber = (String) prefs.get(numberKey);
6779 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006780 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 + " for active subscriber " + subscriberId);
6782 }
6783 if (!TextUtils.isEmpty(mergeNumber)) {
6784 break;
6785 }
6786 }
6787 }
6788 }
6789
6790 // Shortcut when no active merged subscribers
6791 if (TextUtils.isEmpty(mergeNumber)) {
6792 return null;
6793 }
6794
6795 // Second pass, find all subscribers under that line override
6796 final ArraySet<String> result = new ArraySet<>();
6797 for (String key : prefs.keySet()) {
6798 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6799 final String number = (String) prefs.get(key);
6800 if (mergeNumber.equals(number)) {
6801 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6802 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6803 final String subscriberId = (String) prefs.get(subscriberKey);
6804 if (!TextUtils.isEmpty(subscriberId)) {
6805 result.add(subscriberId);
6806 }
6807 }
6808 }
6809 }
6810
6811 final String[] resultArray = result.toArray(new String[result.size()]);
6812 Arrays.sort(resultArray);
6813 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006814 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6816 }
6817 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006818 } finally {
6819 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006820 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006821 }
6822
6823 @Override
zoey chen38003472019-12-13 17:16:31 +08006824 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6825 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006826
6827 final long identity = Binder.clearCallingIdentity();
6828 try {
6829 final TelephonyManager telephonyManager = mApp.getSystemService(
6830 TelephonyManager.class);
6831 String subscriberId = telephonyManager.getSubscriberId(subId);
6832 if (subscriberId == null) {
6833 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006834 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006835 + subId);
6836 }
6837 return null;
6838 }
6839
6840 final SubscriptionInfo info = SubscriptionController.getInstance()
6841 .getSubscriptionInfo(subId);
6842 final ParcelUuid groupUuid = info.getGroupUuid();
6843 // If it doesn't belong to any group, return just subscriberId of itself.
6844 if (groupUuid == null) {
6845 return new String[]{subscriberId};
6846 }
6847
6848 // Get all subscriberIds from the group.
6849 final List<String> mergedSubscriberIds = new ArrayList<>();
6850 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006851 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006852 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006853 for (SubscriptionInfo subInfo : groupInfos) {
6854 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6855 if (subscriberId != null) {
6856 mergedSubscriberIds.add(subscriberId);
6857 }
6858 }
6859
6860 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863
6864 }
6865 }
6866
6867 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006868 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006869 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006870 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
6874 final Phone phone = getPhone(subId);
6875 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006879 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006880
6881 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006882 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006883 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6884 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006885 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6886 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 final Phone phone = getPhone(subId);
6891 if (phone == null) {
6892 return false;
6893 }
6894 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6895 cdmaNonRoamingList);
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006898 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006899 }
6900
6901 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006902 @Deprecated
6903 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6904 enforceModifyPermission();
6905
6906 int returnValue = 0;
6907 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006908 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006909 if(result.exception == null) {
6910 if (result.result != null) {
6911 byte[] responseData = (byte[])(result.result);
6912 if(responseData.length > oemResp.length) {
6913 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6914 responseData.length + "bytes. Buffer Size is " +
6915 oemResp.length + "bytes.");
6916 }
6917 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6918 returnValue = responseData.length;
6919 }
6920 } else {
6921 CommandException ex = (CommandException) result.exception;
6922 returnValue = ex.getCommandError().ordinal();
6923 if(returnValue > 0) returnValue *= -1;
6924 }
6925 } catch (RuntimeException e) {
6926 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6927 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6928 if(returnValue > 0) returnValue *= -1;
6929 }
6930
6931 return returnValue;
6932 }
6933
6934 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006935 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006936 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006937 try {
6938 TelephonyPermissions
6939 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6940 mApp, phone.getSubId(), "getRadioAccessFamily");
6941 } catch (SecurityException e) {
6942 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6943 throw e;
6944 }
chen xub97461a2018-10-26 14:17:57 -07006945 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006946 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006947 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 final long identity = Binder.clearCallingIdentity();
6950 try {
chen xub97461a2018-10-26 14:17:57 -07006951 TelephonyPermissions
6952 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6953 mApp, phone.getSubId(), "getRadioAccessFamily");
6954 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
chen xub97461a2018-10-26 14:17:57 -07006958 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006959 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006960
6961 @Override
6962 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006963 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965
6966 final long identity = Binder.clearCallingIdentity();
6967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006968 ImsManager.getInstance(defaultPhone.getContext(),
6969 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 } finally {
6971 Binder.restoreCallingIdentity(identity);
6972 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006973 }
6974
6975 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006976 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006977 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6979 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006980 return false;
6981 }
Svet Ganovb320e182015-04-16 12:30:10 -07006982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 // Check the user preference and the system-level IMS setting. Even if the user has
6986 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6987 // In the long run, we may instead need to check if there exists a connection service
6988 // which can support video calling.
6989 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 return imsManager.isVtEnabledByPlatform()
6992 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6993 && imsManager.isVtEnabledByUser();
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
6996 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006997 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006998
Andrew Leea1239f22015-03-02 17:44:07 -08006999 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007000 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7001 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007003 mApp, subId, callingPackage, callingFeatureId,
7004 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 return false;
7006 }
7007
7008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 CarrierConfigManager configManager =
7011 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007012 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
Andrew Leea1239f22015-03-02 17:44:07 -08007017 }
7018
7019 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007020 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007022 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 return false;
7024 }
7025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 CarrierConfigManager configManager =
7029 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
Andrew Leea1239f22015-03-02 17:44:07 -08007035 }
7036
Andrew Lee9431b832015-03-09 18:46:45 -07007037 @Override
7038 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007039 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007040 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007041 }
7042
7043 @Override
7044 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 final long identity = Binder.clearCallingIdentity();
7046 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 } finally {
7049 Binder.restoreCallingIdentity(identity);
7050 }
Andrew Lee9431b832015-03-09 18:46:45 -07007051 }
7052
Hall Liuf6668912018-10-31 17:05:23 -07007053 /**
7054 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7055 * support for the feature and device firmware support.
7056 *
7057 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7058 */
7059 @Override
7060 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007062 final Phone phone = getPhone(subscriptionId);
7063 if (phone == null) {
7064 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7065 return false;
7066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007068 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7070 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007071 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 return isCarrierSupported && isDeviceSupported;
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
Hall Liu98187582018-01-22 19:15:32 -08007076 }
7077
Hall Liuf6668912018-10-31 17:05:23 -07007078 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007079 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7080 * RTT setting, will return true if the device and carrier both support RTT.
7081 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007082 */
7083 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 final long identity = Binder.clearCallingIdentity();
7085 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007086 boolean isRttSupported = isRttSupported(subscriptionId);
7087 boolean isUserRttSettingOn = Settings.Secure.getInt(
7088 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7089 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7090 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7091 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 } finally {
7093 Binder.restoreCallingIdentity(identity);
7094 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007095 }
7096
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007097 @Deprecated
7098 @Override
7099 public String getDeviceId(String callingPackage) {
7100 return getDeviceIdWithFeature(callingPackage, null);
7101 }
7102
Sanket Padawe7310cc72015-01-14 09:53:20 -08007103 /**
7104 * Returns the unique device ID of phone, for example, the IMEI for
7105 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7106 *
7107 * <p>Requires Permission:
7108 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7109 */
7110 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007111 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007112 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007113 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007114 return null;
7115 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007116 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007117 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007118 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007119 return null;
7120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 return phone.getDeviceId();
7125 } finally {
7126 Binder.restoreCallingIdentity(identity);
7127 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007128 }
7129
Ping Sunc67b7c22016-03-02 19:16:45 +08007130 /**
7131 * {@hide}
7132 * Returns the IMS Registration Status on a particular subid
7133 *
7134 * @param subId
7135 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007136 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007137 Phone phone = getPhone(subId);
7138 if (phone != null) {
7139 return phone.isImsRegistered();
7140 } else {
7141 return false;
7142 }
7143 }
7144
Santos Cordon7a1885b2015-02-03 11:15:19 -08007145 @Override
7146 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
7152 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007153 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007154
Tyler Gunnf70ed162019-04-03 15:28:53 -07007155 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007156 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007157 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007159 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007160 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7161 }
7162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
7170 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007171 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007172 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7173 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 Phone phone = getPhone(subscriptionId);
7177 if (phone == null) {
7178 return null;
7179 }
7180 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
7184 }
7185
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007186 /**
7187 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007188 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007189 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 Phone phone = getPhone(subId);
7193 if (phone != null) {
7194 return phone.isWifiCallingEnabled();
7195 } else {
7196 return false;
7197 }
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007200 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007201 }
7202
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007203 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007204 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007205 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007206 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 final long identity = Binder.clearCallingIdentity();
7208 try {
7209 Phone phone = getPhone(subId);
7210 if (phone != null) {
7211 return phone.isVideoEnabled();
7212 } else {
7213 return false;
7214 }
7215 } finally {
7216 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007217 }
7218 }
7219
7220 /**
7221 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7222 * defined in {@link ImsRegistrationImplBase}.
7223 */
7224 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 Phone phone = getPhone(subId);
7228 if (phone != null) {
7229 return phone.getImsRegistrationTech();
7230 } else {
7231 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7232 }
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007235 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007236 }
7237
Stuart Scott8eef64f2015-04-08 15:13:54 -07007238 @Override
7239 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007240 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007241 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7242 return;
7243 }
7244
Svet Ganovcc087f82015-05-12 20:35:54 -07007245 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007246
Svet Ganovcc087f82015-05-12 20:35:54 -07007247 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007248 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7249 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007250 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007251 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007252 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007253 Phone phone = getPhone(subId);
7254 if (phone != null) {
7255 SubscriptionManager.setSubscriptionProperty(subId,
7256 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7257 "user=" + RadioAccessFamily.getRafFromNetworkType(
7258 RILConstants.PREFERRED_NETWORK_MODE));
7259 phone.loadAllowedNetworksFromSubscriptionDatabase();
7260 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007261 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7262 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007263 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007264 // There has been issues when Sms raw table somehow stores orphan
7265 // fragments. They lead to garbled message when new fragments come
7266 // in and combined with those stale ones. In case this happens again,
7267 // user can reset all network settings which will clean up this table.
7268 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007269 // Clean up IMS settings as well here.
7270 int slotId = getSlotIndex(subId);
7271 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7272 ImsManager.getInstance(mApp, slotId).factoryReset();
7273 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007274
7275 // Erase modem config if erase modem on network setting is enabled.
7276 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7277 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7278 if (configValue != null && Boolean.parseBoolean(configValue)) {
7279 sendEraseModemConfig(getDefaultPhone());
7280 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007281 } finally {
7282 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007283 }
7284 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007285
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007286 private void cleanUpSmsRawTable(Context context) {
7287 ContentResolver resolver = context.getContentResolver();
7288 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7289 resolver.delete(uri, null, null);
7290 }
7291
Narayan Kamath1c496c22015-04-16 14:40:19 +01007292 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007293 public String getSimLocaleForSubscriber(int subId) {
7294 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7295 final Phone phone = getPhone(subId);
7296 if (phone == null) {
7297 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007298 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300 final long identity = Binder.clearCallingIdentity();
7301 try {
chen xu5d3637b2019-01-21 23:31:38 -08007302 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007303 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007304 if (info == null) {
7305 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7306 return null;
7307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 // Try and fetch the locale from the carrier properties or from the SIM language
7309 // preferences (EF-PL and EF-LI)...
7310 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007312 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7313 if (localeFromDefaultSim != null) {
7314 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7315 if (DBG) log("Using locale from subId: " + subId + " locale: "
7316 + localeFromDefaultSim);
7317 return localeFromDefaultSim.toLanguageTag();
7318 } else {
7319 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 }
7321 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 // The SIM language preferences only store a language (e.g. fr = French), not an
7324 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7325 // the SIM and carrier preferences does not include a country we add the country
7326 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007327 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007329 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 return mccLocale.toLanguageTag();
7331 }
7332
7333 if (DBG) log("No locale found - returning null");
7334 return null;
7335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007338 }
7339
7340 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007341 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007342 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007343 }
7344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 /**
7346 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7347 */
7348 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007349 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007350 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007351 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007352
Chenjie Yu1ba97252018-01-11 18:16:20 -08007353 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007354 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007355
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007356 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007357 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7358 * representing the state of the modem.
7359 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007360 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7361 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007362 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007363 */
7364 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007365 public void requestModemActivityInfo(ResultReceiver result) {
7366 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368
7369 final long identity = Binder.clearCallingIdentity();
7370 try {
sqian1a1be542020-03-05 11:37:28 -08007371 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 } finally {
7373 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007374 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007375 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007376
Siddharth Rayb8114062018-06-17 15:02:38 -07007377 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7378 // less than total activity duration.
7379 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7380 if (info == null) {
7381 return false;
7382 }
7383 int activityDurationMs =
7384 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7385 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007386 int[] txTimeMs = info.getTransmitTimeMillis();
7387 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7388 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007389 }
7390 return (info.isValid()
7391 && (info.getSleepTimeMillis() <= activityDurationMs)
7392 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007393 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007394 && (totalTxTimeMs <= activityDurationMs));
7395 }
7396
Jack Yu85bd38a2015-11-09 11:34:32 -08007397 /**
7398 * {@hide}
7399 * Returns the service state information on specified subscription.
7400 */
7401 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007402 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7403 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007405 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007406 return null;
7407 }
7408
Hall Liuf19c44f2018-11-27 14:38:17 -08007409 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7410 LocationAccessPolicy.checkLocationPermission(mApp,
7411 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7412 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007413 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007414 .setCallingPid(Binder.getCallingPid())
7415 .setCallingUid(Binder.getCallingUid())
7416 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007417 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7419 .build());
7420
7421 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7422 LocationAccessPolicy.checkLocationPermission(mApp,
7423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7424 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007425 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007426 .setCallingPid(Binder.getCallingPid())
7427 .setCallingUid(Binder.getCallingUid())
7428 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007429 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007430 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7431 .build());
7432 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7433 boolean hasFinePermission =
7434 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7435 boolean hasCoarsePermission =
7436 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007440 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7441 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7442 Rlog.d(LOG_TAG,
7443 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7444 return null;
7445 }
7446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 final Phone phone = getPhone(subId);
7448 if (phone == null) {
7449 return null;
7450 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007451
Hall Liuf19c44f2018-11-27 14:38:17 -08007452 ServiceState ss = phone.getServiceState();
7453
7454 // Scrub out the location info in ServiceState depending on what level of access
7455 // the caller has.
7456 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007457 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7458 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007462 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007463
7464 /**
7465 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7466 *
7467 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7468 * voicemail ringtone.
7469 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7470 * PhoneAccount.
7471 */
7472 @Override
7473 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7477 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
7484 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007485 }
7486
7487 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007488 * Sets the per-account voicemail ringtone.
7489 *
7490 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7491 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7492 *
7493 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7494 * voicemail ringtone.
7495 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7496 * PhoneAccount.
7497 */
7498 @Override
7499 public void setVoicemailRingtoneUri(String callingPackage,
7500 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007501 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007503 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7504 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7506 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7507 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7513 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007514 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 }
7516 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007519 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007520 }
7521
7522 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007523 * Returns whether vibration is set for voicemail notification in Phone settings.
7524 *
7525 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7526 * voicemail vibration setting.
7527 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7528 */
7529 @Override
7530 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7534 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007542 }
7543
Youhan Wange64578a2016-05-02 15:32:42 -07007544 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007545 * Sets the per-account voicemail vibration.
7546 *
7547 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7548 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7549 *
7550 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7551 * voicemail vibration setting.
7552 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7553 * specific PhoneAccount.
7554 */
7555 @Override
7556 public void setVoicemailVibrationEnabled(String callingPackage,
7557 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007560 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7561 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7563 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7564 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007565 }
7566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7570 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007571 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 }
7573 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007576 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007577 }
7578
7579 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007580 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7581 *
7582 * @throws SecurityException if the caller does not have the required permission
7583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007584 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007585 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007586 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007587 }
7588
7589 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007590 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7591 * permission.
7592 *
7593 * @throws SecurityException if the caller does not have the required permission
7594 */
7595 private void enforceSendSmsPermission() {
7596 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7597 }
7598
7599 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007600 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007601 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007602 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007603 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007604 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007608 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 if (componentName == null) {
7610 throw new SecurityException(
7611 "Caller not current active visual voicemail package[null]");
7612 }
7613 String vvmPackage = componentName.getPackageName();
7614 if (!callingPackage.equals(vvmPackage)) {
7615 throw new SecurityException("Caller not current active visual voicemail package["
7616 + vvmPackage + "]");
7617 }
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007620 }
7621 }
7622
7623 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007624 * Return the application ID for the app type.
7625 *
7626 * @param subId the subscription ID that this request applies to.
7627 * @param appType the uicc app type.
7628 * @return Application ID for specificied app type, or null if no uicc.
7629 */
7630 @Override
7631 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007632 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007633 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634
7635 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007636 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 if (phone == null) {
7638 return null;
7639 }
7640 String aid = null;
7641 try {
7642 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7643 .getApplicationByType(appType).getAid();
7644 } catch (Exception e) {
7645 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7646 }
7647 return aid;
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007650 }
Youhan Wange64578a2016-05-02 15:32:42 -07007651 }
7652
Youhan Wang4001d252016-05-11 10:29:41 -07007653 /**
7654 * Return the Electronic Serial Number.
7655 *
7656 * @param subId the subscription ID that this request applies to.
7657 * @return ESN or null if error.
7658 */
7659 @Override
7660 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007661 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007662 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663
7664 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007665 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 if (phone == null) {
7667 return null;
7668 }
7669 String esn = null;
7670 try {
7671 esn = phone.getEsn();
7672 } catch (Exception e) {
7673 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7674 }
7675 return esn;
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007678 }
Youhan Wang4001d252016-05-11 10:29:41 -07007679 }
7680
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007681 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007682 * Return the Preferred Roaming List Version.
7683 *
7684 * @param subId the subscription ID that this request applies to.
7685 * @return PRLVersion or null if error.
7686 */
7687 @Override
7688 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007689 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007690 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691
7692 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007693 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 if (phone == null) {
7695 return null;
7696 }
7697 String cdmaPrlVersion = null;
7698 try {
7699 cdmaPrlVersion = phone.getCdmaPrlVersion();
7700 } catch (Exception e) {
7701 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7702 }
7703 return cdmaPrlVersion;
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007706 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007707 }
7708
7709 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007710 * Get snapshot of Telephony histograms
7711 * @return List of Telephony histograms
7712 * @hide
7713 */
7714 @Override
7715 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7717 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718
7719 final long identity = Binder.clearCallingIdentity();
7720 try {
7721 return RIL.getTelephonyRILTimingHistograms();
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007725 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007726
7727 /**
7728 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007729 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7730 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007731 * Require system privileges. In the future we may add this to carrier APIs.
7732 *
Michele Berionne482f8202018-11-27 18:57:59 -08007733 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007734 */
7735 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007736 @TelephonyManager.SetCarrierRestrictionResult
7737 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007739 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007740
Michele Berionne482f8202018-11-27 18:57:59 -08007741 if (carrierRestrictionRules == null) {
7742 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007743 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007747 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007748 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 } finally {
7750 Binder.restoreCallingIdentity(identity);
7751 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007752 }
7753
7754 /**
7755 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007756 * Get the allowed carrier list and the excluded carrier list, including the priority between
7757 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007758 * Require system privileges. In the future we may add this to carrier APIs.
7759 *
Michele Berionne482f8202018-11-27 18:57:59 -08007760 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007761 */
7762 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007763 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007764 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766
7767 final long identity = Binder.clearCallingIdentity();
7768 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007769 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7770 if (response instanceof CarrierRestrictionRules) {
7771 return (CarrierRestrictionRules) response;
7772 }
7773 // Response is an Exception of some kind,
7774 // which is signalled to the user as a NULL retval
7775 return null;
7776 } catch (Exception e) {
7777 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7778 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007782 }
7783
fionaxu59545b42016-05-25 15:53:37 -07007784 /**
fionaxu59545b42016-05-25 15:53:37 -07007785 * Action set from carrier signalling broadcast receivers to enable/disable radio
7786 * @param subId the subscription ID that this action applies to.
7787 * @param enabled control enable or disable radio.
7788 * {@hide}
7789 */
7790 @Override
7791 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7792 enforceModifyPermission();
7793 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794
7795 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007796 if (phone == null) {
7797 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7798 return;
7799 }
7800 try {
7801 phone.carrierActionSetRadioEnabled(enabled);
7802 } catch (Exception e) {
7803 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 } finally {
7805 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007806 }
7807 }
7808
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007809 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007810 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7811 * network status based on which carrier apps could apply actions accordingly,
7812 * enable/disable default url handler for example.
7813 *
7814 * @param subId the subscription ID that this action applies to.
7815 * @param report control start/stop reporting the default network status.
7816 * {@hide}
7817 */
7818 @Override
7819 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7820 enforceModifyPermission();
7821 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822
7823 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007824 if (phone == null) {
7825 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7826 return;
7827 }
7828 try {
7829 phone.carrierActionReportDefaultNetworkStatus(report);
7830 } catch (Exception e) {
7831 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 } finally {
7833 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007834 }
7835 }
7836
7837 /**
fionaxud9622282017-07-17 17:51:30 -07007838 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7839 * @param subId the subscription ID that this action applies to.
7840 * {@hide}
7841 */
7842 @Override
7843 public void carrierActionResetAll(int subId) {
7844 enforceModifyPermission();
7845 final Phone phone = getPhone(subId);
7846 if (phone == null) {
7847 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7848 return;
7849 }
7850 try {
7851 phone.carrierActionResetAll();
7852 } catch (Exception e) {
7853 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7854 }
7855 }
7856
7857 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007858 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7859 * bug report is being generated.
7860 */
7861 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007862 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007863 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7864 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007865 writer.println("Permission Denial: can't dump Phone from pid="
7866 + Binder.getCallingPid()
7867 + ", uid=" + Binder.getCallingUid()
7868 + "without permission "
7869 + android.Manifest.permission.DUMP);
7870 return;
7871 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007872 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007873 }
Jack Yueb89b242016-06-22 13:27:47 -07007874
Brad Ebingerdac2f002018-04-03 15:17:52 -07007875 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007876 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7877 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7878 @NonNull String[] args) {
7879 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7880 this, in.getFileDescriptor(), out.getFileDescriptor(),
7881 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007882 }
7883
Jack Yueb89b242016-06-22 13:27:47 -07007884 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007885 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007886 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007887 * @param reason the reason the data enable change is taking place
7888 * @param enabled True if enabling the data, otherwise disabling.
7889 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007890 */
7891 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007892 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007893 boolean enabled) {
7894 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7895 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7896 try {
7897 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007898 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007899 } catch (SecurityException se) {
7900 enforceModifyPermission();
7901 }
7902 } else {
7903 enforceModifyPermission();
7904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905
7906 final long identity = Binder.clearCallingIdentity();
7907 try {
7908 Phone phone = getPhone(subId);
7909 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007910 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7911 phone.carrierActionSetMeteredApnsEnabled(enabled);
7912 } else {
7913 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 }
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007918 }
7919 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007920
7921 /**
7922 * Get Client request stats
7923 * @return List of Client Request Stats
7924 * @hide
7925 */
7926 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007927 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7928 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007930 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007931 return null;
7932 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007933 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 if (phone != null) {
7938 return phone.getClientRequestStats();
7939 }
7940
7941 return null;
7942 } finally {
7943 Binder.restoreCallingIdentity(identity);
7944 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007945 }
7946
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007947 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007948 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007949 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007950 }
Jack Yueb4124c2017-02-16 15:32:43 -08007951
7952 /**
Grace Chen70990072017-03-24 17:21:30 -07007953 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007954 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007955 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007956 * @param state State of SIM (power down, power up, pass through)
7957 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7958 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7959 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007960 *
7961 **/
7962 @Override
Grace Chen70990072017-03-24 17:21:30 -07007963 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007964 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007965 Phone phone = PhoneFactory.getPhone(slotIndex);
7966
vagdeviaf9a5b92018-08-15 16:01:53 -07007967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 final long identity = Binder.clearCallingIdentity();
7970 try {
7971 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007972 phone.setSimPowerState(state, null, workSource);
7973 }
7974 } finally {
7975 Binder.restoreCallingIdentity(identity);
7976 }
7977 }
7978
7979 /**
7980 * Set SIM card power state.
7981 *
7982 * @param slotIndex SIM slot id.
7983 * @param state State of SIM (power down, power up, pass through)
7984 * @param callback callback to trigger after success or failure
7985 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7986 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7987 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7988 *
7989 **/
7990 @Override
7991 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7992 IIntegerConsumer callback) {
7993 enforceModifyPermission();
7994 Phone phone = PhoneFactory.getPhone(slotIndex);
7995
7996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 if (phone != null) {
8001 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8002 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 }
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008006 }
8007 }
Shuo Qiandd210312017-04-12 22:11:33 +00008008
Tyler Gunn65d45c22017-06-05 11:22:26 -07008009 private boolean isUssdApiAllowed(int subId) {
8010 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008011 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008012 if (configManager == null) {
8013 return false;
8014 }
8015 PersistableBundle pb = configManager.getConfigForSubId(subId);
8016 if (pb == null) {
8017 return false;
8018 }
8019 return pb.getBoolean(
8020 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8021 }
8022
Shuo Qiandd210312017-04-12 22:11:33 +00008023 /**
8024 * Check if phone is in emergency callback mode
8025 * @return true if phone is in emergency callback mode
8026 * @param subId sub id
8027 */
goneil9c5f4872017-12-05 14:07:56 -08008028 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008029 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008030 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008031 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032
8033 final long identity = Binder.clearCallingIdentity();
8034 try {
8035 if (phone != null) {
8036 return phone.isInEcm();
8037 } else {
8038 return false;
8039 }
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008042 }
8043 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008044
8045 /**
8046 * Get the current signal strength information for the given subscription.
8047 * Because this information is not updated when the device is in a low power state
8048 * it should not be relied-upon to be current.
8049 * @param subId Subscription index
8050 * @return the most recent cached signal strength info from the modem
8051 */
8052 @Override
8053 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 Phone p = getPhone(subId);
8057 if (p == null) {
8058 return null;
8059 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 return p.getSignalStrength();
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
8064 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008066
Pengquan Meng77b7f132018-08-22 14:49:57 -07008067 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008068 * Get the current modem radio state for the given slot.
8069 * @param slotIndex slot index.
8070 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008071 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008072 * @return the current radio power state from the modem
8073 */
8074 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008075 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008076 Phone phone = PhoneFactory.getPhone(slotIndex);
8077 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8079 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008080 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8081 }
8082
8083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 return phone.getRadioPowerState();
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
8089 }
8090 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8091 }
8092
8093 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008094 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8095 *
8096 * <p>Requires one of the following permissions:
8097 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8098 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8099 * privileges.
8100 *
8101 * @param subId subscription id
8102 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8103 * {@code false}.
8104 */
8105 @Override
8106 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008107 try {
8108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8109 null);
8110 } catch (Exception e) {
8111 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8112 mApp, subId, "isDataRoamingEnabled");
8113 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008114
Pengquan Menga1bb6272018-09-06 09:59:22 -07008115 boolean isEnabled = false;
8116 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008117 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008118 Phone phone = getPhone(subId);
8119 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008120 } finally {
8121 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008122 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008123 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008124 }
8125
8126
8127 /**
8128 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8129 *
8130 * <p> Requires permission:
8131 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8132 * privileges.
8133 *
8134 * @param subId subscription id
8135 * @param isEnabled {@code true} means enable, {@code false} means disable.
8136 */
8137 @Override
8138 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8140 mApp, subId, "setDataRoamingEnabled");
8141
Pengquan Menga1bb6272018-09-06 09:59:22 -07008142 final long identity = Binder.clearCallingIdentity();
8143 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008144 Phone phone = getPhone(subId);
8145 if (phone != null) {
8146 phone.setDataRoamingEnabled(isEnabled);
8147 }
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008150 }
8151 }
8152
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008153 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008154 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008155 TelephonyPermissions
8156 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008157 mApp, subId, "isManualNetworkSelectionAllowed");
8158
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008159 boolean isAllowed = true;
8160 final long identity = Binder.clearCallingIdentity();
8161 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008162 Phone phone = getPhone(subId);
8163 if (phone != null) {
8164 isAllowed = phone.isCspPlmnEnabled();
8165 }
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
8169 return isAllowed;
8170 }
8171
8172 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008173 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008174 // Verify that tha callingPackage belongs to the calling UID
8175 mApp.getSystemService(AppOpsManager.class)
8176 .checkPackage(Binder.getCallingUid(), callingPackage);
8177
Jordan Liu1e142fc2019-04-22 15:10:43 -07008178 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008179 try {
8180 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008181 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008182 } catch (SecurityException e) {
8183 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8184 // has carrier privileges on an active UICC
8185 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8186 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008187 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008188 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008189 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008190
8191 final long identity = Binder.clearCallingIdentity();
8192 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008193 UiccController uiccController = UiccController.getInstance();
8194 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008195 if (hasReadPermission) {
8196 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008197 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008198
8199 // Remove private info if the caller doesn't have access
8200 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8201 for (UiccCardInfo cardInfo : cardInfos) {
8202 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8203 // is available
8204 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8205 if (card == null || card.getUiccProfile() == null) {
8206 // assume no access if the card or profile is unavailable
8207 filteredInfos.add(cardInfo.getUnprivileged());
8208 continue;
8209 }
8210 UiccProfile profile = card.getUiccProfile();
8211 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8212 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8213 filteredInfos.add(cardInfo);
8214 } else {
8215 filteredInfos.add(cardInfo.getUnprivileged());
8216 }
8217 }
8218 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
8222 }
8223
8224 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008225 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008226 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 final long identity = Binder.clearCallingIdentity();
8229 try {
8230 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8231 if (slots == null) {
8232 Rlog.i(LOG_TAG, "slots is null.");
8233 return null;
8234 }
8235
8236 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8237 for (int i = 0; i < slots.length; i++) {
8238 UiccSlot slot = slots[i];
8239 if (slot == null) {
8240 continue;
8241 }
8242
Jordan Liu7be7e652019-05-06 18:55:02 +00008243 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 UiccCard card = slot.getUiccCard();
8245 if (card != null) {
8246 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008247 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008248 cardId = slot.getEid();
8249 if (TextUtils.isEmpty(cardId)) {
8250 cardId = slot.getIccId();
8251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 }
8253
Jordan Liu857451f2019-05-09 16:35:35 -07008254 if (cardId != null) {
8255 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8256 // if cardId is an EID, it's all digits so this is fine
8257 cardId = IccUtils.stripTrailingFs(cardId);
8258 }
8259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 int cardState = 0;
8261 switch (slot.getCardState()) {
8262 case CARDSTATE_ABSENT:
8263 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8264 break;
8265 case CARDSTATE_PRESENT:
8266 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8267 break;
8268 case CARDSTATE_ERROR:
8269 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8270 break;
8271 case CARDSTATE_RESTRICTED:
8272 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8273 break;
8274 default:
8275 break;
8276
8277 }
8278
8279 infos[i] = new UiccSlotInfo(
8280 slot.isActive(),
8281 slot.isEuicc(),
8282 cardId,
8283 cardState,
8284 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008285 slot.isExtendedApduSupported(),
8286 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 }
8288 return infos;
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008291 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008292 }
8293
8294 @Override
8295 public boolean switchSlots(int[] physicalSlots) {
8296 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008304 }
Jack Yu4c988042018-02-27 15:30:01 -08008305
8306 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008307 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 return UiccController.getInstance().getCardIdForDefaultEuicc();
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
8314 }
8315
Pengquan Meng85728fb2018-03-12 16:31:21 -07008316 /**
goneil47ffb6e2018-04-06 15:40:58 -07008317 * A test API to reload the UICC profile.
8318 *
8319 * <p>Requires that the calling app has permission
8320 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8321 * @hide
8322 */
8323 @Override
8324 public void refreshUiccProfile(int subId) {
8325 enforceModifyPermission();
8326
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 Phone phone = getPhone(subId);
8330 if (phone == null) {
8331 return;
8332 }
8333 UiccCard uiccCard = phone.getUiccCard();
8334 if (uiccCard == null) {
8335 return;
8336 }
8337 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8338 if (uiccProfile == null) {
8339 return;
8340 }
8341 uiccProfile.refresh();
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
8345 }
8346
8347 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008348 * Returns false if the mobile data is disabled by default, otherwise return true.
8349 */
8350 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008351 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008352 }
8353
8354 /**
8355 * Returns true if the data roaming is enabled by default, i.e the system property
8356 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8357 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8358 */
8359 private boolean getDefaultDataRoamingEnabled(int subId) {
8360 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008361 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008362 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008363 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8364 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8365 return isDataRoamingEnabled;
8366 }
8367
8368 /**
8369 * Returns the default network type for the given {@code subId}, if the default network type is
8370 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8371 */
8372 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008373 List<Integer> list = TelephonyProperties.default_network();
8374 int phoneId = mSubscriptionController.getPhoneId(subId);
8375 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8376 return list.get(phoneId);
8377 }
8378 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008379 }
fionaxua13278b2018-03-21 00:08:13 -07008380
8381 @Override
8382 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008383 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008384 enforceModifyPermission();
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("setCarrierTestOverride fails with invalid subId: " + subId);
8391 return;
8392 }
chen xueaba88a2019-03-15 13:15:10 -07008393 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8394 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008395 if (carrierPrivilegeRules == null) {
8396 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8397 } else {
8398 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400 } finally {
8401 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008402 }
fionaxua13278b2018-03-21 00:08:13 -07008403 }
8404
8405 @Override
8406 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008407 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 final Phone phone = getPhone(subId);
8412 if (phone == null) {
8413 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8414 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8415 }
8416 return phone.getCarrierIdListVersion();
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008419 }
fionaxua13278b2018-03-21 00:08:13 -07008420 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008421
8422 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008423 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8424 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008426 mApp, subId, callingPackage, callingFeatureId,
8427 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008428 return -1;
8429 }
8430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008438
8439 @Override
8440 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008441 TelephonyPermissions
8442 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008443 mApp, subId, "getCdmaRoamingMode");
8444
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
8450 }
8451 }
8452
8453 @Override
8454 public boolean setCdmaRoamingMode(int subId, int mode) {
8455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8456 mApp, subId, "setCdmaRoamingMode");
8457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
8464 }
8465
8466 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008467 public int getCdmaSubscriptionMode(int subId) {
8468 TelephonyPermissions
8469 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8470 mApp, subId, "getCdmaSubscriptionMode");
8471
8472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
8477 }
8478 }
8479
8480 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008481 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8483 mApp, subId, "setCdmaSubscriptionMode");
8484
8485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008492
sqianc5eccab2018-10-19 18:46:41 -07008493 @Override
sqian8c685422019-02-22 15:55:18 -08008494 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008495 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008497 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8498 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008499 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8500 }
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
sqian854d44b2018-12-12 16:48:18 -08008503 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8504 for (Phone phone: PhoneFactory.getPhones()) {
8505 if (phone.getEmergencyNumberTracker() != null
8506 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8507 emergencyNumberListInternal.put(
8508 phone.getSubId(),
8509 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8510 }
sqian11b7a0e2018-12-05 18:48:28 -08008511 }
sqian854d44b2018-12-12 16:48:18 -08008512 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
sqianc5eccab2018-10-19 18:46:41 -07008516 }
8517
8518 @Override
sqian8c685422019-02-22 15:55:18 -08008519 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008520 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008521 if (!exactMatch) {
8522 TelephonyPermissions
8523 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008524 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008525 }
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
sqian854d44b2018-12-12 16:48:18 -08008528 for (Phone phone: PhoneFactory.getPhones()) {
8529 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008530 && phone.getEmergencyNumberTracker()
8531 .isEmergencyNumber(number, exactMatch)) {
8532 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008533 }
sqian11b7a0e2018-12-05 18:48:28 -08008534 }
8535 return false;
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
8538 }
8539 }
8540
sqianf4ca7ed2019-01-15 18:32:07 -08008541 /**
8542 * Update emergency number list for test mode.
8543 */
8544 @Override
8545 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8546 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8547 "updateEmergencyNumberListTestMode");
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 for (Phone phone: PhoneFactory.getPhones()) {
8552 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8553 if (tracker != null) {
8554 tracker.executeEmergencyNumberTestModeCommand(action, num);
8555 }
8556 }
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
8562 /**
8563 * Get the full emergency number list for test mode.
8564 */
8565 @Override
8566 public List<String> getEmergencyNumberListTestMode() {
8567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8568 "getEmergencyNumberListTestMode");
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 Set<String> emergencyNumbers = new HashSet<>();
8573 for (Phone phone: PhoneFactory.getPhones()) {
8574 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8575 if (tracker != null) {
8576 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8577 emergencyNumbers.add(num.getNumber());
8578 }
8579 }
8580 }
8581 return new ArrayList<>(emergencyNumbers);
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
8584 }
8585 }
8586
chen xud6b45bd2018-10-30 22:27:10 -07008587 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008588 public int getEmergencyNumberDbVersion(int subId) {
8589 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 final Phone phone = getPhone(subId);
8594 if (phone == null) {
8595 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8596 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8597 }
8598 return phone.getEmergencyNumberDbVersion();
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
8603
8604 @Override
8605 public void notifyOtaEmergencyNumberDbInstalled() {
8606 enforceModifyPermission();
8607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 for (Phone phone: PhoneFactory.getPhones()) {
8611 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8612 if (tracker != null) {
8613 tracker.updateOtaEmergencyNumberDatabase();
8614 }
8615 }
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
8618 }
8619 }
8620
8621 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008622 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008623 enforceActiveEmergencySessionPermission();
8624
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 for (Phone phone: PhoneFactory.getPhones()) {
8628 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8629 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008630 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8631 }
8632 }
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
8636 }
8637
8638 @Override
8639 public void resetOtaEmergencyNumberDbFilePath() {
8640 enforceActiveEmergencySessionPermission();
8641
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 for (Phone phone: PhoneFactory.getPhones()) {
8645 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8646 if (tracker != null) {
8647 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008648 }
8649 }
8650 } finally {
8651 Binder.restoreCallingIdentity(identity);
8652 }
8653 }
8654
8655 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008656 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8657 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8658 Phone phone = getPhone(subId);
8659 if (phone == null) {
8660 return null;
8661 }
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 UiccProfile profile = UiccController.getInstance()
8665 .getUiccProfileForPhone(phone.getPhoneId());
8666 if (profile != null) {
8667 return profile.getCertsFromCarrierPrivilegeAccessRules();
8668 }
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
8671 }
8672 return null;
8673 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008674
8675 /**
8676 * Enable or disable a modem stack.
8677 */
8678 @Override
8679 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8680 enforceModifyPermission();
8681
8682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 Phone phone = PhoneFactory.getPhone(slotIndex);
8685 if (phone == null) {
8686 return false;
8687 } else {
8688 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8689 }
8690 } finally {
8691 Binder.restoreCallingIdentity(identity);
8692 }
8693 }
Michelecea4cf22018-12-21 15:00:11 -08008694
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008695 /**
8696 * Whether a modem stack is enabled or not.
8697 */
8698 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008699 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8700 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008701 Phone phone = PhoneFactory.getPhone(slotIndex);
8702 if (phone == null) return false;
8703
8704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008705 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8706 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008707 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8708 }
8709
8710 final long identity = Binder.clearCallingIdentity();
8711 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008712 try {
8713 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8714 } catch (NoSuchElementException ex) {
8715 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8716 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
Michelecea4cf22018-12-21 15:00:11 -08008722 @Override
Michele0ea7d782019-03-19 14:58:42 -07008723 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008724 enforceModifyPermission();
8725
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
8728 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008729 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008730 .commit();
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
8736 @Override
Michele0ea7d782019-03-19 14:58:42 -07008737 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008738 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008740 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8741 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008742 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008743 }
Michelecea4cf22018-12-21 15:00:11 -08008744
8745 final long identity = Binder.clearCallingIdentity();
8746 try {
Michele0ea7d782019-03-19 14:58:42 -07008747 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008748 } finally {
8749 Binder.restoreCallingIdentity(identity);
8750 }
8751 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008752
Michele0ea7d782019-03-19 14:58:42 -07008753 @TelephonyManager.IsMultiSimSupportedResult
8754 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008755 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8756 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8757 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008758 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8759 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008760 }
8761 // Check if the hardware supports multisim functionality. If usage of multisim is not
8762 // supported by the modem, indicate that it is restricted.
8763 PhoneCapability staticCapability =
8764 mPhoneConfigurationManager.getStaticPhoneCapability();
8765 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008766 loge("isMultiSimSupportedInternal: no static configuration available");
8767 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008768 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008769 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008770 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8771 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008772 }
8773 // Check if support of multiple SIMs is restricted by carrier
8774 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008775 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008776 }
8777
Michele0ea7d782019-03-19 14:58:42 -07008778 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008779 }
8780
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008781 /**
8782 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008783 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8784 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8785 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008786 * @param numOfSims number of active sims we want to switch to
8787 */
8788 @Override
8789 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008790 if (numOfSims == 1) {
8791 enforceModifyPermission();
8792 } else {
8793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8794 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8795 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008796 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008797
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008798 try {
Michele30b57b22019-03-01 12:01:14 -08008799 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008800 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008801 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8802 return;
8803 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008804 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8805 } finally {
8806 Binder.restoreCallingIdentity(identity);
8807 }
8808 }
8809
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008810 @Override
8811 public boolean isApplicationOnUicc(int subId, int appType) {
8812 enforceReadPrivilegedPermission("isApplicationOnUicc");
8813 Phone phone = getPhone(subId);
8814 if (phone == null) {
8815 return false;
8816 }
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 UiccCard uiccCard = phone.getUiccCard();
8820 if (uiccCard == null) {
8821 return false;
8822 }
8823 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8824 if (uiccProfile == null) {
8825 return false;
8826 }
8827 if (TelephonyManager.APPTYPE_SIM <= appType
8828 && appType <= TelephonyManager.APPTYPE_ISIM) {
8829 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8830 }
8831 return false;
8832 } finally {
8833 Binder.restoreCallingIdentity(identity);
8834 }
8835 }
8836
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008837 /**
chen xub4baa772019-04-03 10:23:41 -07008838 * Get whether making changes to modem configurations will trigger reboot.
8839 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008840 */
8841 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008842 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8843 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008845 mApp, subId, callingPackage, callingFeatureId,
8846 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008847 return false;
8848 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8852 } finally {
8853 Binder.restoreCallingIdentity(identity);
8854 }
8855 }
8856
Nathan Harold29f5f052019-02-15 13:41:57 -08008857 private void updateModemStateMetrics() {
8858 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8859 // TODO: check the state for each modem if the api is ready.
8860 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8861 }
8862
Pengquan Meng3889a572019-01-23 11:16:29 -08008863 @Override
8864 public int[] getSlotsMapping() {
8865 enforceReadPrivilegedPermission("getSlotsMapping");
8866
8867 final long identity = Binder.clearCallingIdentity();
8868 try {
8869 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8870 // All logical slots should have a mapping to a physical slot.
8871 int[] logicalSlotsMapping = new int[phoneCount];
8872 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8873 for (int i = 0; i < slotInfos.length; i++) {
8874 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8875 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8876 }
8877 }
8878 return logicalSlotsMapping;
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008883
8884 /**
8885 * Get the IRadio HAL Version
8886 */
8887 @Override
8888 public int getRadioHalVersion() {
8889 Phone phone = getDefaultPhone();
8890 if (phone == null) return -1;
8891 HalVersion hv = phone.getHalVersion();
8892 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8893 return hv.major * 100 + hv.minor;
8894 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008895
8896 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008897 * Get the current calling package name.
8898 * @return the current calling package name
8899 */
8900 @Override
8901 public String getCurrentPackageName() {
8902 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8903 }
8904
8905 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008906 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8907 * corresponding network requests on a subId.
8908 *
8909 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008910 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008911 * 2) APN is un-metered for this subscription, or
8912 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008913 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008914 *
8915 * @return whether data is allowed for a apn type.
8916 *
8917 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008918 */
8919 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008920 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008921 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8922 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008923
8924 // Now that all security checks passes, perform the operation as ourselves.
8925 final long identity = Binder.clearCallingIdentity();
8926 try {
8927 Phone phone = getPhone(subId);
8928 if (phone == null) return false;
8929
Jack Yu41407ee2019-05-13 16:54:09 -07008930 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008931 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
8935 }
8936
8937 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008938 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008939 enforceReadPrivilegedPermission("isApnMetered");
8940
8941 // Now that all security checks passes, perform the operation as ourselves.
8942 final long identity = Binder.clearCallingIdentity();
8943 try {
8944 Phone phone = getPhone(subId);
8945 if (phone == null) return true; // By default return true.
8946
Jack Yu41407ee2019-05-13 16:54:09 -07008947 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
8951 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008952
8953 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008954 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8955 int subscriptionId, IBooleanConsumer resultCallback) {
8956 enforceModifyPermission();
8957 long token = Binder.clearCallingIdentity();
8958 try {
8959 Phone phone = getPhone(subscriptionId);
8960 if (phone == null) {
8961 try {
8962 if (resultCallback != null) {
8963 resultCallback.accept(false);
8964 }
8965 } catch (RemoteException e) {
8966 // ignore
8967 }
8968 return;
8969 }
8970 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8971 Pair.create(specifiers, (x) -> {
8972 try {
8973 if (resultCallback != null) {
8974 resultCallback.accept(x);
8975 }
8976 } catch (RemoteException e) {
8977 // ignore
8978 }
8979 });
8980 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8981 } finally {
8982 Binder.restoreCallingIdentity(token);
8983 }
8984 }
8985
8986 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008987 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8988 TelephonyPermissions
8989 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8990 mApp, subId, "getSystemSelectionChannels");
8991 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8992 final long identity = Binder.clearCallingIdentity();
8993 try {
8994 List<RadioAccessSpecifier> specifiers =
8995 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8996 null, subId, workSource);
8997 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8998 return specifiers;
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
9004 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009005 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009006 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009007 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9008 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9009 if (iccRecords == null) {
9010 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9011 return false;
9012 }
9013 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9014 }
9015
9016 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009017 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9018 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009019 if (callingPackage == null) {
9020 callingPackage = getCurrentPackageName();
9021 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009022 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9023 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009024 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9025 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009026 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9027 }
9028 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9029 Intent intent = new Intent();
9030 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9031 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9032 // Bring up choose default SMS subscription dialog right now
9033 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9034 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9035 mApp.startActivity(intent);
9036 }
chen xud5ca2d52019-05-28 15:20:57 -07009037
9038 @Override
9039 public String getMmsUAProfUrl(int subId) {
9040 //TODO investigate if this API should require proper permission check in R b/133791609
9041 final long identity = Binder.clearCallingIdentity();
9042 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009043 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9044 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9045 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9046 return carrierUAProfUrl;
9047 }
chen xud5ca2d52019-05-28 15:20:57 -07009048 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9049 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
9055 @Override
9056 public String getMmsUserAgent(int subId) {
9057 //TODO investigate if this API should require proper permission check in R b/133791609
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009060 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9061 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9062 if (!TextUtils.isEmpty(carrierUserAgent)) {
9063 return carrierUserAgent;
9064 }
chen xud5ca2d52019-05-28 15:20:57 -07009065 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9066 .getString(com.android.internal.R.string.config_mms_user_agent);
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
Jack Yub07d4972019-05-28 16:12:25 -07009071
9072 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009073 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9074 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9075
9076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 Phone phone = getPhone(subscriptionId);
9079 if (phone == null) return false;
9080
9081 switch (policy) {
9082 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9083 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9084 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9085 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9086 default:
9087 throw new IllegalArgumentException(policy + " is not a valid policy");
9088 }
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093
9094 @Override
9095 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9096 boolean enabled) {
9097 enforceModifyPermission();
9098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 Phone phone = getPhone(subscriptionId);
9102 if (phone == null) return;
9103
9104 switch (policy) {
9105 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9106 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9107 break;
9108 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9109 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9110 break;
9111 default:
9112 throw new IllegalArgumentException(policy + " is not a valid policy");
9113 }
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009119 /**
Hall Liub48cf452020-09-25 11:13:49 -07009120 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009121 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9122 * otherwise.
9123 */
9124 @Override
9125 public void setCepEnabled(boolean isCepEnabled) {
9126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9127
9128 final long identity = Binder.clearCallingIdentity();
9129 try {
9130 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9131 for (Phone phone : PhoneFactory.getPhones()) {
9132 Phone defaultPhone = phone.getImsPhone();
9133 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9134 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9135 ImsPhoneCallTracker imsPhoneCallTracker =
9136 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9137 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9138 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9139 + imsPhone.getMsisdn());
9140 }
9141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
allenwtsu46dcc572020-01-08 18:24:03 +08009146
9147 /**
9148 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9149 *
9150 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9151 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9152 * before being read.
9153 */
9154 @Override
9155 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9156 isCompressed) {
9157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9158 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9160 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9161 }
9162 if (!isImsAvailableOnDevice()) {
9163 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9164 "IMS not available on device.");
9165 }
9166
9167 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009168 try {
Hui Wang068ab862020-10-31 05:12:53 +00009169 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009172 }
9173 }
zoey chenf95ca592019-12-30 16:11:23 +08009174
9175 @Override
9176 public boolean isIccLockEnabled(int subId) {
9177 enforceReadPrivilegedPermission("isIccLockEnabled");
9178
9179 // Now that all security checks passes, perform the operation as ourselves.
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 Phone phone = getPhone(subId);
9183 if (phone != null && phone.getIccCard() != null) {
9184 return phone.getIccCard().getIccLockEnabled();
9185 } else {
9186 return false;
9187 }
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
9193 /**
zoey chene02881a2019-12-30 16:11:23 +08009194 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009195 *
zoey chene02881a2019-12-30 16:11:23 +08009196 * @return an integer representing the status of IccLock enabled or disabled in the following
9197 * three cases:
9198 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9199 * successfully.
9200 * - Positive number and zero for remaining password attempts.
9201 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009202 *
9203 */
9204 @Override
9205 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9206 enforceModifyPermission();
9207
9208 Phone phone = getPhone(subId);
9209 if (phone == null) {
9210 return 0;
9211 }
9212 // Now that all security checks passes, perform the operation as ourselves.
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9216 new Pair<Boolean, String>(enabled, password), phone, null);
9217 return attemptsRemaining;
9218
9219 } catch (Exception e) {
9220 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 return 0;
9225 }
9226
9227 /**
9228 * Change the ICC password used in ICC pin lock.
9229 *
zoey chene02881a2019-12-30 16:11:23 +08009230 * @return an integer representing the status of IccLock changed in the following three cases:
9231 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9232 * - Positive number and zero for remaining password attempts.
9233 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009234 *
9235 */
9236 @Override
9237 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9238 enforceModifyPermission();
9239
9240 Phone phone = getPhone(subId);
9241 if (phone == null) {
9242 return 0;
9243 }
9244 // Now that all security checks passes, perform the operation as ourselves.
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9248 new Pair<String, String>(oldPassword, newPassword), phone, null);
9249 return attemptsRemaining;
9250
9251 } catch (Exception e) {
9252 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
9256 return 0;
9257 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009258
Peter Wangdafb9ac2020-01-15 14:13:38 -08009259 /**
9260 * Request for receiving user activity notification
9261 */
9262 @Override
9263 public void requestUserActivityNotification() {
9264 if (!mNotifyUserActivity.get()
9265 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9266 mNotifyUserActivity.set(true);
9267 }
9268 }
9269
9270 /**
9271 * Called when userActivity is signalled in the power manager.
9272 * This is safe to call from any thread, with any window manager locks held or not.
9273 */
9274 @Override
9275 public void userActivity() {
9276 // ***************************************
9277 // * Inherited from PhoneWindowManager *
9278 // ***************************************
9279 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9280 // WITH ITS LOCKS HELD.
9281 //
9282 // This code must be VERY careful about the locks
9283 // it acquires.
9284 // In fact, the current code acquires way too many,
9285 // and probably has lurking deadlocks.
9286
9287 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9288 throw new SecurityException("Only the OS may call notifyUserActivity()");
9289 }
9290
9291 if (mNotifyUserActivity.getAndSet(false)) {
9292 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9293 USER_ACTIVITY_NOTIFICATION_DELAY);
9294 }
9295 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009296
Malcolm Chen884180b2020-04-13 11:59:40 -07009297 @Override
9298 public boolean canConnectTo5GInDsdsMode() {
9299 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9300 }
Jack Yud10cdd42020-09-28 20:28:01 -07009301
9302 @Override
9303 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9304 String callingFeatureId) {
9305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9306 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9307 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9308 }
9309
9310 Phone phone = getPhone(subId);
9311 if (phone == null) {
9312 throw new RuntimeException("phone is not available");
9313 }
9314 // Now that all security checks passes, perform the operation as ourselves.
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 return phone.getEquivalentHomePlmns();
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009322
Hui Wang0866fcc2020-10-12 12:14:23 -07009323 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009324 public boolean isRadioInterfaceCapabilitySupported(
9325 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009326 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009327 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009328 if (radioInterfaceCapabilities == null) {
9329 throw new RuntimeException("radio interface capabilities are not available");
9330 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009331 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009332 }
9333 }
9334
9335 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009336 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9337 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009338 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9339 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9340 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9341 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9342 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009343 if (DBG) {
9344 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9345 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9346 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9347 }
9348
9349 if (!SubscriptionManager.isValidSubscriptionId(subId)
9350 || appType < TelephonyManager.APPTYPE_UNKNOWN
9351 || appType > TelephonyManager.APPTYPE_ISIM
9352 || nafUrl == null || securityProtocol == null || callback == null) {
9353 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9354 if (callback != null) {
9355 try {
9356 callback.onAuthenticationFailure(
9357 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9358 } catch (RemoteException exception) {
9359 log("Fail to notify onAuthenticationFailure due to " + exception);
9360 }
9361 return;
9362 }
9363 }
9364
9365 final long token = Binder.clearCallingIdentity();
9366 try {
9367 getGbaManager(subId).bootstrapAuthenticationRequest(
9368 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9369 forceBootStrapping, callback));
9370 } finally {
9371 Binder.restoreCallingIdentity(token);
9372 }
9373 }
9374
Jack Nudelman24d51a52020-11-24 12:08:04 -08009375 /**
9376 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9377 * requested radio power state will actually be set. See {@link
9378 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9379 *
9380 * @param subId the subscription ID of the phone requesting to set the radio power state.
9381 * @param enable {@code true} if trying to turn radio on.
9382 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9383 * false}.
9384 */
9385 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9386 Phone phone = getPhone(subId);
9387 if (phone != null) {
9388 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9389 return true;
9390 }
9391 return false;
9392 }
9393
9394 private int handleDataThrottlingRequest(int subId,
9395 DataThrottlingRequest dataThrottlingRequest) {
9396 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9397 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9398 if (!setRadioPowerForThermal(subId, true)) {
9399 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9400 }
9401
9402 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9403
9404 int thermalMitigationResult =
9405 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9406 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9407 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9408 }
9409 return thermalMitigationResult;
9410 }
9411
9412 /**
9413 * Thermal mitigation request to control functionalities at modem.
9414 *
9415 * @param subId the id of the subscription.
9416 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9417 *
9418 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9419 */
9420 @Override
9421 @ThermalMitigationResult
9422 public int sendThermalMitigationRequest(
9423 int subId,
9424 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9425 enforceModifyPermission();
9426
9427 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9428 final long identity = Binder.clearCallingIdentity();
9429
9430 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9431 try {
9432 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9433 switch (thermalMitigationAction) {
9434 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9435 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009436 handleDataThrottlingRequest(subId,
9437 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009438 break;
9439 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9440 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9441 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9442 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9443 }
9444
9445 // Ensure that radio is on. If not able to power on due to phone being
9446 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9447 if (!setRadioPowerForThermal(subId, true)) {
9448 thermalMitigationResult =
9449 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9450 break;
9451 }
9452
9453 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9454 false);
9455 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9456 break;
9457 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9458 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9459 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9460 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9461 }
9462
9463 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9464 if (registry != null) {
9465 TelephonyConnectionService service =
9466 registry.getTelephonyConnectionService();
9467 Phone phone = getPhone(subId);
9468 if (phone == null) {
9469 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009470 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009471 break;
9472 }
9473
9474 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009475 != TelephonyManager.CALL_STATE_IDLE
9476 || phone.isInEmergencySmsMode() || phone.isInEcm()
9477 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009478 String errorMessage = "Phone state is not valid. call state = "
9479 + PhoneConstantConversions.convertCallState(phone.getState())
9480 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9481 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9482 errorMessage += service == null
9483 ? " TelephonyConnectionService is null"
9484 : " isEmergencyCallPending = "
9485 + service.isEmergencyCallPending();
9486 Log.e(LOG_TAG, errorMessage);
9487 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009488 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009489 break;
9490 }
9491 } else {
9492 thermalMitigationResult =
9493 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9494 break;
9495 }
9496
9497 // Turn radio off. If not able to power off due to phone being unavailable,
9498 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9499 if (!setRadioPowerForThermal(subId, false)) {
9500 thermalMitigationResult =
9501 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9502 break;
9503 }
9504 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009505 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009506 break;
9507 default:
9508 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9509 + "not exist. Requested action: " + thermalMitigationAction);
9510 }
9511 } catch (IllegalArgumentException e) {
9512 throw e;
9513 } catch (Exception e) {
9514 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9515 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9516 } finally {
9517 Binder.restoreCallingIdentity(identity);
9518 }
9519
9520 if (DBG) {
9521 log("thermalMitigationRequest returning with thermalMitigationResult: "
9522 + thermalMitigationResult);
9523 }
9524
9525 return thermalMitigationResult;
9526 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009527
9528 /**
9529 * Set the GbaService Package Name that Telephony will bind to.
9530 *
9531 * @param subId The sim that the GbaService is associated with.
9532 * @param packageName The name of the package to be replaced with.
9533 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9534 */
9535 @Override
9536 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9537 enforceModifyPermission();
9538
9539 final long identity = Binder.clearCallingIdentity();
9540 try {
9541 return getGbaManager(subId).overrideServicePackage(packageName);
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
9547 /**
9548 * Return the package name of the currently bound GbaService.
9549 *
9550 * @param subId The sim that the GbaService is associated with.
9551 * @return the package name of the GbaService configuration, null if GBA is not supported.
9552 */
9553 @Override
9554 public String getBoundGbaService(int subId) {
9555 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9556
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 return getGbaManager(subId).getServicePackage();
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
9564
9565 /**
9566 * Set the release time for telephony to unbind GbaService.
9567 *
9568 * @param subId The sim that the GbaService is associated with.
9569 * @param interval The release time to unbind GbaService by millisecond.
9570 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9571 */
9572 @Override
9573 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9574 enforceModifyPermission();
9575
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
9578 return getGbaManager(subId).overrideReleaseTime(interval);
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
9584 /**
9585 * Return the release time for telephony to unbind GbaService.
9586 *
9587 * @param subId The sim that the GbaService is associated with.
9588 * @return The release time to unbind GbaService by millisecond.
9589 */
9590 @Override
9591 public int getGbaReleaseTime(int subId) {
9592 enforceReadPrivilegedPermission("getGbaReleaseTime");
9593
9594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 return getGbaManager(subId).getReleaseTime();
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
9600 }
9601
9602 private GbaManager getGbaManager(int subId) {
9603 GbaManager instance = GbaManager.getInstance(subId);
9604 if (instance == null) {
9605 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9606 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9607 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9608 }
9609 return instance;
9610 }
Hui Wang068ab862020-10-31 05:12:53 +00009611
9612 /**
9613 * indicate whether the device and the carrier can support
9614 * RCS VoLTE single registration.
9615 */
9616 @Override
9617 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009618 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9619 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9620 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9621 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009622
9623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9624 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9625 }
9626
9627 final long identity = Binder.clearCallingIdentity();
9628 try {
9629 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9630 if (rpm != null) {
9631 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9632 }
9633 return false;
9634 } finally {
9635 Binder.restoreCallingIdentity(identity);
9636 }
9637 }
9638
9639 /**
9640 * Register RCS provisioning callback.
9641 */
9642 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009643 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009644 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009645 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009646 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009647 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9648 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009649
9650 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9651 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9652 }
9653 if (!isImsAvailableOnDevice()) {
9654 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9655 "IMS not available on device.");
9656 }
9657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009660 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009661 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9663 "Service not available for the subscription.");
9664 }
Hui Wang068ab862020-10-31 05:12:53 +00009665 } finally {
9666 Binder.restoreCallingIdentity(identity);
9667 }
9668 }
9669
9670 /**
9671 * Unregister RCS provisioning callback.
9672 */
9673 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009674 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009675 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009676 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009677 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009678 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9679 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009680
9681 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9682 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9683 }
9684 if (!isImsAvailableOnDevice()) {
9685 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9686 "IMS not available on device.");
9687 }
9688
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009691 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009692 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009693 } finally {
9694 Binder.restoreCallingIdentity(identity);
9695 }
9696 }
9697
9698 /**
9699 * trigger RCS reconfiguration.
9700 */
9701 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009702 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9703 "triggerRcsReconfiguration",
9704 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009705
9706 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9707 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9708 }
9709 if (!isImsAvailableOnDevice()) {
9710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9711 "IMS not available on device.");
9712 }
9713
9714 final long identity = Binder.clearCallingIdentity();
9715 try {
9716 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9717 } finally {
9718 Binder.restoreCallingIdentity(identity);
9719 }
9720 }
9721
9722 /**
9723 * Provide the client configuration parameters of the RCS application.
9724 */
9725 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009726 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9727 "setRcsClientConfiguration",
9728 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009729
9730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9731 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9732 }
9733 if (!isImsAvailableOnDevice()) {
9734 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9735 "IMS not available on device.");
9736 }
9737
9738 final long identity = Binder.clearCallingIdentity();
9739
9740 try {
9741 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9742 if (configBinder == null) {
9743 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9744 } else {
9745 configBinder.setRcsClientConfiguration(rcc);
9746 }
9747 } catch (RemoteException e) {
9748 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9749 } finally {
9750 Binder.restoreCallingIdentity(identity);
9751 }
9752 }
9753
9754 /**
Hui Wang19a21872021-02-19 20:45:36 -08009755 * Enables or disables the test mode for RCS VoLTE single registration.
9756 */
9757 @Override
9758 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9760 "setRcsSingleRegistrationTestModeEnabled");
9761
9762 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9763 }
9764
9765 /**
9766 * Gets the test mode for RCS VoLTE single registration.
9767 */
9768 @Override
9769 public boolean getRcsSingleRegistrationTestModeEnabled() {
9770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9771 "getRcsSingleRegistrationTestModeEnabled");
9772
9773 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9774 }
9775
9776 /**
Hui Wang068ab862020-10-31 05:12:53 +00009777 * Overrides the config of RCS VoLTE single registration enabled for the device.
9778 */
9779 @Override
9780 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9782 "setDeviceSingleRegistrationEnabledOverride");
9783 enforceModifyPermission();
9784
9785 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9786 : Boolean.parseBoolean(enabledStr);
9787 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009788 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009789 }
9790
9791 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009792 * Sends a device to device communication message. Only usable via shell.
9793 * @param message message to send.
9794 * @param value message value.
9795 */
9796 @Override
9797 public void sendDeviceToDeviceMessage(int message, int value) {
9798 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9799 "setCarrierSingleRegistrationEnabledOverride");
9800 enforceModifyPermission();
9801
9802 final long identity = Binder.clearCallingIdentity();
9803 try {
9804 TelephonyConnectionService service =
9805 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9806 if (service == null) {
9807 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9808 return;
9809 }
9810 service.sendTestDeviceToDeviceMessage(message, value);
9811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
9815
9816
9817 /**
Hui Wang068ab862020-10-31 05:12:53 +00009818 * Gets the config of RCS VoLTE single registration enabled for the device.
9819 */
9820 @Override
9821 public boolean getDeviceSingleRegistrationEnabled() {
9822 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9823 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9824 }
9825
9826 /**
9827 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9828 */
9829 @Override
9830 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9831 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9832 "setCarrierSingleRegistrationEnabledOverride");
9833 enforceModifyPermission();
9834
9835 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9836 : Boolean.parseBoolean(enabledStr);
9837 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9838 subId, enabled);
9839 }
9840
9841 /**
9842 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9843 */
9844 @Override
9845 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9846 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9847 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9848 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009849
9850 /**
9851 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9852 * their mobile plan.
9853 */
9854 @Override
9855 public String getMobileProvisioningUrl() {
9856 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9857 final long identity = Binder.clearCallingIdentity();
9858 try {
9859 return getDefaultPhone().getMobileProvisioningUrl();
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009864
James.cf Linbcdf8b32021-01-14 16:44:13 +08009865 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009866 * Get the EAB contact from the EAB database.
9867 */
9868 @Override
9869 public String getContactFromEab(String contact) {
9870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9871 enforceModifyPermission();
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
9880 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009881 * Remove the EAB contacts from the EAB database.
9882 */
9883 @Override
9884 public int removeContactFromEab(int subId, String contacts) {
9885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9886 enforceModifyPermission();
9887 final long identity = Binder.clearCallingIdentity();
9888 try {
9889 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
9894
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009895 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009896 public boolean getDeviceUceEnabled() {
9897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 return mApp.getDeviceUceEnabled();
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
9905
9906 @Override
9907 public void setDeviceUceEnabled(boolean isEnabled) {
9908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9909 final long identity = Binder.clearCallingIdentity();
9910 try {
9911 mApp.setDeviceUceEnabled(isEnabled);
9912 } finally {
9913 Binder.restoreCallingIdentity(identity);
9914 }
9915 }
9916
9917 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009918 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9919 String callingPackage) {
9920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9921 mApp, subId, "setSignalStrengthUpdateRequest");
9922
9923 final int callingUid = Binder.getCallingUid();
9924 // Verify that tha callingPackage belongs to the calling UID
9925 mApp.getSystemService(AppOpsManager.class)
9926 .checkPackage(callingUid, callingPackage);
9927
9928 validateSignalStrengthUpdateRequest(request, callingUid);
9929
9930 final long identity = Binder.clearCallingIdentity();
9931 try {
9932 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9933 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9934
9935 if (result instanceof IllegalStateException) {
9936 throw (IllegalStateException) result;
9937 }
9938 } finally {
9939 Binder.restoreCallingIdentity(identity);
9940 }
9941 }
9942
9943 @Override
9944 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9945 String callingPackage) {
9946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9947 mApp, subId, "clearSignalStrengthUpdateRequest");
9948
9949 final int callingUid = Binder.getCallingUid();
9950 // Verify that tha callingPackage belongs to the calling UID
9951 mApp.getSystemService(AppOpsManager.class)
9952 .checkPackage(callingUid, callingPackage);
9953
9954 final long identity = Binder.clearCallingIdentity();
9955 try {
9956 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9957 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9958
9959 if (result instanceof IllegalStateException) {
9960 throw (IllegalStateException) result;
9961 }
9962 } finally {
9963 Binder.restoreCallingIdentity(identity);
9964 }
9965 }
9966
9967 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9968 int callingUid) {
9969 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9970 // phone/system process do not have further restriction on request
9971 return;
9972 }
9973
9974 // Applications has restrictions on how to use the request:
9975 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9976 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9977 // This is not system caller which has been checked above
9978 throw new IllegalArgumentException(
9979 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9980 }
9981
9982 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9983 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9984 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9985 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9986 || info.isEnabled()) {
9987 throw new IllegalArgumentException(
9988 "Only system can set hide fields in SignalThresholdInfo");
9989 }
9990
9991 // Thresholds length for each RAN need in range. This has been validated in
9992 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9993 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9994 final int[] thresholds = info.getThresholds();
9995 Objects.requireNonNull(thresholds);
9996 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9997 || thresholds.length
9998 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9999 throw new IllegalArgumentException(
10000 "thresholds length is out of range: " + thresholds.length);
10001 }
10002 }
10003 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010004
10005 /**
10006 * Prepare TelephonyManager for an unattended reboot. The reboot is
10007 * required to be done shortly after the API is invoked.
10008 */
10009 @Override
10010 @TelephonyManager.PrepareUnattendedRebootResult
10011 public int prepareForUnattendedReboot() {
10012 enforceRebootPermission();
10013
10014 final long identity = Binder.clearCallingIdentity();
10015 try {
10016 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10017 } finally {
10018 Binder.restoreCallingIdentity(identity);
10019 }
10020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010021}