blob: 79bb3013707a40fc9b9c97740a342614078d4c11 [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;
Svet Ganovb320e182015-04-16 12:30:10 -0700162import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700163import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700164import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800166import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800167import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700169import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700171import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800172import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700173import com.android.internal.telephony.imsphone.ImsPhone;
174import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800175import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900176import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800178import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700181import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800186import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700187import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700188import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800192import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700193import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700194import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800195import com.android.services.telephony.TelecomAccountRegistry;
196import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800197import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800198
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700199import java.io.FileDescriptor;
200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800211import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800212import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
214/**
215 * Implementation of the ITelephony interface.
216 */
Santos Cordon117fee72014-05-16 17:56:12 -0700217public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 private static final String LOG_TAG = "PhoneInterfaceManager";
219 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
220 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 // Message codes used with mMainThreadHandler
224 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700225 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
226 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227 private static final int CMD_OPEN_CHANNEL = 9;
228 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
229 private static final int CMD_CLOSE_CHANNEL = 11;
230 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800231 private static final int CMD_NV_READ_ITEM = 13;
232 private static final int EVENT_NV_READ_ITEM_DONE = 14;
233 private static final int CMD_NV_WRITE_ITEM = 15;
234 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
235 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
236 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700237 private static final int CMD_RESET_MODEM_CONFIG = 19;
238 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800239 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
240 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
241 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
242 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800243 private static final int CMD_SEND_ENVELOPE = 25;
244 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000245 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
246 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700247 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
248 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
249 private static final int CMD_EXCHANGE_SIM_IO = 31;
250 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800251 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
252 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700253 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
254 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700255 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
256 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700257 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
258 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
259 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
260 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700261 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
262 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
263 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
264 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700265 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800266 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
267 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000268 private static final int CMD_SWITCH_SLOTS = 50;
269 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700270 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
271 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
272 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
273 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
274 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
275 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
276 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
277 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700278 private static final int CMD_GET_ALL_CELL_INFO = 60;
279 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
280 private static final int CMD_GET_CELL_LOCATION = 62;
281 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700282 private static final int CMD_MODEM_REBOOT = 64;
283 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700284 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
285 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800286 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
287 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700288 private static final int CMD_GET_MODEM_STATUS = 70;
289 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700290 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
291 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700292 private static final int CMD_ERASE_MODEM_CONFIG = 74;
293 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800294 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
295 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
296 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
297 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800298 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
299 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800300 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800301 private static final int CMD_GET_CALL_FORWARDING = 83;
302 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
303 private static final int CMD_SET_CALL_FORWARDING = 85;
304 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
305 private static final int CMD_GET_CALL_WAITING = 87;
306 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
307 private static final int CMD_SET_CALL_WAITING = 89;
308 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700309 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
310 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
311 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
312 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700313 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
314 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800315 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
316 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800317 private static final int CMD_SET_DATA_THROTTLING = 99;
318 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800319 private static final int CMD_SET_SIM_POWER = 101;
320 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800321 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
322 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
323 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
324 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
Michele Berionned9fbae52020-11-13 02:36:59 +0000325 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800327 // Parameters of select command.
328 private static final int SELECT_COMMAND = 0xA4;
329 private static final int SELECT_P1 = 0x04;
330 private static final int SELECT_P2 = 0;
331 private static final int SELECT_P3 = 0x10;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 /** The singleton instance. */
334 private static PhoneInterfaceManager sInstance;
335
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800338 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700339 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private AppOpsManager mAppOps;
341 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800342 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700344 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
Peter Wangdafb9ac2020-01-15 14:13:38 -0800346 /** User Activity */
347 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800348 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
349
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700350 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
351
Derek Tan97ebb422014-09-05 16:55:38 -0700352 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
353 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800354 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800355 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700356
Michelecea4cf22018-12-21 15:00:11 -0800357 // String to store multi SIM allowed
358 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
359
Derek Tan740e1672017-06-27 14:56:27 -0700360 // The AID of ISD-R.
361 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
362
yinxub1bed742017-04-17 11:45:04 -0700363 private NetworkScanRequestTracker mNetworkScanRequestTracker;
364
David Kelly5e06a7f2018-03-12 14:10:59 +0000365 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
366 private static final int MANUFACTURER_CODE_LENGTH = 8;
367
Jack Nudelman24d51a52020-11-24 12:08:04 -0800368 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
369
Derek Tan89e89d42014-07-08 17:00:10 -0700370 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700371 * Experiment flag to enable erase modem config on reset network, default value is false
372 */
373 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
374 "reset_network_erase_modem_config_enabled";
375
Rambo Wang0f050d82021-02-12 11:43:36 -0800376 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
377
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700378 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700379 * A request object to use for transmitting data to an ICC.
380 */
381 private static final class IccAPDUArgument {
382 public int channel, cla, command, p1, p2, p3;
383 public String data;
384
385 public IccAPDUArgument(int channel, int cla, int command,
386 int p1, int p2, int p3, String data) {
387 this.channel = channel;
388 this.cla = cla;
389 this.command = command;
390 this.p1 = p1;
391 this.p2 = p2;
392 this.p3 = p3;
393 this.data = data;
394 }
395 }
396
397 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700398 * A request object to use for transmitting data to an ICC.
399 */
400 private static final class ManualNetworkSelectionArgument {
401 public OperatorInfo operatorInfo;
402 public boolean persistSelection;
403
404 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
405 this.operatorInfo = operatorInfo;
406 this.persistSelection = persistSelection;
407 }
408 }
409
410 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
412 * request after sending. The main thread will notify the request when it is complete.
413 */
414 private static final class MainThreadRequest {
415 /** The argument to use for the request */
416 public Object argument;
417 /** The result of the request that is run on the main thread */
418 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800419 // The subscriber id that this request applies to. Defaults to
420 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
421 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422
Nathan Harold92bed182018-10-12 18:16:49 -0700423 // In cases where subId is unavailable, the caller needs to specify the phone.
424 public Phone phone;
425
vagdeviaf9a5b92018-08-15 16:01:53 -0700426 public WorkSource workSource;
427
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 public MainThreadRequest(Object argument) {
429 this.argument = argument;
430 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800431
Nathan Harold92bed182018-10-12 18:16:49 -0700432 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
433 this.argument = argument;
434 if (phone != null) {
435 this.phone = phone;
436 }
437 this.workSource = workSource;
438 }
439
vagdeviaf9a5b92018-08-15 16:01:53 -0700440 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800441 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800442 if (subId != null) {
443 this.subId = subId;
444 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700445 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 }
448
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800449 private static final class IncomingThirdPartyCallArgs {
450 public final ComponentName component;
451 public final String callId;
452 public final String callerDisplayName;
453
454 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
455 String callerDisplayName) {
456 this.component = component;
457 this.callId = callId;
458 this.callerDisplayName = callerDisplayName;
459 }
460 }
461
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 /**
463 * A handler that processes messages on the main thread in the phone process. Since many
464 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
465 * inbound binder threads to the main thread in the phone process. The Binder thread
466 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
467 * on, which will be notified when the operation completes and will contain the result of the
468 * request.
469 *
470 * <p>If a MainThreadRequest object is provided in the msg.obj field,
471 * note that request.result must be set to something non-null for the calling thread to
472 * unblock.
473 */
474 private final class MainThreadHandler extends Handler {
475 @Override
476 public void handleMessage(Message msg) {
477 MainThreadRequest request;
478 Message onCompleted;
479 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800480 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800482 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483
484 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 case CMD_HANDLE_USSD_REQUEST: {
486 request = (MainThreadRequest) msg.obj;
487 final Phone phone = getPhoneFromRequest(request);
488 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
489 String ussdRequest = ussdObject.first;
490 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700491
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 if (!isUssdApiAllowed(request.subId)) {
493 // Carrier does not support use of this API, return failure.
494 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
495 UssdResponse response = new UssdResponse(ussdRequest, null);
496 Bundle returnData = new Bundle();
497 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
498 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700499
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 request.result = true;
501 notifyRequester(request);
502 return;
503 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700504
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 try {
506 request.result = phone != null
507 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
508 } catch (CallStateException cse) {
509 request.result = false;
510 }
511 // Wake up the requesting thread
512 notifyRequester(request);
513 break;
pkanwar32d516d2016-10-14 19:37:38 -0700514 }
515
Yorke Lee716f67e2015-06-17 15:39:16 -0700516 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700518 final Phone phone = getPhoneFromRequest(request);
519 request.result = phone != null ?
520 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
521 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 if (uiccCard == null) {
532 loge("iccTransmitApduLogicalChannel: No UICC");
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
537 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 iccArgument.channel, iccArgument.cla, iccArgument.command,
540 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 break;
544
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
550 } else {
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
552 if (ar.result == null) {
553 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800554 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800556 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 } else {
558 loge("iccTransmitApduLogicalChannel: Unknown exception");
559 }
560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 break;
563
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
565 request = (MainThreadRequest) msg.obj;
566 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 if (uiccCard == null) {
569 loge("iccTransmitApduBasicChannel: No UICC");
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 } else {
573 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
574 request);
575 uiccCard.iccTransmitApduBasicChannel(
576 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
577 iccArgument.p3, iccArgument.data, onCompleted);
578 }
579 break;
580
581 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
584 if (ar.exception == null && ar.result != null) {
585 request.result = ar.result;
586 } else {
587 request.result = new IccIoResult(0x6F, 0, (byte[])null);
588 if (ar.result == null) {
589 loge("iccTransmitApduBasicChannel: Empty response");
590 } else if (ar.exception instanceof CommandException) {
591 loge("iccTransmitApduBasicChannel: CommandException: " +
592 ar.exception);
593 } else {
594 loge("iccTransmitApduBasicChannel: Unknown exception");
595 }
596 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 break;
599
600 case CMD_EXCHANGE_SIM_IO:
601 request = (MainThreadRequest) msg.obj;
602 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800603 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 if (uiccCard == null) {
605 loge("iccExchangeSimIO: No UICC");
606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 } else {
609 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
610 request);
611 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
612 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
613 iccArgument.data, onCompleted);
614 }
615 break;
616
617 case EVENT_EXCHANGE_SIM_IO_DONE:
618 ar = (AsyncResult) msg.obj;
619 request = (MainThreadRequest) ar.userObj;
620 if (ar.exception == null && ar.result != null) {
621 request.result = ar.result;
622 } else {
623 request.result = new IccIoResult(0x6f, 0, (byte[])null);
624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 break;
627
Derek Tan4d5e5c12014-02-04 11:54:58 -0800628 case CMD_SEND_ENVELOPE:
629 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800630 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 if (uiccCard == null) {
632 loge("sendEnvelopeWithStatus: No UICC");
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
637 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
638 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800639 break;
640
641 case EVENT_SEND_ENVELOPE_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700647 request.result = new IccIoResult(0x6F, 0, (byte[])null);
648 if (ar.result == null) {
649 loge("sendEnvelopeWithStatus: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("sendEnvelopeWithStatus: CommandException: " +
652 ar.exception);
653 } else {
654 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
655 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 break;
659
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 case CMD_OPEN_CHANNEL:
661 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800662 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800663 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 if (uiccCard == null) {
665 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800666 request.result = new IccOpenLogicalChannelResponse(-1,
667 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 } else {
670 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800671 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
672 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case EVENT_OPEN_CHANNEL_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 int[] result = (int[]) ar.result;
682 int channelId = result[0];
683 byte[] selectResponse = null;
684 if (result.length > 1) {
685 selectResponse = new byte[result.length - 1];
686 for (int i = 1; i < result.length; ++i) {
687 selectResponse[i - 1] = (byte) result[i];
688 }
689 }
690 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700691 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 if (ar.result == null) {
694 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 if (ar.exception != null) {
697 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
698 }
699
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700701 if (ar.exception instanceof CommandException) {
702 CommandException.Error error =
703 ((CommandException) (ar.exception)).getCommandError();
704 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700705 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700706 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
709 }
710 openChannelResp = new IccOpenLogicalChannelResponse(
711 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700713 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 break;
716
717 case CMD_CLOSE_CHANNEL:
718 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800719 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 if (uiccCard == null) {
721 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900722 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 } else {
725 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
726 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
727 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 break;
729
730 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800731 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
732 break;
733
734 case CMD_NV_READ_ITEM:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
738 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800739 break;
740
741 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 ar = (AsyncResult) msg.obj;
743 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800744 if (ar.exception == null && ar.result != null) {
745 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800747 request.result = "";
748 if (ar.result == null) {
749 loge("nvReadItem: Empty response");
750 } else if (ar.exception instanceof CommandException) {
751 loge("nvReadItem: CommandException: " +
752 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800754 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 }
756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 break;
759
Jake Hambye994d462014-02-03 13:10:13 -0800760 case CMD_NV_WRITE_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
763 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700765 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
768 case EVENT_NV_WRITE_ITEM_DONE:
769 handleNullReturnEvent(msg, "nvWriteItem");
770 break;
771
772 case CMD_NV_WRITE_CDMA_PRL:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800775 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800776 break;
777
778 case EVENT_NV_WRITE_CDMA_PRL_DONE:
779 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
780 break;
781
chen xu6dac5ab2018-10-26 17:39:23 -0700782 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800783 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700784 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
chen xu6dac5ab2018-10-26 17:39:23 -0700788 case EVENT_RESET_MODEM_CONFIG_DONE:
789 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800790 break;
791
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700792 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
795 request);
796 Phone phone = getPhoneFromRequest(request);
797 if (phone != null) {
798 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
799 } else {
800 loge("isNRDualConnectivityEnabled: No phone object");
801 request.result = false;
802 notifyRequester(request);
803 }
804 break;
805 }
806
807 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 // request.result must be set to something non-null
814 // for the calling thread to unblock
815 if (request.result != null) {
816 request.result = ar.result;
817 } else {
818 request.result = false;
819 }
820 if (ar.result == null) {
821 loge("isNRDualConnectivityEnabled: Empty response");
822 } else if (ar.exception instanceof CommandException) {
823 loge("isNRDualConnectivityEnabled: CommandException: "
824 + ar.exception);
825 } else {
826 loge("isNRDualConnectivityEnabled: Unknown exception");
827 }
828 }
829 notifyRequester(request);
830 break;
831
832 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
835 Phone phone = getPhoneFromRequest(request);
836 if (phone != null) {
837 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
838 request.workSource);
839 } else {
840 loge("enableNrDualConnectivity: No phone object");
841 request.result =
842 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
843 notifyRequester(request);
844 }
845 break;
846 }
847
848 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null) {
852 request.result =
853 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
854 } else {
855 request.result =
856 TelephonyManager
857 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
858 if (ar.exception instanceof CommandException) {
859 CommandException.Error error =
860 ((CommandException) (ar.exception)).getCommandError();
861 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
862 request.result =
863 TelephonyManager
864 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
865 }
866 loge("enableNrDualConnectivity" + ": CommandException: "
867 + ar.exception);
868 } else {
869 loge("enableNrDualConnectivity" + ": Unknown exception");
870 }
871 }
872 notifyRequester(request);
873 break;
874 }
875
Jake Hamby7c27be32014-03-03 13:25:59 -0800876 case CMD_GET_PREFERRED_NETWORK_TYPE:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700879 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 break;
881
882 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result; // Integer
887 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530888 // request.result must be set to something non-null
889 // for the calling thread to unblock
890 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800891 if (ar.result == null) {
892 loge("getPreferredNetworkType: Empty response");
893 } else if (ar.exception instanceof CommandException) {
894 loge("getPreferredNetworkType: CommandException: " +
895 ar.exception);
896 } else {
897 loge("getPreferredNetworkType: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 break;
902
903 case CMD_SET_PREFERRED_NETWORK_TYPE:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
906 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700907 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 break;
909
910 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
911 handleNullReturnEvent(msg, "setPreferredNetworkType");
912 break;
913
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000914 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
915 request = (MainThreadRequest)msg.obj;
916 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800917 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000918 break;
919
920 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
921 ar = (AsyncResult)msg.obj;
922 request = (MainThreadRequest)ar.userObj;
923 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000925 break;
926
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800927 case CMD_SET_VOICEMAIL_NUMBER:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
930 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800931 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
932 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800933 break;
934
935 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
936 handleNullReturnEvent(msg, "setVoicemailNumber");
937 break;
938
Stuart Scott54788802015-03-30 13:18:01 -0700939 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
942 request);
943 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
944 break;
945
946 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
947 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
948 break;
949
Shishir Agrawal302c8692015-06-19 13:49:39 -0700950 case CMD_PERFORM_NETWORK_SCAN:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
953 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
954 break;
955
Hall Liua1acea22020-09-18 19:04:59 -0700956 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700959 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
960 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
961 request.argument;
962 int callForwardingReason = args.first;
963 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800964 break;
Hall Liua1acea22020-09-18 19:04:59 -0700965 }
966 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700969 TelephonyManager.CallForwardingInfoCallback callback =
970 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
971 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800972 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700973 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800974 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
975 for (CallForwardInfo callForwardInfo : callForwardInfos) {
976 // Service Class is a bit mask per 3gpp 27.007. Search for
977 // any service for voice call.
978 if ((callForwardInfo.serviceClass
979 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700980 callForwardingInfo = new CallForwardingInfo(true,
981 callForwardInfo.reason,
982 callForwardInfo.number,
983 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800984 break;
985 }
986 }
987 // Didn't find a call forward info for voice call.
988 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700989 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
990 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800991 }
Hall Liua1acea22020-09-18 19:04:59 -0700992 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800993 } else {
994 if (ar.result == null) {
995 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
996 }
997 if (ar.exception != null) {
998 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
999 }
Hall Liuae527aa2020-09-29 17:10:18 -07001000 int errorCode = TelephonyManager
1001 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001002 if (ar.exception instanceof CommandException) {
1003 CommandException.Error error =
1004 ((CommandException) (ar.exception)).getCommandError();
1005 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001006 errorCode = TelephonyManager
1007 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001008 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001009 errorCode = TelephonyManager
1010 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001011 }
1012 }
Hall Liua1acea22020-09-18 19:04:59 -07001013 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001014 }
sqian80370722020-01-29 15:02:51 -08001015 break;
Hall Liua1acea22020-09-18 19:04:59 -07001016 }
sqian80370722020-01-29 15:02:51 -08001017
Hall Liua1acea22020-09-18 19:04:59 -07001018 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001021 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001022 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001023 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1024 request.argument).first;
1025 request.phone.setCallForwardingOption(
1026 callForwardingInfoToSet.isEnabled()
1027 ? CommandsInterface.CF_ACTION_ENABLE
1028 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001029 callForwardingInfoToSet.getReason(),
1030 callForwardingInfoToSet.getNumber(),
1031 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1032 break;
Hall Liua1acea22020-09-18 19:04:59 -07001033 }
sqian80370722020-01-29 15:02:51 -08001034
Hall Liua1acea22020-09-18 19:04:59 -07001035 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001038 Consumer<Integer> callback =
1039 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1040 request.argument).second;
1041 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001042 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001043 int errorCode = TelephonyManager.CallForwardingInfoCallback
1044 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001045 if (ar.exception instanceof CommandException) {
1046 CommandException.Error error =
1047 ((CommandException) (ar.exception)).getCommandError();
1048 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001049 errorCode = TelephonyManager.CallForwardingInfoCallback
1050 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001051 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001052 errorCode = TelephonyManager.CallForwardingInfoCallback
1053 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001054 }
1055 }
1056 callback.accept(errorCode);
1057 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001058 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001059 }
sqian80370722020-01-29 15:02:51 -08001060 break;
Hall Liua1acea22020-09-18 19:04:59 -07001061 }
sqian80370722020-01-29 15:02:51 -08001062
Hall Liua1acea22020-09-18 19:04:59 -07001063 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001064 request = (MainThreadRequest) msg.obj;
1065 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1066 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1067 break;
Hall Liua1acea22020-09-18 19:04:59 -07001068 }
sqian80370722020-01-29 15:02:51 -08001069
Hall Liua1acea22020-09-18 19:04:59 -07001070 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001073 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001074 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1075 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001076 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001077 // Service Class is a bit mask per 3gpp 27.007.
1078 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001079 if (callForwardResults.length > 1
1080 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001081 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001082 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001083 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1084 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001085 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001086 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001087 }
1088 } else {
1089 if (ar.result == null) {
1090 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1091 }
1092 if (ar.exception != null) {
1093 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1094 }
1095 if (ar.exception instanceof CommandException) {
1096 CommandException.Error error =
1097 ((CommandException) (ar.exception)).getCommandError();
1098 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1099 callForwardingStatus =
1100 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1101 }
1102 }
1103 }
Hall Liua1acea22020-09-18 19:04:59 -07001104 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001105 break;
Hall Liua1acea22020-09-18 19:04:59 -07001106 }
sqian80370722020-01-29 15:02:51 -08001107
Hall Liua1acea22020-09-18 19:04:59 -07001108 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001109 request = (MainThreadRequest) msg.obj;
1110 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001111 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1112 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001113 break;
Hall Liua1acea22020-09-18 19:04:59 -07001114 }
sqian80370722020-01-29 15:02:51 -08001115
Hall Liua1acea22020-09-18 19:04:59 -07001116 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001117 ar = (AsyncResult) msg.obj;
1118 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001119 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1120 Consumer<Integer> callback =
1121 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1122 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001123 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1128 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1129 } else {
1130 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1131 }
1132 } else {
1133 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1134 }
1135 } else {
1136 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1137 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001138 }
sqian80370722020-01-29 15:02:51 -08001139 break;
Hall Liua1acea22020-09-18 19:04:59 -07001140 }
sqian80370722020-01-29 15:02:51 -08001141
Shishir Agrawal302c8692015-06-19 13:49:39 -07001142 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 CellNetworkScanResult cellScanResult;
1146 if (ar.exception == null && ar.result != null) {
1147 cellScanResult = new CellNetworkScanResult(
1148 CellNetworkScanResult.STATUS_SUCCESS,
1149 (List<OperatorInfo>) ar.result);
1150 } else {
1151 if (ar.result == null) {
1152 loge("getCellNetworkScanResults: Empty response");
1153 }
1154 if (ar.exception != null) {
1155 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1156 }
1157 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1158 if (ar.exception instanceof CommandException) {
1159 CommandException.Error error =
1160 ((CommandException) (ar.exception)).getCommandError();
1161 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1162 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1163 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1164 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1165 }
1166 }
1167 cellScanResult = new CellNetworkScanResult(errorCode, null);
1168 }
1169 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001171 break;
1172
1173 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1174 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001175 ManualNetworkSelectionArgument selArg =
1176 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001177 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1178 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001179 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1180 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 break;
1182
1183 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null) {
1187 request.result = true;
1188 } else {
1189 request.result = false;
1190 loge("setNetworkSelectionModeManual " + ar.exception);
1191 }
1192 notifyRequester(request);
1193 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 break;
1195
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001196 case CMD_GET_MODEM_ACTIVITY_INFO:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001199 if (defaultPhone != null) {
1200 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001201 } else {
1202 ResultReceiver result = (ResultReceiver) request.argument;
1203 Bundle bundle = new Bundle();
1204 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1205 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1206 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001207 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001208 break;
1209
1210 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001213 ResultReceiver result = (ResultReceiver) request.argument;
1214
1215 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001216 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001217 // Update the last modem activity info and the result of the request.
1218 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1219 if (isModemActivityInfoValid(info)) {
1220 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1221 int[] txTimeMs = info.getTransmitTimeMillis();
1222 int[] lastModemTxTimeMs = mLastModemActivityInfo
1223 .getTransmitTimeMillis();
1224 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1225 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1226 }
1227 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1228 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1229 + mLastModemActivityInfo.getSleepTimeMillis());
1230 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1231 + mLastModemActivityInfo.getIdleTimeMillis());
1232 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1233 mLastModemActivityInfo.setReceiveTimeMillis(
1234 info.getReceiveTimeMillis()
1235 + mLastModemActivityInfo.getReceiveTimeMillis());
1236 }
1237 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1238 mLastModemActivityInfo.getSleepTimeMillis(),
1239 mLastModemActivityInfo.getIdleTimeMillis(),
1240 mLastModemActivityInfo.getTransmitTimeMillis(),
1241 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 } else {
1243 if (ar.result == null) {
1244 loge("queryModemActivityInfo: Empty response");
1245 } else if (ar.exception instanceof CommandException) {
1246 loge("queryModemActivityInfo: CommandException: " +
1247 ar.exception);
1248 } else {
1249 loge("queryModemActivityInfo: Unknown exception");
1250 }
1251 }
sqian1a1be542020-03-05 11:37:28 -08001252 Bundle bundle = new Bundle();
1253 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1254 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001255 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001256 break;
1257
Meng Wang1a7c35a2016-05-05 20:56:15 -07001258 case CMD_SET_ALLOWED_CARRIERS:
1259 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001260 CarrierRestrictionRules argument =
1261 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001262 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001263 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001264 break;
1265
1266 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
1269 if (ar.exception == null && ar.result != null) {
1270 request.result = ar.result;
1271 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001272 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1273 if (ar.exception instanceof CommandException) {
1274 loge("setAllowedCarriers: CommandException: " + ar.exception);
1275 CommandException.Error error =
1276 ((CommandException) (ar.exception)).getCommandError();
1277 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1278 request.result =
1279 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 } else {
1282 loge("setAllowedCarriers: Unknown exception");
1283 }
1284 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001285 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 break;
1287
1288 case CMD_GET_ALLOWED_CARRIERS:
1289 request = (MainThreadRequest) msg.obj;
1290 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001291 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 break;
1293
1294 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null && ar.result != null) {
1298 request.result = ar.result;
1299 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001300 request.result = new IllegalStateException(
1301 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 if (ar.result == null) {
1303 loge("getAllowedCarriers: Empty response");
1304 } else if (ar.exception instanceof CommandException) {
1305 loge("getAllowedCarriers: CommandException: " +
1306 ar.exception);
1307 } else {
1308 loge("getAllowedCarriers: Unknown exception");
1309 }
1310 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001312 break;
1313
Nathan Haroldb3014052017-01-25 15:57:32 -08001314 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
1317 if (ar.exception == null && ar.result != null) {
1318 request.result = ar.result;
1319 } else {
1320 request.result = new IllegalArgumentException(
1321 "Failed to retrieve Forbidden Plmns");
1322 if (ar.result == null) {
1323 loge("getForbiddenPlmns: Empty response");
1324 } else {
1325 loge("getForbiddenPlmns: Unknown exception");
1326 }
1327 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001328 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001329 break;
1330
1331 case CMD_GET_FORBIDDEN_PLMNS:
1332 request = (MainThreadRequest) msg.obj;
1333 uiccCard = getUiccCardFromRequest(request);
1334 if (uiccCard == null) {
1335 loge("getForbiddenPlmns() UiccCard is null");
1336 request.result = new IllegalArgumentException(
1337 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001338 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001339 break;
1340 }
1341 Integer appType = (Integer) request.argument;
1342 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1343 if (uiccApp == null) {
1344 loge("getForbiddenPlmns() no app with specified type -- "
1345 + appType);
1346 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001347 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001348 break;
1349 } else {
1350 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1351 + " specified type -- " + appType);
1352 }
1353 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1354 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1355 onCompleted);
1356 break;
1357
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001358 case CMD_SWITCH_SLOTS:
1359 request = (MainThreadRequest) msg.obj;
1360 int[] physicalSlots = (int[]) request.argument;
1361 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1362 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1363 break;
1364
1365 case EVENT_SWITCH_SLOTS_DONE:
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
1370 break;
1371 case CMD_GET_NETWORK_SELECTION_MODE:
1372 request = (MainThreadRequest) msg.obj;
1373 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1374 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1375 break;
1376
1377 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 if (ar.exception != null) {
1381 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1382 } else {
1383 int mode = ((int[]) ar.result)[0];
1384 if (mode == 0) {
1385 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1386 } else {
1387 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1388 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001389 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001390 notifyRequester(request);
1391 break;
1392 case CMD_GET_CDMA_ROAMING_MODE:
1393 request = (MainThreadRequest) msg.obj;
1394 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1395 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1396 break;
1397 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception != null) {
1401 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1402 } else {
1403 request.result = ((int[]) ar.result)[0];
1404 }
1405 notifyRequester(request);
1406 break;
1407 case CMD_SET_CDMA_ROAMING_MODE:
1408 request = (MainThreadRequest) msg.obj;
1409 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1410 int mode = (int) request.argument;
1411 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1412 break;
1413 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
1416 request.result = ar.exception == null;
1417 notifyRequester(request);
1418 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001419 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1422 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1423 break;
1424 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1425 ar = (AsyncResult) msg.obj;
1426 request = (MainThreadRequest) ar.userObj;
1427 if (ar.exception != null) {
1428 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1429 } else {
1430 request.result = ((int[]) ar.result)[0];
1431 }
1432 notifyRequester(request);
1433 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1437 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001438 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1439 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001440 break;
1441 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 request.result = ar.exception == null;
1445 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001446 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001447 case CMD_GET_ALL_CELL_INFO:
1448 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001449 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001450 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001451 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 case EVENT_GET_ALL_CELL_INFO_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001455 // If a timeout occurs, the response will be null
1456 request.result = (ar.exception == null && ar.result != null)
1457 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 synchronized (request) {
1459 request.notifyAll();
1460 }
1461 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001462 case CMD_REQUEST_CELL_INFO_UPDATE:
1463 request = (MainThreadRequest) msg.obj;
1464 request.phone.requestCellInfoUpdate(request.workSource,
1465 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1466 break;
1467 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1471 try {
1472 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001473 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001474 cb.onError(
1475 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1476 ar.exception.getClass().getName(),
1477 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001479 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001480 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 } else {
1482 // use the result as returned
1483 cb.onCellInfo((List<CellInfo>) ar.result);
1484 }
1485 } catch (RemoteException re) {
1486 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1487 }
1488 break;
Sarah Chincc055732020-11-18 13:39:35 -08001489 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 request = (MainThreadRequest) msg.obj;
1491 WorkSource ws = (WorkSource) request.argument;
1492 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001493 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 break;
Sarah Chincc055732020-11-18 13:39:35 -08001495 }
1496 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 if (ar.exception == null) {
1500 request.result = ar.result;
1501 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001502 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001503 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001504 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 }
1506
1507 synchronized (request) {
1508 request.notifyAll();
1509 }
1510 break;
Sarah Chincc055732020-11-18 13:39:35 -08001511 }
chen xu6dac5ab2018-10-26 17:39:23 -07001512 case CMD_MODEM_REBOOT:
1513 request = (MainThreadRequest) msg.obj;
1514 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001515 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001516 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001517 case EVENT_CMD_MODEM_REBOOT_DONE:
1518 handleNullReturnEvent(msg, "rebootModem");
1519 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001520 case CMD_REQUEST_ENABLE_MODEM:
1521 request = (MainThreadRequest) msg.obj;
1522 boolean enable = (boolean) request.argument;
1523 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001524 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001525 PhoneConfigurationManager.getInstance()
1526 .enablePhone(request.phone, enable, onCompleted);
1527 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001528 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001532 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001533 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001534 if ((boolean) request.result) {
1535 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1536 updateModemStateMetrics();
1537 } else {
1538 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1539 + ar.exception);
1540 }
1541 notifyRequester(request);
1542 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001543 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001544 case CMD_GET_MODEM_STATUS:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1547 PhoneConfigurationManager.getInstance()
1548 .getPhoneStatusFromModem(request.phone, onCompleted);
1549 break;
1550 case EVENT_GET_MODEM_STATUS_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 int id = request.phone.getPhoneId();
1554 if (ar.exception == null && ar.result != null) {
1555 request.result = ar.result;
1556 //update the cache as modem status has changed
1557 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1558 (boolean) request.result);
1559 } else {
1560 // Return true if modem status cannot be retrieved. For most cases,
1561 // modem status is on. And for older version modems, GET_MODEM_STATUS
1562 // and disable modem are not supported. Modem is always on.
1563 // TODO: this should be fixed in R to support a third
1564 // status UNKNOWN b/131631629
1565 request.result = true;
1566 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1567 + ar.exception);
1568 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 notifyRequester(request);
1570 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001571 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1574 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1575 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1576 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1577 break;
1578 }
1579 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1583 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1584 args.second.accept(ar.exception == null);
1585 notifyRequester(request);
1586 break;
1587 }
Sarah Chincc055732020-11-18 13:39:35 -08001588 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1591 Phone phone = getPhoneFromRequest(request);
1592 if (phone != null) {
1593 phone.getSystemSelectionChannels(onCompleted);
1594 } else {
1595 loge("getSystemSelectionChannels: No phone object");
1596 request.result = new ArrayList<RadioAccessSpecifier>();
1597 notifyRequester(request);
1598 }
1599 break;
1600 }
1601 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception == null && ar.result != null) {
1605 request.result = ar.result;
1606 } else {
1607 request.result = new IllegalArgumentException(
1608 "Failed to retrieve system selection channels");
1609 if (ar.result == null) {
1610 loge("getSystemSelectionChannels: Empty response");
1611 } else {
1612 loge("getSystemSelectionChannels: Unknown exception");
1613 }
1614 }
1615 notifyRequester(request);
1616 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001617 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception == null && ar.result != null) {
1621 request.result = ar.result;
1622 } else {
1623 request.result = -1;
1624 loge("Failed to set Forbidden Plmns");
1625 if (ar.result == null) {
1626 loge("setForbidenPlmns: Empty response");
1627 } else if (ar.exception != null) {
1628 loge("setForbiddenPlmns: Exception: " + ar.exception);
1629 request.result = -1;
1630 } else {
1631 loge("setForbiddenPlmns: Unknown exception");
1632 }
1633 }
1634 notifyRequester(request);
1635 break;
1636 case CMD_SET_FORBIDDEN_PLMNS:
1637 request = (MainThreadRequest) msg.obj;
1638 uiccCard = getUiccCardFromRequest(request);
1639 if (uiccCard == null) {
1640 loge("setForbiddenPlmns: UiccCard is null");
1641 request.result = -1;
1642 notifyRequester(request);
1643 break;
1644 }
1645 Pair<Integer, List<String>> setFplmnsArgs =
1646 (Pair<Integer, List<String>>) request.argument;
1647 appType = setFplmnsArgs.first;
1648 List<String> fplmns = setFplmnsArgs.second;
1649 uiccApp = uiccCard.getApplicationByType(appType);
1650 if (uiccApp == null) {
1651 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1652 request.result = -1;
1653 loge("Failed to get UICC App");
1654 notifyRequester(request);
1655 } else {
1656 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1657 ((SIMRecords) uiccApp.getIccRecords())
1658 .setForbiddenPlmns(onCompleted, fplmns);
1659 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001660 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001661 case CMD_ERASE_MODEM_CONFIG:
1662 request = (MainThreadRequest) msg.obj;
1663 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1664 defaultPhone.eraseModemConfig(onCompleted);
1665 break;
1666 case EVENT_ERASE_MODEM_CONFIG_DONE:
1667 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001668 break;
zoey chenf95ca592019-12-30 16:11:23 +08001669
1670 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1673 Pair<String, String> changed = (Pair<String, String>) request.argument;
1674 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1675 changed.first, changed.second, onCompleted);
1676 break;
1677 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 if (ar.exception == null) {
1681 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001682 // If the operation is successful, update the PIN storage
1683 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1684 int phoneId = getPhoneFromRequest(request).getPhoneId();
1685 UiccController.getInstance().getPinStorage()
1686 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001687 } else {
1688 request.result = msg.arg1;
1689 }
1690 notifyRequester(request);
1691 break;
1692
Michele Berionned9fbae52020-11-13 02:36:59 +00001693 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001694 request = (MainThreadRequest) msg.obj;
1695 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1696 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1697 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1698 enabled.first, enabled.second, onCompleted);
1699 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001700 }
zoey chenf95ca592019-12-30 16:11:23 +08001701 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 if (ar.exception == null) {
1705 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001706 // If the operation is successful, update the PIN storage
1707 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1708 int phoneId = getPhoneFromRequest(request).getPhoneId();
1709 if (enabled.first) {
1710 UiccController.getInstance().getPinStorage()
1711 .storePin(enabled.second, phoneId);
1712 } else {
1713 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1714 }
zoey chenf95ca592019-12-30 16:11:23 +08001715 } else {
1716 request.result = msg.arg1;
1717 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001718
1719
zoey chenf95ca592019-12-30 16:11:23 +08001720 notifyRequester(request);
1721 break;
1722
Peter Wangdafb9ac2020-01-15 14:13:38 -08001723 case MSG_NOTIFY_USER_ACTIVITY:
1724 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001725 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001726 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1727 getDefaultPhone().getContext().sendBroadcastAsUser(
1728 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1729 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001730
1731 case CMD_SET_DATA_THROTTLING: {
1732 request = (MainThreadRequest) msg.obj;
1733 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1734 DataThrottlingRequest dataThrottlingRequest =
1735 (DataThrottlingRequest) request.argument;
1736 Phone phone = getPhoneFromRequest(request);
1737 if (phone != null) {
1738 phone.setDataThrottling(onCompleted,
1739 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1740 dataThrottlingRequest.getCompletionDurationMillis());
1741 } else {
1742 loge("setDataThrottling: No phone object");
1743 request.result =
1744 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1745 notifyRequester(request);
1746 }
1747
1748 break;
1749 }
1750 case EVENT_SET_DATA_THROTTLING_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753
1754 if (ar.exception == null) {
1755 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1756 } else if (ar.exception instanceof CommandException) {
1757 loge("setDataThrottling: CommandException: " + ar.exception);
1758 CommandException.Error error =
1759 ((CommandException) (ar.exception)).getCommandError();
1760
1761 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1762 request.result = TelephonyManager
1763 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1764 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1765 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1766 } else {
1767 request.result =
1768 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1769 }
1770 } else {
1771 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1772 }
1773 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1774 notifyRequester(request);
1775 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001776
1777 case CMD_SET_SIM_POWER: {
1778 request = (MainThreadRequest) msg.obj;
1779 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1780 request = (MainThreadRequest) msg.obj;
1781 int stateToSet =
1782 ((Pair<Integer, IIntegerConsumer>)
1783 request.argument).first;
1784 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1785 break;
1786 }
1787 case EVENT_SET_SIM_POWER_DONE: {
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790 IIntegerConsumer callback =
1791 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1792 if (ar.exception != null) {
1793 loge("setSimPower exception: " + ar.exception);
1794 int errorCode = TelephonyManager.CallForwardingInfoCallback
1795 .RESULT_ERROR_UNKNOWN;
1796 if (ar.exception instanceof CommandException) {
1797 CommandException.Error error =
1798 ((CommandException) (ar.exception)).getCommandError();
1799 if (error == CommandException.Error.SIM_ERR) {
1800 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1801 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1802 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1803 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1804 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1805 } else {
1806 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1807 }
1808 }
1809 try {
1810 callback.accept(errorCode);
1811 } catch (RemoteException e) {
1812 // Ignore if the remote process is no longer available to call back.
1813 Log.w(LOG_TAG, "setSimPower: callback not available.");
1814 }
1815 } else {
1816 try {
1817 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1818 } catch (RemoteException e) {
1819 // Ignore if the remote process is no longer available to call back.
1820 Log.w(LOG_TAG, "setSimPower: callback not available.");
1821 }
1822 }
1823 break;
1824 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001825 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1826 request = (MainThreadRequest) msg.obj;
1827
1828 final Phone phone = getPhoneFromRequest(request);
1829 if (phone == null || phone.getServiceStateTracker() == null) {
1830 request.result = new IllegalStateException("Phone or SST is null");
1831 notifyRequester(request);
1832 break;
1833 }
1834
1835 Pair<Integer, SignalStrengthUpdateRequest> pair =
1836 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1837 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1838 request);
1839 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1840 request.subId, pair.first /*callingUid*/,
1841 pair.second /*request*/, onCompleted);
1842 break;
1843 }
1844 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 // request.result will be the exception of ar if present, true otherwise.
1848 // Be cautious not to leave result null which will wait() forever
1849 request.result = ar.exception != null ? ar.exception : true;
1850 notifyRequester(request);
1851 break;
1852 }
1853 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1854 request = (MainThreadRequest) msg.obj;
1855
1856 Phone phone = getPhoneFromRequest(request);
1857 if (phone == null || phone.getServiceStateTracker() == null) {
1858 request.result = new IllegalStateException("Phone or SST is null");
1859 notifyRequester(request);
1860 break;
1861 }
1862
1863 Pair<Integer, SignalStrengthUpdateRequest> pair =
1864 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1865 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1866 request);
1867 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1868 request.subId, pair.first /*callingUid*/,
1869 pair.second /*request*/, onCompleted);
1870 break;
1871 }
1872 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1873 ar = (AsyncResult) msg.obj;
1874 request = (MainThreadRequest) ar.userObj;
1875 request.result = ar.exception != null ? ar.exception : true;
1876 notifyRequester(request);
1877 break;
1878 }
Jordan Liud5366d92020-11-24 14:50:34 -08001879
Michele Berionned9fbae52020-11-13 02:36:59 +00001880 case CMD_PREPARE_UNATTENDED_REBOOT:
1881 request = (MainThreadRequest) msg.obj;
1882 request.result =
1883 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1884 notifyRequester(request);
1885 break;
1886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 default:
1888 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1889 break;
1890 }
1891 }
Jake Hambye994d462014-02-03 13:10:13 -08001892
Pengquan Menga1bb6272018-09-06 09:59:22 -07001893 private void notifyRequester(MainThreadRequest request) {
1894 synchronized (request) {
1895 request.notifyAll();
1896 }
1897 }
1898
Jake Hambye994d462014-02-03 13:10:13 -08001899 private void handleNullReturnEvent(Message msg, String command) {
1900 AsyncResult ar = (AsyncResult) msg.obj;
1901 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1902 if (ar.exception == null) {
1903 request.result = true;
1904 } else {
1905 request.result = false;
1906 if (ar.exception instanceof CommandException) {
1907 loge(command + ": CommandException: " + ar.exception);
1908 } else {
1909 loge(command + ": Unknown exception");
1910 }
1911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001912 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
1916 /**
1917 * Posts the specified command to be executed on the main thread,
1918 * waits for the request to complete, and returns the result.
1919 * @see #sendRequestAsync
1920 */
1921 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001922 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1923 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001924 }
1925
1926 /**
1927 * Posts the specified command to be executed on the main thread,
1928 * waits for the request to complete, and returns the result.
1929 * @see #sendRequestAsync
1930 */
1931 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1932 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001933 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001934 }
1935
1936 /**
1937 * Posts the specified command to be executed on the main thread,
1938 * waits for the request to complete, and returns the result.
1939 * @see #sendRequestAsync
1940 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001941 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001942 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1943 }
1944
1945 /**
1946 * Posts the specified command to be executed on the main thread,
1947 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1948 * if not timeout or null otherwise.
1949 * @see #sendRequestAsync
1950 */
1951 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1952 long timeoutInMs) {
1953 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001954 }
1955
1956 /**
1957 * Posts the specified command to be executed on the main thread,
1958 * waits for the request to complete, and returns the result.
1959 * @see #sendRequestAsync
1960 */
Nathan Harold92bed182018-10-12 18:16:49 -07001961 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001962 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001963 }
1964
1965 /**
1966 * Posts the specified command to be executed on the main thread,
1967 * waits for the request to complete, and returns the result.
1968 * @see #sendRequestAsync
1969 */
1970 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001971 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1972 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001973 }
1974
1975 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001976 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1977 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1978 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001979 * @see #sendRequestAsync
1980 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001981 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1982 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1984 throw new RuntimeException("This method will deadlock if called from the main thread.");
1985 }
1986
Nathan Harold92bed182018-10-12 18:16:49 -07001987 MainThreadRequest request = null;
1988 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1989 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1990 } else if (phone != null) {
1991 request = new MainThreadRequest(argument, phone, workSource);
1992 } else {
1993 request = new MainThreadRequest(argument, subId, workSource);
1994 }
1995
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 Message msg = mMainThreadHandler.obtainMessage(command, request);
1997 msg.sendToTarget();
1998
Rambo Wang0f050d82021-02-12 11:43:36 -08001999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002001 if (timeoutInMs >= 0) {
2002 // Wait for at least timeoutInMs before returning null request result
2003 long now = SystemClock.elapsedRealtime();
2004 long deadline = now + timeoutInMs;
2005 while (request == null && now < deadline) {
2006 try {
2007 request.wait(deadline - now);
2008 } catch (InterruptedException e) {
2009 // Do nothing, go back and check if request is completed or timeout
2010 } finally {
2011 now = SystemClock.elapsedRealtime();
2012 }
2013 }
2014 } else {
2015 // Wait for the request to complete
2016 while (request.result == null) {
2017 try {
2018 request.wait();
2019 } catch (InterruptedException e) {
2020 // Do nothing, go back and wait until the request is complete
2021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 }
2023 }
2024 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002025 if (request.result == null) {
2026 Log.wtf(LOG_TAG,
2027 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 return request.result;
2030 }
2031
2032 /**
2033 * Asynchronous ("fire and forget") version of sendRequest():
2034 * Posts the specified command to be executed on the main thread, and
2035 * returns immediately.
2036 * @see #sendRequest
2037 */
2038 private void sendRequestAsync(int command) {
2039 mMainThreadHandler.sendEmptyMessage(command);
2040 }
2041
2042 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002043 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002044 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002045 */
2046 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002047 sendRequestAsync(command, argument, null, null);
2048 }
2049
2050 /**
2051 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2052 * @see {@link #sendRequest(int,Object)}
2053 */
2054 private void sendRequestAsync(
2055 int command, Object argument, Phone phone, WorkSource workSource) {
2056 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002057 Message msg = mMainThreadHandler.obtainMessage(command, request);
2058 msg.sendToTarget();
2059 }
2060
2061 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 * Initialize the singleton PhoneInterfaceManager instance.
2063 * This is only done once, at startup, from PhoneApp.onCreate().
2064 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002065 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 synchronized (PhoneInterfaceManager.class) {
2067 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002068 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 } else {
2070 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2071 }
2072 return sInstance;
2073 }
2074 }
2075
2076 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002077 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002080 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002081 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2083 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002084 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002085 mTelephonySharedPreferences =
2086 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002087 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002088 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002089 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002090
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 publish();
2092 }
2093
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002094 private Phone getDefaultPhone() {
2095 Phone thePhone = getPhone(getDefaultSubscription());
2096 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2097 }
2098
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 private void publish() {
2100 if (DBG) log("publish: " + this);
2101
Peter Wangc035ce42020-01-08 21:00:22 -08002102 TelephonyFrameworkInitializer
2103 .getTelephonyServiceManager()
2104 .getTelephonyServiceRegisterer()
2105 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 }
2107
Stuart Scott584921c2015-01-15 17:10:34 -08002108 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002109 if (request.phone != null) {
2110 return request.phone;
2111 } else {
2112 return getPhoneFromSubId(request.subId);
2113 }
2114 }
2115
2116 private Phone getPhoneFromSubId(int subId) {
2117 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2118 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002119 }
2120
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002121 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2122 Phone phone = getPhoneFromRequest(request);
2123 return phone == null ? null :
2124 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2125 }
2126
Wink Saville36469e72014-06-11 15:17:00 -07002127 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002128 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002129 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002132 private void sendEraseModemConfig(Phone phone) {
2133 if (phone != null) {
2134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2135 mApp, phone.getSubId(), "eraseModemConfig");
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2139 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
2143 }
2144 }
2145
Peter Wang050bb052020-01-13 23:33:09 -08002146 private boolean isImsAvailableOnDevice() {
2147 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2148 if (pm == null) {
2149 // For some reason package manger is not available.. This will fail internally anyway,
2150 // so do not throw error and allow.
2151 return true;
2152 }
2153 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2154 }
2155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002157 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002158 }
2159
Wink Savilleb564aae2014-10-23 10:18:09 -07002160 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 if (DBG) log("dial: " + number);
2162 // No permission check needed here: This is just a wrapper around the
2163 // ACTION_DIAL intent, which is available to any app since it puts up
2164 // the UI before it does anything.
2165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166 final long identity = Binder.clearCallingIdentity();
2167 try {
2168 String url = createTelUrl(number);
2169 if (url == null) {
2170 return;
2171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173 // PENDING: should we just silently fail if phone is offhook or ringing?
2174 PhoneConstants.State state = mCM.getState(subId);
2175 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2176 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2177 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2178 mApp.startActivity(intent);
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183 }
2184
2185 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002186 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002187 }
2188
Wink Savilleb564aae2014-10-23 10:18:09 -07002189 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 if (DBG) log("call: " + number);
2191
2192 // This is just a wrapper around the ACTION_CALL intent, but we still
2193 // need to do a permission check since we're calling startActivity()
2194 // from the context of the phone app.
2195 enforceCallPermission();
2196
Jordan Liu1617b712019-07-10 15:06:26 -07002197 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 != AppOpsManager.MODE_ALLOWED) {
2199 return;
2200 }
2201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 String url = createTelUrl(number);
2205 if (url == null) {
2206 return;
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 boolean isValid = false;
2210 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2211 if (slist != null) {
2212 for (SubscriptionInfo subInfoRecord : slist) {
2213 if (subInfoRecord.getSubscriptionId() == subId) {
2214 isValid = true;
2215 break;
2216 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002217 }
Wink Saville08874612014-08-31 19:19:58 -07002218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 if (!isValid) {
2220 return;
2221 }
Wink Saville08874612014-08-31 19:19:58 -07002222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2224 intent.putExtra(SUBSCRIPTION_KEY, subId);
2225 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2226 mApp.startActivity(intent);
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
Wink Savilleb564aae2014-10-23 10:18:09 -07002232 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002233 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002234 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2235 }
2236
Wink Savilleb564aae2014-10-23 10:18:09 -07002237 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002238 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002239 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2240 }
2241
Wink Savilleb564aae2014-10-23 10:18:09 -07002242 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244
2245 final long identity = Binder.clearCallingIdentity();
2246 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002247 Phone phone = getPhone(subId);
2248 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 checkSimPin.start();
2250 return checkSimPin.unlockSim(null, pin);
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
2253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 }
2255
Wink Savilleb564aae2014-10-23 10:18:09 -07002256 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258
2259 final long identity = Binder.clearCallingIdentity();
2260 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002261 Phone phone = getPhone(subId);
2262 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 checkSimPuk.start();
2264 return checkSimPuk.unlockSim(puk, pin);
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
2270 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002271 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 * a synchronous one.
2273 */
2274 private static class UnlockSim extends Thread {
2275
2276 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002277 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278
2279 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002280 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2281 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282
2283 // For replies from SimCard interface
2284 private Handler mHandler;
2285
2286 // For async handler to identify request type
2287 private static final int SUPPLY_PIN_COMPLETE = 100;
2288
Michele Berionned9fbae52020-11-13 02:36:59 +00002289 UnlockSim(int phoneId, IccCard simCard) {
2290 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 mSimCard = simCard;
2292 }
2293
2294 @Override
2295 public void run() {
2296 Looper.prepare();
2297 synchronized (UnlockSim.this) {
2298 mHandler = new Handler() {
2299 @Override
2300 public void handleMessage(Message msg) {
2301 AsyncResult ar = (AsyncResult) msg.obj;
2302 switch (msg.what) {
2303 case SUPPLY_PIN_COMPLETE:
2304 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2305 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002306 mRetryCount = msg.arg1;
2307 if (ar.exception != null) {
2308 if (ar.exception instanceof CommandException &&
2309 ((CommandException)(ar.exception)).getCommandError()
2310 == CommandException.Error.PASSWORD_INCORRECT) {
2311 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002312 } //When UiccCardApp dispose,handle message and return exception
2313 else if (ar.exception instanceof CommandException &&
2314 ((CommandException) (ar.exception)).getCommandError()
2315 == CommandException.Error.ABORTED) {
2316 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002317 } else {
2318 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2319 }
2320 } else {
2321 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 mDone = true;
2324 UnlockSim.this.notifyAll();
2325 }
2326 break;
2327 }
2328 }
2329 };
2330 UnlockSim.this.notifyAll();
2331 }
2332 Looper.loop();
2333 }
2334
2335 /*
2336 * Use PIN or PUK to unlock SIM card
2337 *
2338 * If PUK is null, unlock SIM card with PIN
2339 *
2340 * If PUK is not null, unlock SIM card with PUK and set PIN code
2341 */
Wink Saville9de0f752013-10-22 19:04:03 -07002342 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343
2344 while (mHandler == null) {
2345 try {
2346 wait();
2347 } catch (InterruptedException e) {
2348 Thread.currentThread().interrupt();
2349 }
2350 }
2351 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2352
2353 if (puk == null) {
2354 mSimCard.supplyPin(pin, callback);
2355 } else {
2356 mSimCard.supplyPuk(puk, pin, callback);
2357 }
2358
2359 while (!mDone) {
2360 try {
2361 Log.d(LOG_TAG, "wait for done");
2362 wait();
2363 } catch (InterruptedException e) {
2364 // Restore the interrupted status
2365 Thread.currentThread().interrupt();
2366 }
2367 }
2368 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002369 int[] resultArray = new int[2];
2370 resultArray[0] = mResult;
2371 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002372
2373 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2374 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2375 }
2376
Wink Saville9de0f752013-10-22 19:04:03 -07002377 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379 }
2380
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002381 /**
2382 * This method has been removed due to privacy and stability concerns.
2383 */
2384 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002386 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2387 return;
Wink Saville36469e72014-06-11 15:17:00 -07002388 }
2389
Nathan Harold1f889d82020-06-04 17:05:26 -07002390 @Override
2391 public void updateServiceLocationWithPackageName(String callingPackage) {
2392 mApp.getSystemService(AppOpsManager.class)
2393 .checkPackage(Binder.getCallingUid(), callingPackage);
2394
Nathan Haroldf096d982020-11-18 17:18:06 -08002395 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002396 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2397 // Callers targeting S have no business invoking this method.
2398 return;
2399 }
2400
2401 LocationAccessPolicy.LocationPermissionResult locationResult =
2402 LocationAccessPolicy.checkLocationPermission(mApp,
2403 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2404 .setCallingPackage(callingPackage)
2405 .setCallingFeatureId(null)
2406 .setCallingPid(Binder.getCallingPid())
2407 .setCallingUid(Binder.getCallingUid())
2408 .setMethod("updateServiceLocation")
2409 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2410 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2411 .build());
2412 // Apps that lack location permission have no business calling this method;
2413 // however, because no permission was declared in the public API, denials must
2414 // all be "soft".
2415 switch (locationResult) {
2416 case DENIED_HARD: /* fall through */
2417 case DENIED_SOFT:
2418 return;
2419 }
2420
2421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002424 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002426 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 }
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002433 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002434 @Override
2435 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002436 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002439
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2442 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2443 callingFeatureId);
2444 }
2445
2446 @Deprecated
2447 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002448 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2450 }
2451
2452 @Override
2453 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2454 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002456 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002457 return false;
2458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459
2460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 return isRadioOnForSubscriber(subId);
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
2465 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002466 }
2467
2468 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 final Phone phone = getPhone(subId);
2472 if (phone != null) {
2473 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2474 } else {
2475 return false;
2476 }
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481
2482 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002483 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
Wink Saville36469e72014-06-11 15:17:00 -07002485
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 if (phone != null) {
2493 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2494 }
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 }
Wink Saville36469e72014-06-11 15:17:00 -07002498 }
2499
2500 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002501 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
Wink Savilleb564aae2014-10-23 10:18:09 -07002504 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506
2507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 final Phone phone = getPhone(subId);
2510 if (phone == null) {
2511 return false;
2512 }
2513 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2514 toggleRadioOnOffForSubscriber(subId);
2515 }
2516 return true;
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
Wink Saville36469e72014-06-11 15:17:00 -07002521
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002522 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002523 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002524 /*
2525 * If any of the Radios are available, it will need to be
2526 * shutdown. So return true if any Radio is available.
2527 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2531 Phone phone = PhoneFactory.getPhone(i);
2532 if (phone != null && phone.isRadioAvailable()) return true;
2533 }
2534 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2535 return false;
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002538 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002539 }
2540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002542 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 enforceModifyPermission();
2544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2548 logv("Shutting down Phone " + i);
2549 shutdownRadioUsingPhoneId(i);
2550 }
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002553 }
2554 }
2555
2556 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002557 Phone phone = PhoneFactory.getPhone(phoneId);
2558 if (phone != null && phone.isRadioAvailable()) {
2559 phone.shutdownRadio();
2560 }
2561 }
2562
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002564 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2569 if (defaultPhone != null) {
2570 defaultPhone.setRadioPower(turnOn);
2571 return true;
2572 } else {
2573 loge("There's no default phone.");
2574 return false;
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002578 }
Wink Saville36469e72014-06-11 15:17:00 -07002579 }
2580
Wink Savilleb564aae2014-10-23 10:18:09 -07002581 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 phone.setRadioPower(turnOn);
2589 return true;
2590 } else {
2591 return false;
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 }
2597
Wink Saville36469e72014-06-11 15:17:00 -07002598 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002599 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 public boolean enableDataConnectivity() {
2601 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602
2603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 int subId = mSubscriptionController.getDefaultDataSubId();
2606 final Phone phone = getPhone(subId);
2607 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002608 phone.getDataEnabledSettings().setDataEnabled(
2609 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 return true;
2611 } else {
2612 return false;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 }
2618
Wink Saville36469e72014-06-11 15:17:00 -07002619 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002620 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 public boolean disableDataConnectivity() {
2622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 int subId = mSubscriptionController.getDefaultDataSubId();
2627 final Phone phone = getPhone(subId);
2628 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002629 phone.getDataEnabledSettings().setDataEnabled(
2630 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 return true;
2632 } else {
2633 return false;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 }
2639
Sanket Padawe356d7632015-06-22 14:03:32 -07002640 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002641 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002646 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 } else {
2648 return false;
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
2655 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002656 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002657 }
2658
pkanwarae03a6b2016-11-06 20:37:09 -08002659 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 enforceCallPermission();
2661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2665 return;
2666 }
2667 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2668 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
pkanwar32d516d2016-10-14 19:37:38 -07002672 };
2673
Wink Savilleb564aae2014-10-23 10:18:09 -07002674 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676
2677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2680 return false;
2681 }
2682 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
2687
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002689 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002690 }
2691
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002692 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 Phone phone = PhoneFactory.getPhone(slotIndex);
2696 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2697 PhoneConstantConversions.convertCallState(phone.getState());
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
Sanket Padawe356d7632015-06-22 14:03:32 -07002703 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002704 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002705 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2706 }
2707
2708 @Override
2709 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 final long identity = Binder.clearCallingIdentity();
2711 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002712 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 if (phone != null) {
2714 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2715 } else {
2716 return PhoneConstantConversions.convertDataState(
2717 PhoneConstants.DataState.DISCONNECTED);
2718 }
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002725 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002726 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2727 }
2728
2729 @Override
2730 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002733 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 if (phone != null) {
2735 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2736 } else {
2737 return TelephonyManager.DATA_ACTIVITY_NONE;
2738 }
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 }
2743
2744 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002745 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002746 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002747 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002748
2749 LocationAccessPolicy.LocationPermissionResult locationResult =
2750 LocationAccessPolicy.checkLocationPermission(mApp,
2751 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2752 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002753 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002754 .setCallingPid(Binder.getCallingPid())
2755 .setCallingUid(Binder.getCallingUid())
2756 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002757 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002758 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2759 .build());
2760 switch (locationResult) {
2761 case DENIED_HARD:
2762 throw new SecurityException("Not allowed to access cell location");
2763 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002764 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2765 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 }
2767
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002768 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002772 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002773 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Svetoslav64fad262015-04-14 14:35:21 -07002777 }
2778
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 @Override
Jack Yu01425032020-02-22 19:38:58 -08002780 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002781 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2782 // registered cell info, so return a NULL country instead.
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002785 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2786 // Get default phone in this case.
2787 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2788 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002789 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002791 if (phone == null) return "";
2792 ServiceStateTracker sst = phone.getServiceStateTracker();
2793 if (sst == null) return "";
2794 LocaleTracker lt = sst.getLocaleTracker();
2795 if (lt == null) return "";
2796 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2797 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2798 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 }
2803
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002804 /**
2805 * This method was removed due to potential issues caused by performing partial
2806 * updates of service state, and lack of a credible use case.
2807 *
2808 * This has the ability to break the telephony implementation by disabling notification of
2809 * changes in device connectivity. DO NOT USE THIS!
2810 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002811 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 public void enableLocationUpdates() {
2813 mApp.enforceCallingOrSelfPermission(
2814 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002817 /**
2818 * This method was removed due to potential issues caused by performing partial
2819 * updates of service state, and lack of a credible use case.
2820 *
2821 * This has the ability to break the telephony implementation by disabling notification of
2822 * changes in device connectivity. DO NOT USE THIS!
2823 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 @Override
2825 public void disableLocationUpdates() {
2826 mApp.enforceCallingOrSelfPermission(
2827 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 @Override
2831 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002832 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2833 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002834 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002835 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2836 throw new SecurityException(
2837 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2838 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002839
Jordan Liu1617b712019-07-10 15:06:26 -07002840 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2842 return null;
2843 }
Svetoslav64fad262015-04-14 14:35:21 -07002844
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002845 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002847 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002848 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849
Nathan Haroldf180aac2018-06-01 18:43:55 -07002850 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2851 for (CellInfo ci : info) {
2852 if (ci instanceof CellInfoGsm) {
2853 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2854 } else if (ci instanceof CellInfoWcdma) {
2855 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002858 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002861 private List<CellInfo> getCachedCellInfo() {
2862 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2863 for (Phone phone : PhoneFactory.getPhones()) {
2864 List<CellInfo> info = phone.getAllCellInfo();
2865 if (info != null) cellInfos.addAll(info);
2866 }
2867 return cellInfos;
2868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869
2870 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002871 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002873 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002874
2875 LocationAccessPolicy.LocationPermissionResult locationResult =
2876 LocationAccessPolicy.checkLocationPermission(mApp,
2877 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2878 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002879 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002880 .setCallingPid(Binder.getCallingPid())
2881 .setCallingUid(Binder.getCallingUid())
2882 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002883 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002884 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2885 .build());
2886 switch (locationResult) {
2887 case DENIED_HARD:
2888 throw new SecurityException("Not allowed to access cell info");
2889 case DENIED_SOFT:
2890 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
Nathan Haroldf096d982020-11-18 17:18:06 -08002893 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002894 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2895 return getCachedCellInfo();
2896 }
2897
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002898 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2903 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002904 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002905 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 if (info != null) cellInfos.addAll(info);
2907 }
2908 return cellInfos;
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912 }
2913
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002914 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002915 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2916 String callingFeatureId) {
2917 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2918 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002919 }
2920
2921 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002922 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2923 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002924 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002926 }
2927
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002928 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2929 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002930 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002931 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002932
2933 LocationAccessPolicy.LocationPermissionResult locationResult =
2934 LocationAccessPolicy.checkLocationPermission(mApp,
2935 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2936 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002937 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002938 .setCallingPid(Binder.getCallingPid())
2939 .setCallingUid(Binder.getCallingUid())
2940 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002941 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2942 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002943 .build());
2944 switch (locationResult) {
2945 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002946 if (TelephonyPermissions
2947 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002948 // Safetynet logging for b/154934934
2949 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2950 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002951 throw new SecurityException("Not allowed to access cell info");
2952 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002953 if (TelephonyPermissions
2954 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002955 // Safetynet logging for b/154934934
2956 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2957 }
Nathan Harold5320c422019-05-09 10:26:08 -07002958 try {
2959 cb.onCellInfo(new ArrayList<CellInfo>());
2960 } catch (RemoteException re) {
2961 // Drop without consequences
2962 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002963 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002964 }
2965
Nathan Harolda939a962019-05-09 10:13:47 -07002966
2967 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002968 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2969
2970 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2971 }
2972
2973 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002975 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002980 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 }
2985
Shishir Agrawala9f32182016-04-12 12:00:16 -07002986 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002987 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002988 Phone phone = PhoneFactory.getPhone(slotIndex);
2989 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002990 return null;
2991 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002992 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002993 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002994 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002995 return null;
2996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997
2998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 return phone.getImei();
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003004 }
3005
3006 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003007 public String getTypeAllocationCodeForSlot(int slotIndex) {
3008 Phone phone = PhoneFactory.getPhone(slotIndex);
3009 String tac = null;
3010 if (phone != null) {
3011 String imei = phone.getImei();
3012 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3013 }
3014 return tac;
3015 }
3016
3017 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003018 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003019 Phone phone = PhoneFactory.getPhone(slotIndex);
3020 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003021 return null;
3022 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003025 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003026 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 return null;
3028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 return phone.getMeid();
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
Jack Yu2af8d712017-03-15 17:14:14 -07003036 }
3037
3038 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003039 public String getManufacturerCodeForSlot(int slotIndex) {
3040 Phone phone = PhoneFactory.getPhone(slotIndex);
3041 String manufacturerCode = null;
3042 if (phone != null) {
3043 String meid = phone.getMeid();
3044 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3045 }
3046 return manufacturerCode;
3047 }
3048
3049 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003050 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3051 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003052 Phone phone = PhoneFactory.getPhone(slotIndex);
3053 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003054 return null;
3055 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003056 int subId = phone.getSubId();
3057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003058 mApp, subId, callingPackage, callingFeatureId,
3059 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003060 return null;
3061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 return phone.getDeviceSvn();
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003069 }
3070
fionaxu43304da2017-11-27 22:51:16 -08003071 @Override
3072 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 final Phone phone = getPhone(subId);
3076 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
fionaxu43304da2017-11-27 22:51:16 -08003080 }
3081
3082 @Override
3083 public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName();
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
fionaxu43304da2017-11-27 22:51:16 -08003091 }
3092
calvinpanffe225e2018-11-01 19:43:06 +08003093 @Override
chen xu0026ca62019-03-06 15:28:50 -08003094 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 final Phone phone = getPhone(subId);
3098 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003099 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
3103 }
3104
3105 @Override
chen xu0026ca62019-03-06 15:28:50 -08003106 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003110 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
chen xu651eec72018-11-11 19:03:44 -08003116 @Override
chen xu864e11c2018-12-06 22:10:03 -08003117 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3118 if (!isSubscriptionMccMnc) {
3119 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3120 }
chen xu651eec72018-11-11 19:03:44 -08003121 final Phone phone = PhoneFactory.getPhone(slotIndex);
3122 if (phone == null) {
3123 return TelephonyManager.UNKNOWN_CARRIER_ID;
3124 }
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003133 //
3134 // Internal helper methods.
3135 //
3136
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003137 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3139 *
3140 * @throws SecurityException if the caller does not have the required permission
3141 */
3142 private void enforceModifyPermission() {
3143 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3144 }
3145
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003146 /**
3147 * Make sure the caller is system.
3148 *
3149 * @throws SecurityException if the caller is not system.
3150 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003151 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003152 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3153 throw new SecurityException("Caller must be system");
3154 }
3155 }
3156
Shuo Qianf2b2df42019-11-13 17:43:31 -08003157 private void enforceActiveEmergencySessionPermission() {
3158 mApp.enforceCallingOrSelfPermission(
3159 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3160 }
3161
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 /**
3163 * Make sure the caller has the CALL_PHONE permission.
3164 *
3165 * @throws SecurityException if the caller does not have the required permission
3166 */
3167 private void enforceCallPermission() {
3168 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3169 }
3170
paulhu423b5f22019-08-23 19:17:33 +08003171 private void enforceSettingsPermission() {
3172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003173 }
3174
Michele Berionned9fbae52020-11-13 02:36:59 +00003175 private void enforceRebootPermission() {
3176 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3177 }
3178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003179 private String createTelUrl(String number) {
3180 if (TextUtils.isEmpty(number)) {
3181 return null;
3182 }
3183
Jake Hambye994d462014-02-03 13:10:13 -08003184 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 }
3186
Ihab Awadf9e92732013-12-05 18:02:52 -08003187 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3189 }
3190
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003191 private static void logv(String msg) {
3192 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3193 }
3194
Ihab Awadf9e92732013-12-05 18:02:52 -08003195 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3197 }
3198
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003199 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003201 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003202 }
3203
Sanket Padawe356d7632015-06-22 14:03:32 -07003204 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003205 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 final Phone phone = PhoneFactory.getPhone(slotIndex);
3209 if (phone == null) {
3210 return PhoneConstants.PHONE_TYPE_NONE;
3211 } else {
3212 return phone.getPhoneType();
3213 }
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 }
3218
3219 /**
3220 * Returns the CDMA ERI icon index to display
3221 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003222 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003223 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3224 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3225 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003226 }
3227
Sanket Padawe356d7632015-06-22 14:03:32 -07003228 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003229 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3230 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003232 mApp, subId, callingPackage, callingFeatureId,
3233 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003234 return -1;
3235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 final Phone phone = getPhone(subId);
3240 if (phone != null) {
3241 return phone.getCdmaEriIconIndex();
3242 } else {
3243 return -1;
3244 }
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
3249
3250 /**
3251 * Returns the CDMA ERI icon mode,
3252 * 0 - ON
3253 * 1 - FLASHING
3254 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003255 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003256 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3257 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3258 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003259 }
3260
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003262 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3263 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003265 mApp, subId, callingPackage, callingFeatureId,
3266 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003267 return -1;
3268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269
3270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 final Phone phone = getPhone(subId);
3273 if (phone != null) {
3274 return phone.getCdmaEriIconMode();
3275 } else {
3276 return -1;
3277 }
3278 } finally {
3279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003281 }
3282
3283 /**
3284 * Returns the CDMA ERI text,
3285 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003286 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003287 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3288 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3289 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003290 }
3291
Sanket Padawe356d7632015-06-22 14:03:32 -07003292 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003293 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3294 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003296 mApp, subId, callingPackage, callingFeatureId,
3297 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003298 return null;
3299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300
3301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 final Phone phone = getPhone(subId);
3304 if (phone != null) {
3305 return phone.getCdmaEriText();
3306 } else {
3307 return null;
3308 }
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312 }
3313
3314 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003315 * Returns the CDMA MDN.
3316 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003317 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003318 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3320 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003325 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 return phone.getLine1Number();
3327 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 return null;
3330 }
3331 } finally {
3332 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003333 }
3334 }
3335
3336 /**
3337 * Returns the CDMA MIN.
3338 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003339 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003340 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3342 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 final Phone phone = getPhone(subId);
3347 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3348 return phone.getCdmaMin();
3349 } else {
3350 return null;
3351 }
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003354 }
3355 }
3356
Hall Liud892bec2018-11-30 14:51:45 -08003357 @Override
3358 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3359 INumberVerificationCallback callback, String callingPackage) {
3360 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3361 != PERMISSION_GRANTED) {
3362 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3363 }
3364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3365
3366 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3367 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003368 throw new SecurityException("Calling package must be configured in the device config: "
3369 + "calling package: " + callingPackage
3370 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003371 }
3372
3373 if (range == null) {
3374 throw new NullPointerException("Range must be non-null");
3375 }
3376
3377 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003378 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003379
3380 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3381 }
3382
Junda Liuca05d5d2014-08-14 22:36:34 -07003383 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 * Returns true if CDMA provisioning needs to run.
3385 */
3386 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 final long identity = Binder.clearCallingIdentity();
3388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 }
3394
3395 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003396 * Sets the voice mail number of a given subId.
3397 */
3398 @Override
3399 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003400 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3401 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3406 new Pair<String, String>(alphaTag, number), new Integer(subId));
3407 return success;
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003411 }
3412
Ta-wei Yen87c49842016-05-13 21:19:52 -07003413 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003414 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003416 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3417 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003418 if (!TextUtils.equals(callingPackage, systemDialer)) {
3419 throw new SecurityException("caller must be system dialer");
3420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3425 if (phoneAccountHandle == null) {
3426 return null;
3427 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003431 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003432 }
3433
3434 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003435 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3436 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003437 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003439 mApp, subId, callingPackage, callingFeatureId,
3440 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003441 return null;
3442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003444 final long identity = Binder.clearCallingIdentity();
3445 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003446 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003450 }
3451
3452 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003453 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3454 VisualVoicemailSmsFilterSettings settings) {
3455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003464 }
3465
3466 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003467 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003473 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474 } finally {
3475 Binder.restoreCallingIdentity(identity);
3476 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003477 }
3478
3479 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003480 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3481 String callingPackage, int subId) {
3482 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003487 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003491 }
3492
3493 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003494 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003500 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501 } finally {
3502 Binder.restoreCallingIdentity(identity);
3503 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003504 }
3505
3506 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003507 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3508 String callingAttributionTag, int subId, String number, int port, String text,
3509 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003511 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003512 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003513 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003514 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3515 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003516 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003517
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003518 /**
fionaxu0152e512016-11-14 13:36:14 -08003519 * Sets the voice activation state of a given subId.
3520 */
3521 @Override
3522 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3524 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 final Phone phone = getPhone(subId);
3529 if (phone != null) {
3530 phone.setVoiceActivationState(activationState);
3531 } else {
3532 loge("setVoiceActivationState fails with invalid subId: " + subId);
3533 }
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003536 }
3537 }
3538
3539 /**
3540 * Sets the data activation state of a given subId.
3541 */
3542 @Override
3543 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3545 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone != null) {
3551 phone.setDataActivationState(activationState);
3552 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003553 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003557 }
3558 }
3559
3560 /**
3561 * Returns the voice activation state of a given subId.
3562 */
3563 @Override
3564 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566
fionaxu0152e512016-11-14 13:36:14 -08003567 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 if (phone != null) {
3571 return phone.getVoiceActivationState();
3572 } else {
3573 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003577 }
3578 }
3579
3580 /**
3581 * Returns the data activation state of a given subId.
3582 */
3583 @Override
3584 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586
fionaxu0152e512016-11-14 13:36:14 -08003587 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 if (phone != null) {
3591 return phone.getDataActivationState();
3592 } else {
3593 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003597 }
3598 }
3599
3600 /**
Wink Saville36469e72014-06-11 15:17:00 -07003601 * Returns the unread count of voicemails for a subId
3602 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003603 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003604 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3605 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003607 mApp, subId, callingPackage, callingFeatureId,
3608 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003609 return 0;
3610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 final Phone phone = getPhone(subId);
3614 if (phone != null) {
3615 return phone.getVoiceMessageCount();
3616 } else {
3617 return 0;
3618 }
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003622 }
3623
3624 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003625 * returns true, if the device is in a state where both voice and data
3626 * are supported simultaneously. This can change based on location or network condition.
3627 */
3628 @Override
3629 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003637 }
3638
3639 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003640 * Send the dialer code if called from the current default dialer or the caller has
3641 * carrier privilege.
3642 * @param inputCode The dialer code to send
3643 */
3644 @Override
3645 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003646 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003648 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3649 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003650 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003651 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003652 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
fionaxu235cc5e2017-03-06 22:25:57 -08003661 }
3662
Pengquan Menga1bb6272018-09-06 09:59:22 -07003663 @Override
3664 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003665 TelephonyPermissions
3666 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3667 mApp, subId, "getNetworkSelectionMode");
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 if (!isActiveSubscription(subId)) {
3671 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3672 }
3673 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003677 }
3678
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003680 public boolean isInEmergencySmsMode() {
3681 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 for (Phone phone : PhoneFactory.getPhones()) {
3685 if (phone.isInEmergencySmsMode()) {
3686 return true;
3687 }
3688 }
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
3692 return false;
3693 }
3694
shilu366312e2019-12-17 09:28:10 -08003695 /**
3696 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3697 * @param subId The subscription to use to check the configuration.
3698 * @param c The callback that will be used to send the result.
3699 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003700 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003701 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3702 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003703 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3704 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003705
Brad Ebinger77b832e2019-10-17 17:03:22 -07003706 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3707 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3708 "IMS not available on device.");
3709 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 final long token = Binder.clearCallingIdentity();
3711 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003712 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003715 } catch (ImsException e) {
3716 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 } finally {
3718 Binder.restoreCallingIdentity(token);
3719 }
3720 }
3721
shilu366312e2019-12-17 09:28:10 -08003722 /**
3723 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3724 * @param subId The subscription to use to check the configuration.
3725 * @param c The callback that will be used to send the result.
3726 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003728 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003729 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3730 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003731 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3732 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3733 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003734 final long token = Binder.clearCallingIdentity();
3735 try {
3736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3737 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3738 .removeRegistrationCallbackForSubscription(c, subId);
3739 } catch (ImsException e) {
3740 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3741 + "is inactive, ignoring unregister.");
3742 // If the subscription is no longer active, just return, since the callback
3743 // will already have been removed internally.
3744 } finally {
3745 Binder.restoreCallingIdentity(token);
3746 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 }
3748
Brad Ebinger774ba362019-10-22 17:36:18 -07003749 /**
3750 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3751 */
3752 @Override
3753 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3754 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3755 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3757 "IMS not available on device.");
3758 }
3759 final long token = Binder.clearCallingIdentity();
3760 try {
3761 Phone phone = getPhone(subId);
3762 if (phone == null) {
3763 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3764 + subId + "'");
3765 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3766 }
3767 phone.getImsRegistrationState(regState -> {
3768 try {
3769 consumer.accept((regState == null)
3770 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3771 } catch (RemoteException e) {
3772 // Ignore if the remote process is no longer available to call back.
3773 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3774 }
3775 });
3776 } finally {
3777 Binder.restoreCallingIdentity(token);
3778 }
3779 }
3780
3781 /**
3782 * Get the transport type for the IMS service registration state.
3783 */
3784 @Override
3785 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003786 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3787 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003788 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3790 "IMS not available on device.");
3791 }
3792 final long token = Binder.clearCallingIdentity();
3793 try {
3794 Phone phone = getPhone(subId);
3795 if (phone == null) {
3796 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3797 + subId + "'");
3798 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3799 }
3800 phone.getImsRegistrationTech(regTech -> {
3801 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3802 int regTechConverted = (regTech == null)
3803 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3804 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3805 regTechConverted);
3806 try {
3807 consumer.accept(regTechConverted);
3808 } catch (RemoteException e) {
3809 // Ignore if the remote process is no longer available to call back.
3810 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3811 }
3812 });
3813 } finally {
3814 Binder.restoreCallingIdentity(token);
3815 }
3816 }
3817
shilu366312e2019-12-17 09:28:10 -08003818 /**
3819 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3820 * @param subId The subscription to use to check the configuration.
3821 * @param c The callback that will be used to send the result.
3822 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003824 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3825 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003826 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3827 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003828 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3830 "IMS not available on device.");
3831 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3833 final long token = Binder.clearCallingIdentity();
3834 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003835 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003837 } catch (ImsException e) {
3838 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 } finally {
3840 Binder.restoreCallingIdentity(token);
3841 }
3842 }
3843
shilu366312e2019-12-17 09:28:10 -08003844 /**
3845 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3846 * @param subId The subscription to use to check the configuration.
3847 * @param c The callback that will be used to send the result.
3848 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003850 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003851 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3852 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3854 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3855 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003856
3857 final long token = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3860 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003861 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003862 } catch (ImsException e) {
3863 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3864 + "is inactive, ignoring unregister.");
3865 // If the subscription is no longer active, just return, since the callback
3866 // will already have been removed internally.
3867 } finally {
3868 Binder.restoreCallingIdentity(token);
3869 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003870 }
3871
3872 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003873 public boolean isCapable(int subId, int capability, int regTech) {
3874 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3876 final long token = Binder.clearCallingIdentity();
3877 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003878 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003880 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3882 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003883 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003884 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3885 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 } finally {
3887 Binder.restoreCallingIdentity(token);
3888 }
3889 }
3890
3891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003892 public boolean isAvailable(int subId, int capability, int regTech) {
3893 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 final long token = Binder.clearCallingIdentity();
3895 try {
3896 Phone phone = getPhone(subId);
3897 if (phone == null) return false;
3898 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003899 } catch (com.android.ims.ImsException e) {
3900 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3901 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 } finally {
3903 Binder.restoreCallingIdentity(token);
3904 }
3905 }
3906
Brad Ebinger77b832e2019-10-17 17:03:22 -07003907 /**
3908 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3909 * subscription.
3910 * @param subId The subscription to use to check the configuration.
3911 * @param callback The callback that will be used to send the result.
3912 * @param capability The MmTelFeature capability that will be used to send the result.
3913 * @param transportType The transport type of the MmTelFeature capability.
3914 */
3915 @Override
3916 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3917 int transportType) {
3918 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3919 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3920 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3921 "IMS not available on device.");
3922 }
3923 final long token = Binder.clearCallingIdentity();
3924 try {
3925 int slotId = getSlotIndex(subId);
3926 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3927 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3928 + subId + "'");
3929 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3930 }
3931 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3932 transportType, aBoolean -> {
3933 try {
3934 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3935 } catch (RemoteException e) {
3936 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3937 + "running. Ignore");
3938 }
3939 });
3940 } finally {
3941 Binder.restoreCallingIdentity(token);
3942 }
3943 }
3944
shilu366312e2019-12-17 09:28:10 -08003945 /**
3946 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3947 * @param subId The subscription to use to check the configuration.
3948 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 @Override
3950 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003951 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3952 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003953
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3955 final long token = Binder.clearCallingIdentity();
3956 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003959 } catch (ImsException e) {
3960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 } finally {
3962 Binder.restoreCallingIdentity(token);
3963 }
3964 }
3965
3966 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003967 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003969 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003973 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003975 } catch (ImsException e) {
3976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
3980 }
3981
shilu366312e2019-12-17 09:28:10 -08003982 /**
3983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3984 * @param subId The subscription to use to check the configuration.
3985 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003987 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003988 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3989 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3994 } catch (ImsException e) {
3995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
3999 }
4000
4001 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004002 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004004 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004008 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004009 } catch (ImsException e) {
4010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
shilu366312e2019-12-17 09:28:10 -08004016 /**
4017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4018 * @param subId The subscription to use to check the configuration.
4019 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 @Override
4021 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004022 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4023 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004027 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 } catch (ImsException e) {
4030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
4034 }
4035
4036 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004037 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004039 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004043 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004044 } catch (ImsException e) {
4045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
4049 }
4050
shilu366312e2019-12-17 09:28:10 -08004051 /**
4052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4053 * @param subId The subscription to use to check the configuration.
4054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 @Override
4056 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004057 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4058 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004062 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004064 } catch (ImsException e) {
4065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
4069 }
4070
4071 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004072 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004074 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004078 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 } catch (ImsException e) {
4081 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
4085 }
4086
4087 @Override
4088 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4090 "setVoWiFiNonPersistent");
4091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004095 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
4101 }
4102
shilu366312e2019-12-17 09:28:10 -08004103 /**
4104 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4105 * @param subId The subscription to use to check the configuration.
4106 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 @Override
4108 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004109 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4110 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004116 } catch (ImsException e) {
4117 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 }
4122
4123 @Override
4124 public void setVoWiFiModeSetting(int subId, int mode) {
4125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4126 "setVoWiFiModeSetting");
4127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004130 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004132 } catch (ImsException e) {
4133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
4137 }
4138
4139 @Override
4140 public int getVoWiFiRoamingModeSetting(int subId) {
4141 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004145 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004147 } catch (ImsException e) {
4148 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
4152 }
4153
4154 @Override
4155 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4157 "setVoWiFiRoamingModeSetting");
4158 final long identity = Binder.clearCallingIdentity();
4159 try {
4160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004161 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004163 } catch (ImsException e) {
4164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
4170 @Override
4171 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4173 "setRttCapabilityEnabled");
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004177 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4178 } catch (ImsException e) {
4179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184
shilu366312e2019-12-17 09:28:10 -08004185 /**
4186 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4187 * @param subId The subscription to use to check the configuration.
4188 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 @Override
4190 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004191 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4192 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004196 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 } catch (ImsException e) {
4199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004205 @Override
4206 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4207 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4208 final long identity = Binder.clearCallingIdentity();
4209 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004210 if (!isImsAvailableOnDevice()) {
4211 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4212 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004213 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004216 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
4224 @Override
4225 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4226 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4227 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004228 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4229 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4230 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004231 try {
4232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004233 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004234 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004235 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004236 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4237 + "is inactive, ignoring unregister.");
4238 // If the subscription is no longer active, just return, since the callback will already
4239 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
4243 }
4244
allenwtsu99c623b2020-01-03 18:24:23 +08004245
4246 private void checkModifyPhoneStatePermission(int subId, String message) {
4247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4248 message);
4249 }
4250
4251 private boolean isImsProvisioningRequired(int subId, int capability,
4252 boolean isMmtelCapability) {
4253 Phone phone = getPhone(subId);
4254 if (phone == null) {
4255 loge("phone instance null for subid " + subId);
4256 return false;
4257 }
4258 if (isMmtelCapability) {
4259 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4260 return false;
4261 }
4262 } else {
4263 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4264 return false;
4265 }
4266 }
4267 return true;
4268 }
4269
4270 @Override
4271 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4272 boolean isProvisioned) {
4273 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4274
4275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4278 if (!isImsProvisioningRequired(subId, capability, false)) {
4279 return;
4280 }
4281
4282 // this capability requires provisioning, route to the correct API.
4283 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4284 switch (capability) {
4285 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4286 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4287 ims.setEabProvisioned(isProvisioned);
4288 break;
4289 default: {
4290 throw new IllegalArgumentException("Tried to set provisioning for "
4291 + "rcs capability '" + capability + "', which does not require "
4292 + "provisioning.");
4293 }
4294 }
4295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298
4299 }
4300
4301
4302 @Override
4303 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4304 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4308 if (!isImsProvisioningRequired(subId, capability, false)) {
4309 return true;
4310 }
4311
4312 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4313 switch (capability) {
4314 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4315 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4316 return ims.isEabProvisionedOnDevice();
4317
4318 default: {
4319 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4320 + "capability '" + capability + "', which does not require "
4321 + "provisioning.");
4322 }
4323 }
4324
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004330 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004331 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4332 boolean isProvisioned) {
4333 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4334 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4335 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4336 }
allenwtsu99c623b2020-01-03 18:24:23 +08004337 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004341 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004342 return;
4343 }
4344
4345 // this capability requires provisioning, route to the correct API.
4346 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4347 switch (capability) {
4348 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4349 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4350 ims.setVolteProvisioned(isProvisioned);
4351 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4352 ims.setWfcProvisioned(isProvisioned);
4353 }
4354 break;
4355 }
4356 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4357 // There is currently no difference in VT provisioning type.
4358 ims.setVtProvisioned(isProvisioned);
4359 break;
4360 }
4361 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4362 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4363 // change the capability of the feature instead if needed.
4364 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4365 == isProvisioned) {
4366 // No change in provisioning.
4367 return;
4368 }
4369 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4370 try {
4371 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004373 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4374 + ", Exception" + e.getMessage());
4375 }
4376 break;
4377 }
4378 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004379 throw new IllegalArgumentException("Tried to set provisioning for "
4380 + "MmTel capability '" + capability + "', which does not require "
4381 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004382 }
4383 }
4384
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
4388 }
4389
4390 @Override
4391 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4392 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4393 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4394 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4395 }
4396 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004400 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004401 return true;
4402 }
4403
4404 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4405 switch (capability) {
4406 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4407 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4408 return ims.isVolteProvisionedOnDevice();
4409 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4410 return ims.isWfcProvisionedOnDevice();
4411 }
4412 // This should never happen, since we are checking tech above to make sure it
4413 // is either LTE or IWLAN.
4414 throw new IllegalArgumentException("Invalid radio technology for voice "
4415 + "capability.");
4416 }
4417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4418 // There is currently no difference in VT provisioning type.
4419 return ims.isVtProvisionedOnDevice();
4420 }
4421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4422 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4423 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4424 }
4425 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004426 throw new IllegalArgumentException(
4427 "Tried to get provisioning for MmTel capability '" + capability
4428 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004429 }
4430 }
4431
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436
4437 @Override
4438 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4439 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4440 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4441 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4442 }
4443 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4444 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4445 return (provisionedBits & capability) > 0;
4446 }
4447
4448 @Override
4449 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4450 boolean isProvisioned) {
4451 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4452 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4453 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4454 }
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4456 "setProvisioningStatusForCapability");
4457 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4458 // If the current provisioning status for capability already matches isProvisioned,
4459 // do nothing.
4460 if (((provisionedBits & capability) > 0) == isProvisioned) {
4461 return;
4462 }
4463 if (isProvisioned) {
4464 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4465 } else {
4466 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4467 }
4468 }
4469
4470 /**
4471 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4472 * technology. The bitfield should mirror the bitfield defined by
4473 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4474 */
4475 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4476 String key = getMmTelProvisioningKey(subId, tech);
4477 // Default is no capabilities are provisioned.
4478 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4479 }
4480
4481 /**
4482 * Sets the MmTel capability provisioning bitfield (defined by
4483 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4484 * technology specified.
4485 *
4486 * Note: This is a synchronous command and should not be called on UI thread.
4487 */
4488 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4489 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4490 String key = getMmTelProvisioningKey(subId, tech);
4491 editor.putInt(key, newField);
4492 editor.commit();
4493 }
4494
4495 private static String getMmTelProvisioningKey(int subId, int tech) {
4496 // resulting key is provision_ims_mmtel_{subId}_{tech}
4497 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4498 }
4499
4500 /**
4501 * Query CarrierConfig to see if the specified capability requires provisioning for the
4502 * carrier associated with the subscription id.
4503 */
4504 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4505 int capability) {
4506 CarrierConfigManager configManager = new CarrierConfigManager(context);
4507 PersistableBundle c = configManager.getConfigForSubId(subId);
4508 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004509 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004510 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4511 false);
4512 boolean requireVoiceVtProvisioning = c.getBoolean(
4513 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4514
4515 // First check to make sure that the capability requires provisioning.
4516 switch (capability) {
4517 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4518 // intentional fallthrough
4519 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4520 if (requireVoiceVtProvisioning) {
4521 // Voice and Video requires provisioning
4522 return true;
4523 }
4524 break;
4525 }
4526 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4527 if (requireUtProvisioning) {
4528 // UT requires provisioning
4529 return true;
4530 }
4531 break;
4532 }
4533 }
4534 return false;
4535 }
4536
allenwtsu99c623b2020-01-03 18:24:23 +08004537 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4538 int capability) {
4539 CarrierConfigManager configManager = new CarrierConfigManager(context);
4540 PersistableBundle c = configManager.getConfigForSubId(subId);
4541
4542 boolean requireRcsProvisioning = c.getBoolean(
4543 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4544
4545 // First check to make sure that the capability requires provisioning.
4546 switch (capability) {
4547 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4548 // intentional fallthrough
4549 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4550 if (requireRcsProvisioning) {
4551 // OPTION or PRESENCE requires provisioning
4552 return true;
4553 }
4554 break;
4555 }
4556 }
4557 return false;
4558 }
4559
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004560 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004561 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4563 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4564 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004565 enforceReadPrivilegedPermission("getImsProvisioningInt");
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004569 int slotId = getSlotIndex(subId);
4570 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4571 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4572 + subId + "' for key:" + key);
4573 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4574 }
4575 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004576 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004577 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4578 + subId + "' for key:" + key);
4579 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
4583 }
4584
4585 @Override
4586 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4588 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4589 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004590 enforceReadPrivilegedPermission("getImsProvisioningString");
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004594 int slotId = getSlotIndex(subId);
4595 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4596 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4597 + subId + "' for key:" + key);
4598 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4599 }
4600 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004601 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004602 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4603 + subId + "' for key:" + key);
4604 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608 }
4609
4610 @Override
4611 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004612 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4613 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4614 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4616 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 final long identity = Binder.clearCallingIdentity();
4618 try {
4619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004620 int slotId = getSlotIndex(subId);
4621 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4622 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4623 + subId + "' for key:" + key);
4624 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4625 }
4626 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004627 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4629 + "' for key:" + key);
4630 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
4634 }
4635
4636 @Override
4637 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4639 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4640 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4642 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004643 final long identity = Binder.clearCallingIdentity();
4644 try {
4645 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 int slotId = getSlotIndex(subId);
4647 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4648 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4649 + subId + "' for key:" + key);
4650 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4651 }
4652 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004653 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4655 + "' for key:" + key);
4656 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004657 } finally {
4658 Binder.restoreCallingIdentity(identity);
4659 }
4660 }
4661
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004662 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 int slotId = SubscriptionManager.getSlotIndex(subId);
4664 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4666 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 }
4668 return slotId;
4669 }
4670
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004671 private int getSlotIndex(int subId) {
4672 int slotId = SubscriptionManager.getSlotIndex(subId);
4673 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4674 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4675 }
4676 return slotId;
4677 }
4678
Wink Saville36469e72014-06-11 15:17:00 -07004679 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004680 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004681 */
4682 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004683 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4684 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004685 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004686 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004687 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004688 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004689 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004690 mApp, subId, callingPackage, callingFeatureId,
4691 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004692 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4693 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 final Phone phone = getPhone(subId);
4698 if (phone != null) {
4699 return phone.getServiceState().getDataNetworkType();
4700 } else {
4701 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4702 }
4703 } finally {
4704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004706 }
4707
4708 /**
4709 * Returns the data network type
4710 */
4711 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004712 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4713 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4714 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004715 }
4716
4717 /**
4718 * Returns the data network type for a subId
4719 */
4720 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004721 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4722 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004724 mApp, subId, callingPackage, callingFeatureId,
4725 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004726 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4727 }
4728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 final Phone phone = getPhone(subId);
4732 if (phone != null) {
4733 return phone.getServiceState().getDataNetworkType();
4734 } else {
4735 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4736 }
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004740 }
4741
4742 /**
Wink Saville36469e72014-06-11 15:17:00 -07004743 * Returns the Voice network type for a subId
4744 */
4745 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004746 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4747 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004749 mApp, subId, callingPackage, callingFeatureId,
4750 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004751 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4752 }
4753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 final Phone phone = getPhone(subId);
4757 if (phone != null) {
4758 return phone.getServiceState().getVoiceNetworkType();
4759 } else {
4760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4761 }
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004765 }
4766
4767 /**
4768 * @return true if a ICC card is present
4769 */
4770 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004771 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004772 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4773 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004774 }
4775
4776 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004777 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004778 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004779 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004780 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 final long identity = Binder.clearCallingIdentity();
4782 try {
4783 final Phone phone = PhoneFactory.getPhone(slotIndex);
4784 if (phone != null) {
4785 return phone.getIccCard().hasIccCard();
4786 } else {
4787 return false;
4788 }
4789 } finally {
4790 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004792 }
4793
4794 /**
4795 * Return if the current radio is LTE on CDMA. This
4796 * is a tri-state return value as for a period of time
4797 * the mode may be unknown.
4798 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004799 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004800 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004801 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004802 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004803 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004804 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4805 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4806 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004807 }
4808
Sanket Padawe356d7632015-06-22 14:03:32 -07004809 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004810 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4811 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004812 try {
4813 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4814 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004815 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4816 }
4817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 final Phone phone = getPhone(subId);
4821 if (phone == null) {
4822 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4823 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004824 return TelephonyProperties.lte_on_cdma_device()
4825 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 }
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004829 }
Wink Saville36469e72014-06-11 15:17:00 -07004830 }
4831
Wink Saville36469e72014-06-11 15:17:00 -07004832 /**
4833 * {@hide}
4834 * Returns Default subId, 0 in the case of single standby.
4835 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004836 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004837 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004838 }
4839
Shishir Agrawala9f32182016-04-12 12:00:16 -07004840 private int getSlotForDefaultSubscription() {
4841 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4842 }
4843
Wink Savilleb564aae2014-10-23 10:18:09 -07004844 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004845 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004846 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004847
Pengquan Menge92a50d2018-09-21 15:54:48 -07004848 private boolean isActiveSubscription(int subId) {
4849 return mSubscriptionController.isActiveSubId(subId);
4850 }
4851
Ihab Awadf2177b72013-11-25 13:33:23 -08004852 /**
4853 * @see android.telephony.TelephonyManager.WifiCallingChoices
4854 */
4855 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 final long identity = Binder.clearCallingIdentity();
4857 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004858 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4860 getWhenToMakeWifiCallsDefaultPreference());
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004864 }
4865
4866 /**
4867 * @see android.telephony.TelephonyManager.WifiCallingChoices
4868 */
4869 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004878 }
4879
Sailesh Nepald1e68152013-12-12 19:08:02 -08004880 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004881 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004882 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004883 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004884
Jordan Liu4c733742019-02-28 12:03:40 -08004885 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4886 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4887 if (phoneId == -1) {
4888 throw new IllegalArgumentException("Given slot index: " + slotIndex
4889 + " does not correspond to an active phone");
4890 }
4891 return PhoneFactory.getPhone(phoneId);
4892 }
4893
Shishir Agrawal566b7612013-10-28 14:41:00 -07004894 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004895 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4896 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4898 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004900 if (DBG) {
4901 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4902 }
4903 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4904 p2);
4905 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004906
Jordan Liu4c733742019-02-28 12:03:40 -08004907
4908 @Override
4909 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4910 int slotIndex, String callingPackage, String aid, int p2) {
4911 enforceModifyPermission();
4912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4913 if (DBG) {
4914 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4915 }
4916 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4917 callingPackage, aid, p2);
4918 }
4919
4920 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4921 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 if (TextUtils.equals(ISDR_AID, aid)) {
4925 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004926 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4927 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 if (bestComponent == null
4929 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4930 loge("The calling package is not allowed to access ISD-R.");
4931 throw new SecurityException(
4932 "The calling package is not allowed to access ISD-R.");
4933 }
Derek Tan740e1672017-06-27 14:56:27 -07004934 }
Derek Tan740e1672017-06-27 14:56:27 -07004935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004937 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4938 null /* workSource */);
4939 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 return response;
4941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004944 }
4945
4946 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004947 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4949 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004950 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4951 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4952 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004953
Jordan Liu4c733742019-02-28 12:03:40 -08004954 @Override
4955 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4956 enforceModifyPermission();
4957 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4958 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4959 channel);
4960 }
4961
4962 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 final long identity = Binder.clearCallingIdentity();
4964 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 if (channel < 0) {
4966 return false;
4967 }
Jordan Liu4c733742019-02-28 12:03:40 -08004968 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4969 null /* workSource */);
4970 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 return success;
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004974 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004975 }
4976
4977 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004978 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004979 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4981 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004982 if (DBG) {
4983 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4984 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4985 + p3 + " data=" + data);
4986 }
4987 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4988 command, p1, p2, p3, data);
4989 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004990
Jordan Liu4c733742019-02-28 12:03:40 -08004991 @Override
4992 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4993 int command, int p1, int p2, int p3, String data) {
4994 enforceModifyPermission();
4995 if (DBG) {
4996 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4997 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4998 + p3 + " data=" + data);
4999 }
5000 return iccTransmitApduLogicalChannelWithPermission(
5001 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5002 data);
5003 }
5004
5005 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5006 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 final long identity = Binder.clearCallingIdentity();
5008 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005009 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 return "";
5011 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005014 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5015 null /* workSource */);
5016 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 // Append the returned status code to the end of the response payload.
5019 String s = Integer.toHexString(
5020 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5021 if (response.payload != null) {
5022 s = IccUtils.bytesToHexString(response.payload) + s;
5023 }
5024 return s;
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005027 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005028 }
Jake Hambye994d462014-02-03 13:10:13 -08005029
Evan Charltonc66da362014-05-16 14:06:40 -07005030 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005031 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5032 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5034 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005036 if (DBG) {
5037 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5038 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5039 }
5040 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5041 cla, command, p1, p2, p3, data);
5042 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005043
Jordan Liu4c733742019-02-28 12:03:40 -08005044 @Override
5045 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5046 int command, int p1, int p2, int p3, String data) {
5047 enforceModifyPermission();
5048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5049 if (DBG) {
5050 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5051 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5052 + " data=" + data);
5053 }
5054
5055 return iccTransmitApduBasicChannelWithPermission(
5056 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5057 p2, p3, data);
5058 }
5059
5060 // open APDU basic channel assuming the caller has sufficient permissions
5061 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5062 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5066 && TextUtils.equals(ISDR_AID, data)) {
5067 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005068 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5069 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 if (bestComponent == null
5071 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5072 loge("The calling package is not allowed to select ISD-R.");
5073 throw new SecurityException(
5074 "The calling package is not allowed to select ISD-R.");
5075 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005076 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005079 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5080 null /* workSource */);
5081 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 // Append the returned status code to the end of the response payload.
5084 String s = Integer.toHexString(
5085 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5086 if (response.payload != null) {
5087 s = IccUtils.bytesToHexString(response.payload) + s;
5088 }
5089 return s;
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005092 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093 }
5094
5095 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005096 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005097 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5099 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
5103 if (DBG) {
5104 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5105 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5106 }
5107
5108 IccIoResult response =
5109 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5110 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5111 subId);
5112
5113 if (DBG) {
5114 log("Exchange SIM_IO [R]" + response);
5115 }
5116
5117 byte[] result = null;
5118 int length = 2;
5119 if (response.payload != null) {
5120 length = 2 + response.payload.length;
5121 result = new byte[length];
5122 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5123 } else {
5124 result = new byte[length];
5125 }
5126
5127 result[length - 1] = (byte) response.sw2;
5128 result[length - 2] = (byte) response.sw1;
5129 return result;
5130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005133 }
5134
Nathan Haroldb3014052017-01-25 15:57:32 -08005135 /**
5136 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5137 * on a particular subscription
5138 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005139 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5140 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005142 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005143 return null;
5144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 if (appType != TelephonyManager.APPTYPE_USIM
5149 && appType != TelephonyManager.APPTYPE_SIM) {
5150 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5151 return null;
5152 }
5153 Object response = sendRequest(
5154 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5155 if (response instanceof String[]) {
5156 return (String[]) response;
5157 }
yincheng zhaod698b842019-09-06 17:06:54 -07005158 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005160 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005163 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005164 }
5165
yincheng zhaod698b842019-09-06 17:06:54 -07005166 /**
5167 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5168 * subscription.
5169 *
5170 * @param subId the id of the subscription.
5171 * @param appType the uicc app type, must be USIM or SIM.
5172 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5173 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005174 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005175 * @return number of fplmns that is successfully written to the SIM.
5176 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005177 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5178 String callingFeatureId) {
5179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5180 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005181 if (DBG) logv("no permissions for setForbiddenplmns");
5182 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5183 }
5184 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5185 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5186 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5187 }
5188 if (fplmns == null) {
5189 throw new IllegalArgumentException("Fplmn List provided is null");
5190 }
5191 for (String fplmn : fplmns) {
5192 if (!CellIdentity.isValidPlmn(fplmn)) {
5193 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5194 }
5195 }
5196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 Object response = sendRequest(
5199 CMD_SET_FORBIDDEN_PLMNS,
5200 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5201 subId);
5202 return (int) response;
5203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
5206 }
5207
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005208 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005209 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5211 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 final long identity = Binder.clearCallingIdentity();
5214 try {
5215 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5216 if (response.payload == null) {
5217 return "";
5218 }
Evan Charltonc66da362014-05-16 14:06:40 -07005219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 // Append the returned status code to the end of the response payload.
5221 String s = Integer.toHexString(
5222 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5223 s = IccUtils.bytesToHexString(response.payload) + s;
5224 return s;
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
Evan Charltonc66da362014-05-16 14:06:40 -07005228 }
5229
Jake Hambye994d462014-02-03 13:10:13 -08005230 /**
5231 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5232 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5233 *
5234 * @param itemID the ID of the item to read
5235 * @return the NV item as a String, or null on error.
5236 */
5237 @Override
5238 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005239 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5241 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242
5243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005246 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5248 return value;
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Jake Hambye994d462014-02-03 13:10:13 -08005252 }
5253
5254 /**
5255 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5256 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5257 *
5258 * @param itemID the ID of the item to read
5259 * @param itemValue the value to write, as a String
5260 * @return true on success; false on any failure
5261 */
5262 @Override
5263 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267
5268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5271 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005272 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5274 return success;
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Jake Hambye994d462014-02-03 13:10:13 -08005278 }
5279
5280 /**
5281 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5282 * Used for device configuration by some CDMA operators.
5283 *
5284 * @param preferredRoamingList byte array containing the new PRL
5285 * @return true on success; false on any failure
5286 */
5287 @Override
5288 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5290 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291
5292 final long identity = Binder.clearCallingIdentity();
5293 try {
5294 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5295 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5296 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5297 return success;
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
Jake Hambye994d462014-02-03 13:10:13 -08005301 }
5302
5303 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005304 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005305 * Used for device configuration by some CDMA operators.
5306 *
chen xu6dac5ab2018-10-26 17:39:23 -07005307 * @param slotIndex - device slot.
5308 *
Jake Hambye994d462014-02-03 13:10:13 -08005309 * @return true on success; false on any failure
5310 */
5311 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005312 public boolean resetModemConfig(int slotIndex) {
5313 Phone phone = PhoneFactory.getPhone(slotIndex);
5314 if (phone != null) {
5315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5316 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317
chen xu6dac5ab2018-10-26 17:39:23 -07005318 final long identity = Binder.clearCallingIdentity();
5319 try {
5320 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5321 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5322 return success;
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 }
chen xu6dac5ab2018-10-26 17:39:23 -07005327 return false;
5328 }
5329
5330 /**
5331 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5332 *
5333 * @param slotIndex - device slot.
5334 *
5335 * @return true on success; false on any failure
5336 */
5337 @Override
5338 public boolean rebootModem(int slotIndex) {
5339 Phone phone = PhoneFactory.getPhone(slotIndex);
5340 if (phone != null) {
5341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5342 mApp, phone.getSubId(), "rebootModem");
5343
5344 final long identity = Binder.clearCallingIdentity();
5345 try {
5346 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5347 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5348 return success;
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
5352 }
5353 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005354 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005355
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005356 public String[] getPcscfAddress(String apnType, String callingPackage,
5357 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005358 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5360 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005361 return new String[0];
5362 }
5363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 final long identity = Binder.clearCallingIdentity();
5365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005366 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 } finally {
5368 Binder.restoreCallingIdentity(identity);
5369 }
Wink Saville36469e72014-06-11 15:17:00 -07005370 }
5371
Brad Ebinger51f743a2017-01-23 13:50:20 -08005372 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005373 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5374 * {@link #disableIms(int)}.
5375 * @param slotIndex device slot.
5376 */
5377 public void resetIms(int slotIndex) {
5378 enforceModifyPermission();
5379
5380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 if (mImsResolver == null) {
5383 // may happen if the does not support IMS.
5384 return;
5385 }
5386 mImsResolver.disableIms(slotIndex);
5387 mImsResolver.enableIms(slotIndex);
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
5391 }
5392
5393 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005394 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5395 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005396 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005397 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005398 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399
5400 final long identity = Binder.clearCallingIdentity();
5401 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005402 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005403 // may happen if the device does not support IMS.
5404 return;
5405 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005406 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005410 }
5411
5412 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005413 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5414 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005415 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005416 public void disableIms(int slotId) {
5417 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418
5419 final long identity = Binder.clearCallingIdentity();
5420 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005421 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005422 // may happen if the device does not support IMS.
5423 return;
5424 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005425 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005429 }
5430
5431 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005432 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5433 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005434 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005435 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005436 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438
5439 final long identity = Binder.clearCallingIdentity();
5440 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005441 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005442 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5443 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005444 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005445 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005449 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005450 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005451 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5452 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005453 @Override
5454 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005455 enforceModifyPermission();
5456
5457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005460 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
5464 }
5465
5466 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005467 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005468 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005469 */
5470 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472
5473 final long identity = Binder.clearCallingIdentity();
5474 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005475 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005476 // may happen if the device does not support IMS.
5477 return null;
5478 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005479 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005483 }
5484
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005485 /**
5486 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005487 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005488 */
5489 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005494 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005495 // may happen if the device does not support IMS.
5496 return null;
5497 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005498 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005502 }
5503
Brad Ebinger884c07b2018-02-15 16:17:40 -08005504 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005505 * Sets the ImsService Package Name that Telephony will bind to.
5506 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005507 * @param slotIndex the slot ID that the ImsService should bind for.
5508 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005509 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005510 * @param featureTypes An integer array of feature types associated with a packageName.
5511 * @param packageName The name of the package that the current configuration will be replaced
5512 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005513 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005514 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005515 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5516 int[] featureTypes, String packageName) {
5517 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5518 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5520 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005521 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005526 // may happen if the device does not support IMS.
5527 return false;
5528 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005529 Map<Integer, String> featureConfig = new HashMap<>();
5530 for (int featureType : featureTypes) {
5531 featureConfig.put(featureType, packageName);
5532 }
5533 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5534 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005538 }
5539
5540 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005541 * Clears any carrier ImsService overrides for the slot index specified that were previously
5542 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5543 *
5544 * This should only be used for testing.
5545 *
5546 * @param slotIndex the slot ID that the ImsService should bind for.
5547 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5548 */
5549 @Override
5550 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5551 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5553 "clearCarrierImsServiceOverride");
5554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5555 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5556 "clearCarrierImsServiceOverride");
5557
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 if (mImsResolver == null) {
5561 // may happen if the device does not support IMS.
5562 return false;
5563 }
5564 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569
5570 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005571 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005572 *
5573 * @param slotId The slot that the ImsService is associated with.
5574 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5575 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005576 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005577 * @return the package name of the ImsService configuration.
5578 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005579 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5580 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005581 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 TelephonyPermissions
5583 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5584 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5585 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 final long identity = Binder.clearCallingIdentity();
5588 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005589 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005590 // may happen if the device does not support IMS.
5591 return "";
5592 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005593 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005594 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5595 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005599 }
5600
Brad Ebinger77b832e2019-10-17 17:03:22 -07005601 /**
5602 * Get the MmTelFeature state associated with the requested subscription id.
5603 * @param subId The subscription that the MmTelFeature is associated with.
5604 * @param callback A callback with an integer containing the
5605 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5606 */
5607 @Override
5608 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5609 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5610 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5612 "IMS not available on device.");
5613 }
5614 final long token = Binder.clearCallingIdentity();
5615 try {
5616 int slotId = getSlotIndex(subId);
5617 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5618 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5619 + subId + "'");
5620 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5621 }
5622 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5623 try {
5624 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5625 } catch (RemoteException e) {
5626 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5627 + "Ignore");
5628 }
5629 });
5630 } finally {
5631 Binder.restoreCallingIdentity(token);
5632 }
5633 }
5634
Daniel Brightbb5840b2021-01-12 15:48:18 -08005635 /**
5636 * Sets the ims registration state on all valid {@link Phone}s.
5637 */
5638 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005643 // NOTE: Before S, this method only set the default phone.
5644 for (final Phone phone : PhoneFactory.getPhones()) {
5645 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5646 phone.setImsRegistrationState(registered);
5647 }
5648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
Wink Saville36469e72014-06-11 15:17:00 -07005652 }
5653
5654 /**
Stuart Scott54788802015-03-30 13:18:01 -07005655 * Set the network selection mode to automatic.
5656 *
5657 */
5658 @Override
5659 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
shilufc958392020-01-20 11:36:01 -08005665 if (!isActiveSubscription(subId)) {
5666 return;
5667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005669 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5670 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
Stuart Scott54788802015-03-30 13:18:01 -07005674 }
5675
Jack Yud10cdd42020-09-28 20:28:01 -07005676 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005677 * Ask the radio to connect to the input network and change selection mode to manual.
5678 *
5679 * @param subId the id of the subscription.
5680 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5681 * the operator to attach to.
5682 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5683 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5684 * normal network selection next time.
5685 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005686 */
5687 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005688 public boolean setNetworkSelectionModeManual(
5689 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005692
5693 if (!isActiveSubscription(subId)) {
5694 return false;
5695 }
5696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
5698 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005699 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005701 if (DBG) {
5702 log("setNetworkSelectionModeManual: subId: " + subId
5703 + " operator: " + operatorInfo);
5704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005709 }
shilu84f6e8b2019-12-19 13:58:01 -08005710 /**
5711 * Get the manual network selection
5712 *
5713 * @param subId the id of the subscription.
5714 *
5715 * @return the previously saved user selected PLMN
5716 */
5717 @Override
5718 public String getManualNetworkSelectionPlmn(int subId) {
5719 TelephonyPermissions
5720 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5721 mApp, subId, "getManualNetworkSelectionPlmn");
5722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 if (!isActiveSubscription(subId)) {
5726 return "";
5727 }
5728
5729 final Phone phone = getPhone(subId);
5730 if (phone == null) {
5731 return "";
5732 }
5733 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5734 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5735 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005740
5741 /**
5742 * Scans for available networks.
5743 */
5744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005745 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5746 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5748 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005749 LocationAccessPolicy.LocationPermissionResult locationResult =
5750 LocationAccessPolicy.checkLocationPermission(mApp,
5751 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5752 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005753 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005754 .setCallingPid(Binder.getCallingPid())
5755 .setCallingUid(Binder.getCallingUid())
5756 .setMethod("getCellNetworkScanResults")
5757 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5758 .build());
5759 switch (locationResult) {
5760 case DENIED_HARD:
5761 throw new SecurityException("Not allowed to access scan results -- location");
5762 case DENIED_SOFT:
5763 return null;
5764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
Pengquan Menga1bb6272018-09-06 09:59:22 -07005766 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 try {
5768 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005769 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005774 }
5775
5776 /**
sqian80370722020-01-29 15:02:51 -08005777 * Get the call forwarding info, given the call forwarding reason.
5778 */
5779 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005780 public void getCallForwarding(int subId, int callForwardingReason,
5781 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005782 enforceReadPrivilegedPermission("getCallForwarding");
5783 long identity = Binder.clearCallingIdentity();
5784 try {
5785 if (DBG) {
5786 log("getCallForwarding: subId " + subId
5787 + " callForwardingReason" + callForwardingReason);
5788 }
Hall Liua1acea22020-09-18 19:04:59 -07005789
5790 Phone phone = getPhone(subId);
5791 if (phone == null) {
5792 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005793 callback.onError(
5794 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005795 } catch (RemoteException e) {
5796 // ignore
5797 }
5798 return;
5799 }
5800
5801 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5802 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5803 @Override
5804 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5805 try {
5806 callback.onCallForwardingInfoAvailable(info);
5807 } catch (RemoteException e) {
5808 // ignore
5809 }
5810 }
5811
5812 @Override
5813 public void onError(int error) {
5814 try {
5815 callback.onError(error);
5816 } catch (RemoteException e) {
5817 // ignore
5818 }
5819 }
5820 });
5821 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
5825 }
5826
5827 /**
5828 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5829 * reason, the number to forward, and the timeout before the forwarding is attempted.
5830 */
5831 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005832 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5833 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005834 enforceModifyPermission();
5835 long identity = Binder.clearCallingIdentity();
5836 try {
5837 if (DBG) {
5838 log("setCallForwarding: subId " + subId
5839 + " callForwardingInfo" + callForwardingInfo);
5840 }
Hall Liua1acea22020-09-18 19:04:59 -07005841
5842 Phone phone = getPhone(subId);
5843 if (phone == null) {
5844 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005845 callback.accept(
5846 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005847 } catch (RemoteException e) {
5848 // ignore
5849 }
5850 return;
5851 }
5852
5853 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5854 FunctionalUtils.ignoreRemoteException(callback::accept));
5855
5856 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 /**
Hall Liua1acea22020-09-18 19:04:59 -07005863 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005864 */
5865 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005866 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005867 enforceReadPrivilegedPermission("getCallForwarding");
5868 long identity = Binder.clearCallingIdentity();
5869 try {
Hall Liua1acea22020-09-18 19:04:59 -07005870
5871 Phone phone = getPhone(subId);
5872 if (phone == null) {
5873 try {
5874 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5875 } catch (RemoteException e) {
5876 // ignore
5877 }
5878 return;
5879 }
5880
5881 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5882
sqian80370722020-01-29 15:02:51 -08005883 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005884 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
5888 }
5889
5890 /**
Hall Liua1acea22020-09-18 19:04:59 -07005891 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005892 */
5893 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005894 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005895 enforceModifyPermission();
5896 long identity = Binder.clearCallingIdentity();
5897 try {
Hall Liua1acea22020-09-18 19:04:59 -07005898 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5899
5900 Phone phone = getPhone(subId);
5901 if (phone == null) {
5902 try {
5903 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5904 } catch (RemoteException e) {
5905 // ignore
5906 }
5907 return;
5908 }
5909
5910 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5911 FunctionalUtils.ignoreRemoteException(callback::accept));
5912
5913 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
5917 }
5918
5919 /**
yinxub1bed742017-04-17 11:45:04 -07005920 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005921 *
yinxub1bed742017-04-17 11:45:04 -07005922 * @param subId id of the subscription
5923 * @param request contains the radio access networks with bands/channels to scan
5924 * @param messenger callback messenger for scan results or errors
5925 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005926 * @return the id of the requested scan which can be used to stop the scan.
5927 */
5928 @Override
5929 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005930 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5932 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005933 LocationAccessPolicy.LocationPermissionResult locationResult =
5934 LocationAccessPolicy.checkLocationPermission(mApp,
5935 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5936 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005937 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005938 .setCallingPid(Binder.getCallingPid())
5939 .setCallingUid(Binder.getCallingUid())
5940 .setMethod("requestNetworkScan")
5941 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5942 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005943 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005944 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5945 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005946 if (e != null) {
5947 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5948 throw e;
5949 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005950 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005951 return TelephonyScanManager.INVALID_SCAN_ID;
5952 }
5953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 }
Hall Liu912dfd32019-04-25 14:02:26 -07005955 int callingUid = Binder.getCallingUid();
5956 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005957 final long identity = Binder.clearCallingIdentity();
5958 try {
5959 return mNetworkScanRequestTracker.startNetworkScan(
5960 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005961 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
yinxu504e1392017-04-12 16:03:22 -07005965 }
5966
Hall Liub2ac8ef2019-02-28 15:56:23 -08005967 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005968 NetworkScanRequest request, int subId, String callingPackage) {
5969 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005970 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5971 boolean hasNetworkScanPermission =
5972 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5973 == PERMISSION_GRANTED;
5974
5975 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5976 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5977 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005978 }
5979
5980 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5981 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005982 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5983 return new SecurityException("Specific channels must not be"
5984 + " scanned without location access.");
5985 }
5986 }
5987 }
5988
Hall Liub2ac8ef2019-02-28 15:56:23 -08005989 return null;
5990 }
5991
yinxu504e1392017-04-12 16:03:22 -07005992 /**
5993 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005994 *
5995 * @param subId id of the subscription
5996 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005997 */
5998 @Override
5999 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6001 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002
Hall Liu912dfd32019-04-25 14:02:26 -07006003 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 final long identity = Binder.clearCallingIdentity();
6005 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006006 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
yinxu504e1392017-04-12 16:03:22 -07006010 }
6011
6012 /**
Junda Liu84d15a22014-07-02 11:21:04 -07006013 * Get the calculated preferred network type.
6014 * Used for debugging incorrect network type.
6015 *
6016 * @return the preferred network type, defined in RILConstants.java.
6017 */
6018 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006019 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006020 final Phone defaultPhone = getDefaultPhone();
6021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006022 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006023 return RILConstants.PREFERRED_NETWORK_MODE;
6024 }
6025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006029 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
Junda Liu84d15a22014-07-02 11:21:04 -07006033 }
6034
6035 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08006036 * Get the preferred network type.
6037 * Used for device configuration by some CDMA operators.
6038 *
6039 * @return the preferred network type, defined in RILConstants.java.
6040 */
6041 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006042 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006043 TelephonyPermissions
6044 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6045 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 if (DBG) log("getPreferredNetworkType");
6050 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6051 int networkType = (result != null ? result[0] : -1);
6052 if (DBG) log("getPreferredNetworkType: " + networkType);
6053 return networkType;
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006057 }
6058
6059 /**
6060 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006061 *
6062 * @param networkType the preferred network type, defined in RILConstants.java.
6063 * @return true on success; false on any failure.
6064 */
6065 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006066 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6068 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
calvinpan089c2a62020-03-12 14:17:55 +08006072 Boolean success = (Boolean) sendRequest(
6073 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006074
6075 if (success) {
6076 Settings.Global.putInt(mApp.getContentResolver(),
6077 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6078 }
calvinpan089c2a62020-03-12 14:17:55 +08006079 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6080 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 } finally {
6082 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006083 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006084 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006085
6086 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006087 * Get the allowed network types that store in the telephony provider.
6088 *
6089 * @param subId the id of the subscription.
6090 * @return allowedNetworkTypes the allowed network types.
6091 */
6092 @Override
6093 public long getAllowedNetworkTypes(int subId) {
6094 TelephonyPermissions
6095 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6096 mApp, subId, "getAllowedNetworkTypes");
6097
6098 final long identity = Binder.clearCallingIdentity();
6099 try {
6100 return SubscriptionManager.getLongSubscriptionProperty(
6101 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
6104 }
6105 }
6106
6107 /**
6108 * Set the allowed network types.
6109 *
6110 * @param subId the id of the subscription.
6111 * @param allowedNetworkTypes the allowed network types.
6112 * @return true on success; false on any failure.
6113 */
6114 @Override
6115 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6117 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006118
calvinpan089c2a62020-03-12 14:17:55 +08006119 SubscriptionManager.setSubscriptionProperty(subId,
6120 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6121 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006122
calvinpan089c2a62020-03-12 14:17:55 +08006123 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6124 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6125 RILConstants.PREFERRED_NETWORK_MODE);
6126 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006127 }
6128
6129 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006130 * Get the allowed network types for certain reason.
6131 *
6132 * @param subId the id of the subscription.
6133 * @param reason the reason the allowed network type change is taking place
6134 * @return the allowed network types.
6135 */
6136 @Override
6137 public long getAllowedNetworkTypesForReason(int subId,
6138 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6139 TelephonyPermissions
6140 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6141 mApp, subId, "getAllowedNetworkTypesForReason");
6142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
6147 }
6148 }
6149
6150 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006151 * Enable/Disable E-UTRA-NR Dual Connectivity
6152 * @param subId subscription id of the sim card
6153 * @param nrDualConnectivityState expected NR dual connectivity state
6154 * This can be passed following states
6155 * <ol>
6156 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6157 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6158 * <li>Disable NR dual connectivity and force secondary cell to be released
6159 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6160 * </ol>
6161 * @return operation result.
6162 */
6163 @Override
6164 public int setNrDualConnectivityState(int subId,
6165 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6167 mApp, subId, "enableNRDualConnectivity");
6168 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6169 final long identity = Binder.clearCallingIdentity();
6170 try {
6171 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6172 nrDualConnectivityState, subId,
6173 workSource);
6174 if (DBG) log("enableNRDualConnectivity result: " + result);
6175 return result;
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
6182 * Is E-UTRA-NR Dual Connectivity enabled
6183 * @return true if dual connectivity is enabled else false
6184 */
6185 @Override
6186 public boolean isNrDualConnectivityEnabled(int subId) {
6187 TelephonyPermissions
6188 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6189 mApp, subId, "isNRDualConnectivityEnabled");
6190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6194 null, subId, workSource);
6195 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6196 return isEnabled;
6197 } finally {
6198 Binder.restoreCallingIdentity(identity);
6199 }
6200 }
6201
6202 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006203 * get carrier bandwidth per primary and secondary carrier
6204 * @param subId subscription id of the sim card
6205 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6206 */
6207 @Override
6208 public CarrierBandwidth getCarrierBandwidth(int subId) {
6209 TelephonyPermissions
6210 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6211 mApp, subId, "isNRDualConnectivityEnabled");
6212 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6213 final long identity = Binder.clearCallingIdentity();
6214 try {
6215 CarrierBandwidth carrierBandwidth =
6216 getPhoneFromSubId(subId).getCarrierBandwidth();
6217 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6218 return carrierBandwidth;
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
6221 }
6222 }
6223
6224 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006225 * Get the effective allowed network types on the device.
6226 * This API will return an intersection of allowed network types for all reasons,
6227 * including the configuration done through setAllowedNetworkTypes
6228 *
6229 * @param subId the id of the subscription.
6230 * @return the allowed network types
6231 */
6232 @Override
6233 public long getEffectiveAllowedNetworkTypes(int subId) {
6234 TelephonyPermissions
6235 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6236 mApp, subId, "getEffectiveAllowedNetworkTypes");
6237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
6242 }
6243 }
6244
6245 /**
6246 * Set the allowed network types of the device and
6247 * provide the reason triggering the allowed network change.
6248 *
6249 * @param subId the id of the subscription.
6250 * @param reason the reason the allowed network type change is taking place
6251 * @param allowedNetworkTypes the allowed network types.
6252 * @return true on success; false on any failure.
6253 */
6254 @Override
6255 public boolean setAllowedNetworkTypesForReason(int subId,
6256 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6258 mApp, subId, "setAllowedNetworkTypesForReason");
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6262 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6263 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6264 RILConstants.PREFERRED_NETWORK_MODE);
6265 return setPreferredNetworkType(subId, preferredNetworkMode);
6266 } finally {
6267 Binder.restoreCallingIdentity(identity);
6268 }
6269 }
6270
6271 /**
Miaoa84611c2019-03-15 09:21:10 +08006272 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006273 *
Miaoa84611c2019-03-15 09:21:10 +08006274 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006275 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006276 * @hide
6277 */
6278 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006279 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006282 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 try {
Miaoa84611c2019-03-15 09:21:10 +08006284 if (phone != null) {
6285 return phone.hasMatchedTetherApnSetting();
6286 } else {
6287 return false;
6288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006291 }
Junda Liu475951f2014-11-07 16:45:03 -08006292 }
6293
6294 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006295 * Enable or disable always reporting signal strength changes from radio.
6296 *
6297 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6298 */
6299 @Override
6300 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6301 enforceModifyPermission();
6302 enforceSystemCaller();
6303
6304 final long identity = Binder.clearCallingIdentity();
6305 final Phone phone = getPhone(subId);
6306 try {
6307 if (phone != null) {
6308 if (DBG) {
6309 log("setAlwaysReportSignalStrength: subId=" + subId
6310 + " isEnable=" + isEnable);
6311 }
6312 phone.setAlwaysReportSignalStrength(isEnable);
6313 } else {
6314 loge("setAlwaysReportSignalStrength: no phone found for subId="
6315 + subId);
6316 }
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
6320 }
6321
6322 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006323 * Get the user enabled state of Mobile Data.
6324 *
6325 * TODO: remove and use isUserDataEnabled.
6326 * This can't be removed now because some vendor codes
6327 * calls through ITelephony directly while they should
6328 * use TelephonyManager.
6329 *
6330 * @return true on enabled
6331 */
6332 @Override
6333 public boolean getDataEnabled(int subId) {
6334 return isUserDataEnabled(subId);
6335 }
6336
6337 /**
6338 * Get whether mobile data is enabled per user setting.
6339 *
6340 * There are other factors deciding whether mobile data is actually enabled, but they are
6341 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006342 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006343 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006344 *
6345 * @return {@code true} if data is enabled else {@code false}
6346 */
6347 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006348 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006349 try {
6350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6351 null);
6352 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6354 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 int phoneId = mSubscriptionController.getPhoneId(subId);
6360 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6361 Phone phone = PhoneFactory.getPhone(phoneId);
6362 if (phone != null) {
6363 boolean retVal = phone.isUserDataEnabled();
6364 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6365 return retVal;
6366 } else {
6367 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6368 return false;
6369 }
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006372 }
6373 }
6374
6375 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006376 * Checks if the device is capable of mobile data by considering whether whether the
6377 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6378 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006379 *
Shuo Qian985d1232020-01-08 14:30:06 -08006380 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006381 */
6382 @Override
6383 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006384 try {
6385 try {
6386 mApp.enforceCallingOrSelfPermission(
6387 android.Manifest.permission.ACCESS_NETWORK_STATE,
6388 null);
6389 } catch (Exception e) {
6390 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6391 "isDataEnabled");
6392 }
6393 } catch (Exception e) {
6394 enforceReadPrivilegedPermission("isDataEnabled");
6395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396
6397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 int phoneId = mSubscriptionController.getPhoneId(subId);
6400 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6401 Phone phone = PhoneFactory.getPhone(phoneId);
6402 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006403 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6405 return retVal;
6406 } else {
6407 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6408 return false;
6409 }
6410 } finally {
6411 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006412 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006413 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006414
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006415 /**
6416 * Check if data is enabled for a specific reason
6417 * @param subId Subscription index
6418 * @param reason the reason the data enable change is taking place
6419 * @return {@code true} if the overall data is enabled; {@code false} if not.
6420 */
6421 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006422 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006423 @TelephonyManager.DataEnabledReason int reason) {
6424 try {
6425 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6426 null);
6427 } catch (Exception e) {
6428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006429 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006430 }
6431
6432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 int phoneId = mSubscriptionController.getPhoneId(subId);
6436 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006437 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006438 + " reason=" + reason);
6439 }
6440 Phone phone = PhoneFactory.getPhone(phoneId);
6441 if (phone != null) {
6442 boolean retVal;
6443 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6444 retVal = phone.isUserDataEnabled();
6445 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006446 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006447 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006448 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006449 return retVal;
6450 } else {
6451 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006452 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006453 + subId + " retVal=false");
6454 }
6455 return false;
6456 }
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006462 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006463 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006464 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6465 // Skip the check if it's one of these special uids
6466 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6467 }
6468
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006469 //load access rules from carrier configs, and check those as well: b/139133814
6470 SubscriptionController subController = SubscriptionController.getInstance();
6471 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6472 || subController == null) return privilegeFromSim;
6473
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006474 PackageManager pkgMgr = phone.getContext().getPackageManager();
6475 String[] packages = pkgMgr.getPackagesForUid(uid);
6476
6477 final long identity = Binder.clearCallingIdentity();
6478 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006479 int subId = phone.getSubId();
6480 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6481 // A test override is in place for the privileges for this subId, so don't try to
6482 // read the subscription privileges.
6483 return privilegeFromSim;
6484 }
6485 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006486 SubscriptionManager subManager = (SubscriptionManager)
6487 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6488 for (String pkg : packages) {
6489 if (subManager.canManageSubscription(subInfo, pkg)) {
6490 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6491 }
6492 }
6493 return privilegeFromSim;
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
6497 }
6498
6499 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6500 String pkgName) {
6501 //load access rules from carrier configs, and check those as well: b/139133814
6502 SubscriptionController subController = SubscriptionController.getInstance();
6503 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6504 || subController == null) return privilegeFromSim;
6505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006508 int subId = phone.getSubId();
6509 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6510 // A test override is in place for the privileges for this subId, so don't try to
6511 // read the subscription privileges.
6512 return privilegeFromSim;
6513 }
6514 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006515 SubscriptionManager subManager = (SubscriptionManager)
6516 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6517 return subManager.canManageSubscription(subInfo, pkgName)
6518 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006525 public int getCarrierPrivilegeStatus(int subId) {
6526 final Phone phone = getPhone(subId);
6527 if (phone == null) {
6528 loge("getCarrierPrivilegeStatus: Invalid subId");
6529 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6530 }
6531 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006532 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006533 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006534 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6535 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006536
6537 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6538 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006539 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006540 }
Junda Liu29340342014-07-10 15:23:27 -07006541
6542 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006543 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006544 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006545 final Phone phone = getPhone(subId);
6546 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006547 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006548 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6549 }
6550 UiccProfile profile =
6551 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6552 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006553 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6555 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006556 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006557 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006558 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006559 }
6560
6561 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006562 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6563 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006564 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006565 }
6566
6567 int phoneId = SubscriptionManager.getPhoneId(subId);
6568 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006569 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006570 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006571 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6572 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006573 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6574 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6575 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006576 }
6577
6578 @Override
6579 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006580 if (TextUtils.isEmpty(pkgName))
6581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006582 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6583 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6584 UiccCard card = UiccController.getInstance().getUiccCard(i);
6585 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006586 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006587 continue;
6588 }
6589
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006590 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6591 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6592 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006593 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6594 break;
6595 }
6596 }
6597
6598 return result;
Junda Liu29340342014-07-10 15:23:27 -07006599 }
Derek Tan89e89d42014-07-08 17:00:10 -07006600
6601 @Override
Junda Liue64de782015-04-16 17:19:16 -07006602 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6603 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6604 loge("phoneId " + phoneId + " is not valid.");
6605 return null;
6606 }
6607 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006608 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006609 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006610 return null ;
6611 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006612 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006613 }
6614
Amith Yamasani6e118872016-02-19 12:53:51 -08006615 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006616 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006617 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006618 List<String> privilegedPackages = new ArrayList<>();
6619 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006620 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6621 // has UICC in that slot.
6622 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006623 if (card.hasCarrierPrivilegeRules()) {
6624 if (packages == null) {
6625 // Only check packages in user 0 for now
6626 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006627 PackageManager.MATCH_DISABLED_COMPONENTS
6628 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006629 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006630 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006631 }
6632 for (int p = packages.size() - 1; p >= 0; p--) {
6633 PackageInfo pkgInfo = packages.get(p);
6634 if (pkgInfo != null && pkgInfo.packageName != null
6635 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006636 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006637 privilegedPackages.add(pkgInfo.packageName);
6638 }
6639 }
6640 }
6641 }
6642 return privilegedPackages;
6643 }
6644
chen xuf7e9fe82019-05-09 19:31:02 -07006645 @Override
6646 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006647 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6648
6649 final long identity = Binder.clearCallingIdentity();
6650
chen xuf7e9fe82019-05-09 19:31:02 -07006651 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006652 try {
6653 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6654 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6655 }
6656 } finally {
6657 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006658 }
6659 return privilegedPackages;
6660 }
6661
Wink Savilleb564aae2014-10-23 10:18:09 -07006662 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006663 final Phone phone = getPhone(subId);
6664 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006665 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006666 return null;
6667 }
6668 String iccId = card.getIccId();
6669 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006670 return null;
6671 }
6672 return iccId;
6673 }
6674
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006675 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006676 public void setCallComposerStatus(int subId, int status) {
6677 enforceModifyPermission();
6678
6679 final long identity = Binder.clearCallingIdentity();
6680 try {
6681 Phone phone = getPhone(subId);
6682 if (phone != null) {
6683 Phone defaultPhone = phone.getImsPhone();
6684 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6685 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6686 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006687 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6688 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006689 }
6690 }
Shuo Qiand8782462020-12-22 19:10:14 -08006691 } catch (ImsException e) {
6692 throw new ServiceSpecificException(e.getCode());
6693 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
6698 @Override
6699 public int getCallComposerStatus(int subId) {
6700 enforceReadPrivilegedPermission("getCallComposerStatus");
6701
6702 final long identity = Binder.clearCallingIdentity();
6703 try {
6704 Phone phone = getPhone(subId);
6705 if (phone != null) {
6706 Phone defaultPhone = phone.getImsPhone();
6707 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6708 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6709 return imsPhone.getCallComposerStatus();
6710 }
6711 }
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
6715 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6716 }
6717
6718 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006719 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6720 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006721 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006722 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 final String iccId = getIccId(subId);
6727 final Phone phone = getPhone(subId);
6728 if (phone == null) {
6729 return false;
6730 }
6731 final String subscriberId = phone.getSubscriberId();
6732
6733 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006734 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 + subscriberId + " to " + number);
6736 }
6737
6738 if (TextUtils.isEmpty(iccId)) {
6739 return false;
6740 }
6741
6742 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6743
6744 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6745 if (alphaTag == null) {
6746 editor.remove(alphaTagPrefKey);
6747 } else {
6748 editor.putString(alphaTagPrefKey, alphaTag);
6749 }
6750
6751 // Record both the line number and IMSI for this ICCID, since we need to
6752 // track all merged IMSIs based on line number
6753 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6754 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6755 if (number == null) {
6756 editor.remove(numberPrefKey);
6757 editor.remove(subscriberPrefKey);
6758 } else {
6759 editor.putString(numberPrefKey, number);
6760 editor.putString(subscriberPrefKey, subscriberId);
6761 }
6762
6763 editor.commit();
6764 return true;
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006767 }
Derek Tan7226c842014-07-02 17:42:23 -07006768 }
6769
6770 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006771 public String getLine1NumberForDisplay(int subId, String callingPackage,
6772 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006773 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006775 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006776 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006777 return null;
6778 }
Derek Tan97ebb422014-09-05 16:55:38 -07006779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 final long identity = Binder.clearCallingIdentity();
6781 try {
6782 String iccId = getIccId(subId);
6783 if (iccId != null) {
6784 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6785 if (DBG_MERGE) {
6786 log("getLine1NumberForDisplay returning "
6787 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6788 }
6789 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6792 return null;
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006795 }
Derek Tan7226c842014-07-02 17:42:23 -07006796 }
6797
6798 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006799 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006802 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006803 return null;
6804 }
Derek Tan97ebb422014-09-05 16:55:38 -07006805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 String iccId = getIccId(subId);
6809 if (iccId != null) {
6810 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6811 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6812 }
6813 return null;
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006816 }
Derek Tan7226c842014-07-02 17:42:23 -07006817 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006818
6819 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006820 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6821 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006822 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6823 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006825 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006826 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006827 return null;
6828 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006829
Jordan Liub49b04b2019-05-06 14:45:15 -07006830 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6831 // the process, where TelephonyManager was instantiated.
6832 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006833 final long identity = Binder.clearCallingIdentity();
6834 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006835 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 final TelephonyManager tele = TelephonyManager.from(context);
6837 final SubscriptionManager sub = SubscriptionManager.from(context);
6838
6839 // Figure out what subscribers are currently active
6840 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841
Jordan Liub49b04b2019-05-06 14:45:15 -07006842 // Only consider subs which match the current subId
6843 // This logic can be simplified. See b/131189269 for progress.
6844 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006845 activeSubscriberIds.add(tele.getSubscriberId(subId));
6846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847
6848 // First pass, find a number override for an active subscriber
6849 String mergeNumber = null;
6850 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6851 for (String key : prefs.keySet()) {
6852 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6853 final String subscriberId = (String) prefs.get(key);
6854 if (activeSubscriberIds.contains(subscriberId)) {
6855 final String iccId = key.substring(
6856 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6857 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6858 mergeNumber = (String) prefs.get(numberKey);
6859 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006860 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 + " for active subscriber " + subscriberId);
6862 }
6863 if (!TextUtils.isEmpty(mergeNumber)) {
6864 break;
6865 }
6866 }
6867 }
6868 }
6869
6870 // Shortcut when no active merged subscribers
6871 if (TextUtils.isEmpty(mergeNumber)) {
6872 return null;
6873 }
6874
6875 // Second pass, find all subscribers under that line override
6876 final ArraySet<String> result = new ArraySet<>();
6877 for (String key : prefs.keySet()) {
6878 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6879 final String number = (String) prefs.get(key);
6880 if (mergeNumber.equals(number)) {
6881 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6882 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6883 final String subscriberId = (String) prefs.get(subscriberKey);
6884 if (!TextUtils.isEmpty(subscriberId)) {
6885 result.add(subscriberId);
6886 }
6887 }
6888 }
6889 }
6890
6891 final String[] resultArray = result.toArray(new String[result.size()]);
6892 Arrays.sort(resultArray);
6893 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006894 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6896 }
6897 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006898 } finally {
6899 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006900 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006901 }
6902
6903 @Override
zoey chen38003472019-12-13 17:16:31 +08006904 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6905 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006906
6907 final long identity = Binder.clearCallingIdentity();
6908 try {
6909 final TelephonyManager telephonyManager = mApp.getSystemService(
6910 TelephonyManager.class);
6911 String subscriberId = telephonyManager.getSubscriberId(subId);
6912 if (subscriberId == null) {
6913 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006914 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006915 + subId);
6916 }
6917 return null;
6918 }
6919
6920 final SubscriptionInfo info = SubscriptionController.getInstance()
6921 .getSubscriptionInfo(subId);
6922 final ParcelUuid groupUuid = info.getGroupUuid();
6923 // If it doesn't belong to any group, return just subscriberId of itself.
6924 if (groupUuid == null) {
6925 return new String[]{subscriberId};
6926 }
6927
6928 // Get all subscriberIds from the group.
6929 final List<String> mergedSubscriberIds = new ArrayList<>();
6930 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006931 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006932 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006933 for (SubscriptionInfo subInfo : groupInfos) {
6934 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6935 if (subscriberId != null) {
6936 mergedSubscriberIds.add(subscriberId);
6937 }
6938 }
6939
6940 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
6943
6944 }
6945 }
6946
6947 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006948 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006949 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006950 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951
6952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 final Phone phone = getPhone(subId);
6955 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006959 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006960
6961 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006962 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006963 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6964 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006965 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6966 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967
6968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 final Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 return false;
6973 }
6974 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6975 cdmaNonRoamingList);
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006978 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006979 }
6980
6981 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006982 @Deprecated
6983 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6984 enforceModifyPermission();
6985
6986 int returnValue = 0;
6987 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006988 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006989 if(result.exception == null) {
6990 if (result.result != null) {
6991 byte[] responseData = (byte[])(result.result);
6992 if(responseData.length > oemResp.length) {
6993 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6994 responseData.length + "bytes. Buffer Size is " +
6995 oemResp.length + "bytes.");
6996 }
6997 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6998 returnValue = responseData.length;
6999 }
7000 } else {
7001 CommandException ex = (CommandException) result.exception;
7002 returnValue = ex.getCommandError().ordinal();
7003 if(returnValue > 0) returnValue *= -1;
7004 }
7005 } catch (RuntimeException e) {
7006 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7007 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7008 if(returnValue > 0) returnValue *= -1;
7009 }
7010
7011 return returnValue;
7012 }
7013
7014 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07007015 public void setRadioCapability(RadioAccessFamily[] rafs) {
7016 try {
7017 ProxyController.getInstance().setRadioCapability(rafs);
7018 } catch (RuntimeException e) {
7019 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
7020 }
7021 }
7022
7023 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007024 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007025 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007026 try {
7027 TelephonyPermissions
7028 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7029 mApp, phone.getSubId(), "getRadioAccessFamily");
7030 } catch (SecurityException e) {
7031 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7032 throw e;
7033 }
chen xub97461a2018-10-26 14:17:57 -07007034 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007035 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007036 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 final long identity = Binder.clearCallingIdentity();
7039 try {
chen xub97461a2018-10-26 14:17:57 -07007040 TelephonyPermissions
7041 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7042 mApp, phone.getSubId(), "getRadioAccessFamily");
7043 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
chen xub97461a2018-10-26 14:17:57 -07007047 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007048 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007049
7050 @Override
7051 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007052 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054
7055 final long identity = Binder.clearCallingIdentity();
7056 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007057 ImsManager.getInstance(defaultPhone.getContext(),
7058 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007062 }
7063
7064 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007065 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007066 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7068 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007069 return false;
7070 }
Svet Ganovb320e182015-04-16 12:30:10 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 // Check the user preference and the system-level IMS setting. Even if the user has
7075 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7076 // In the long run, we may instead need to check if there exists a connection service
7077 // which can support video calling.
7078 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 return imsManager.isVtEnabledByPlatform()
7081 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7082 && imsManager.isVtEnabledByUser();
7083 } finally {
7084 Binder.restoreCallingIdentity(identity);
7085 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007086 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007087
Andrew Leea1239f22015-03-02 17:44:07 -08007088 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007089 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7090 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 mApp, subId, callingPackage, callingFeatureId,
7093 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 return false;
7095 }
7096
7097 final long identity = Binder.clearCallingIdentity();
7098 try {
7099 CarrierConfigManager configManager =
7100 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007101 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105 }
Andrew Leea1239f22015-03-02 17:44:07 -08007106 }
7107
7108 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007109 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007111 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 return false;
7113 }
7114
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
7117 CarrierConfigManager configManager =
7118 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7121 } finally {
7122 Binder.restoreCallingIdentity(identity);
7123 }
Andrew Leea1239f22015-03-02 17:44:07 -08007124 }
7125
Andrew Lee9431b832015-03-09 18:46:45 -07007126 @Override
7127 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007128 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007129 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007130 }
7131
7132 @Override
7133 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 final long identity = Binder.clearCallingIdentity();
7135 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007136 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Andrew Lee9431b832015-03-09 18:46:45 -07007140 }
7141
Hall Liuf6668912018-10-31 17:05:23 -07007142 /**
7143 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7144 * support for the feature and device firmware support.
7145 *
7146 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7147 */
7148 @Override
7149 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007151 final Phone phone = getPhone(subscriptionId);
7152 if (phone == null) {
7153 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7154 return false;
7155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007157 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7159 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007160 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 return isCarrierSupported && isDeviceSupported;
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
Hall Liu98187582018-01-22 19:15:32 -08007165 }
7166
Hall Liuf6668912018-10-31 17:05:23 -07007167 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007168 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7169 * RTT setting, will return true if the device and carrier both support RTT.
7170 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007171 */
7172 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007175 boolean isRttSupported = isRttSupported(subscriptionId);
7176 boolean isUserRttSettingOn = Settings.Secure.getInt(
7177 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7178 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7179 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7180 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007184 }
7185
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007186 @Deprecated
7187 @Override
7188 public String getDeviceId(String callingPackage) {
7189 return getDeviceIdWithFeature(callingPackage, null);
7190 }
7191
Sanket Padawe7310cc72015-01-14 09:53:20 -08007192 /**
7193 * Returns the unique device ID of phone, for example, the IMEI for
7194 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7195 *
7196 * <p>Requires Permission:
7197 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7198 */
7199 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007200 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007201 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007202 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007203 return null;
7204 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007205 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007206 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007207 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007208 return null;
7209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 return phone.getDeviceId();
7214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007217 }
7218
Ping Sunc67b7c22016-03-02 19:16:45 +08007219 /**
7220 * {@hide}
7221 * Returns the IMS Registration Status on a particular subid
7222 *
7223 * @param subId
7224 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007225 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007226 Phone phone = getPhone(subId);
7227 if (phone != null) {
7228 return phone.isImsRegistered();
7229 } else {
7230 return false;
7231 }
7232 }
7233
Santos Cordon7a1885b2015-02-03 11:15:19 -08007234 @Override
7235 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007242 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007243
Tyler Gunnf70ed162019-04-03 15:28:53 -07007244 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007245 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007246 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007248 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007249 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7250 }
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
7259 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007260 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007261 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7262 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 Phone phone = getPhone(subscriptionId);
7266 if (phone == null) {
7267 return null;
7268 }
7269 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7270 } finally {
7271 Binder.restoreCallingIdentity(identity);
7272 }
7273 }
7274
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007275 /**
7276 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007277 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007278 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 Phone phone = getPhone(subId);
7282 if (phone != null) {
7283 return phone.isWifiCallingEnabled();
7284 } else {
7285 return false;
7286 }
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007289 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007290 }
7291
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007292 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007293 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007294 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007295 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 Phone phone = getPhone(subId);
7299 if (phone != null) {
7300 return phone.isVideoEnabled();
7301 } else {
7302 return false;
7303 }
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007306 }
7307 }
7308
7309 /**
7310 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7311 * defined in {@link ImsRegistrationImplBase}.
7312 */
7313 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 final long identity = Binder.clearCallingIdentity();
7315 try {
7316 Phone phone = getPhone(subId);
7317 if (phone != null) {
7318 return phone.getImsRegistrationTech();
7319 } else {
7320 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7321 }
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007324 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007325 }
7326
Stuart Scott8eef64f2015-04-08 15:13:54 -07007327 @Override
7328 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007329 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007330 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7331 return;
7332 }
7333
Svet Ganovcc087f82015-05-12 20:35:54 -07007334 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007335
Svet Ganovcc087f82015-05-12 20:35:54 -07007336 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007337 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7338 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007339 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007340 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007341 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007342 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007343 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7344 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007345 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007346 // There has been issues when Sms raw table somehow stores orphan
7347 // fragments. They lead to garbled message when new fragments come
7348 // in and combined with those stale ones. In case this happens again,
7349 // user can reset all network settings which will clean up this table.
7350 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007351 // Clean up IMS settings as well here.
7352 int slotId = getSlotIndex(subId);
7353 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7354 ImsManager.getInstance(mApp, slotId).factoryReset();
7355 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007356
7357 // Erase modem config if erase modem on network setting is enabled.
7358 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7359 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7360 if (configValue != null && Boolean.parseBoolean(configValue)) {
7361 sendEraseModemConfig(getDefaultPhone());
7362 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007363 } finally {
7364 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007365 }
7366 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007367
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007368 private void cleanUpSmsRawTable(Context context) {
7369 ContentResolver resolver = context.getContentResolver();
7370 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7371 resolver.delete(uri, null, null);
7372 }
7373
Narayan Kamath1c496c22015-04-16 14:40:19 +01007374 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007375 public String getSimLocaleForSubscriber(int subId) {
7376 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7377 final Phone phone = getPhone(subId);
7378 if (phone == null) {
7379 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007380 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 final long identity = Binder.clearCallingIdentity();
7383 try {
chen xu5d3637b2019-01-21 23:31:38 -08007384 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007385 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007386 if (info == null) {
7387 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7388 return null;
7389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 // Try and fetch the locale from the carrier properties or from the SIM language
7391 // preferences (EF-PL and EF-LI)...
7392 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007394 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7395 if (localeFromDefaultSim != null) {
7396 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7397 if (DBG) log("Using locale from subId: " + subId + " locale: "
7398 + localeFromDefaultSim);
7399 return localeFromDefaultSim.toLanguageTag();
7400 } else {
7401 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 }
7403 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 // The SIM language preferences only store a language (e.g. fr = French), not an
7406 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7407 // the SIM and carrier preferences does not include a country we add the country
7408 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007409 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007411 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 return mccLocale.toLanguageTag();
7413 }
7414
7415 if (DBG) log("No locale found - returning null");
7416 return null;
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007420 }
7421
7422 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007423 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007424 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007425 }
7426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 /**
7428 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7429 */
7430 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007431 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007432 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007433 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007434
Chenjie Yu1ba97252018-01-11 18:16:20 -08007435 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007436 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007437
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007438 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007439 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7440 * representing the state of the modem.
7441 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007442 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7443 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007444 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007445 */
7446 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007447 public void requestModemActivityInfo(ResultReceiver result) {
7448 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007449 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450
7451 final long identity = Binder.clearCallingIdentity();
7452 try {
sqian1a1be542020-03-05 11:37:28 -08007453 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 } finally {
7455 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007456 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007457 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007458
Siddharth Rayb8114062018-06-17 15:02:38 -07007459 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7460 // less than total activity duration.
7461 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7462 if (info == null) {
7463 return false;
7464 }
7465 int activityDurationMs =
7466 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7467 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007468 int[] txTimeMs = info.getTransmitTimeMillis();
7469 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7470 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007471 }
7472 return (info.isValid()
7473 && (info.getSleepTimeMillis() <= activityDurationMs)
7474 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007475 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007476 && (totalTxTimeMs <= activityDurationMs));
7477 }
7478
Jack Yu85bd38a2015-11-09 11:34:32 -08007479 /**
7480 * {@hide}
7481 * Returns the service state information on specified subscription.
7482 */
7483 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007484 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7485 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007487 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007488 return null;
7489 }
7490
Hall Liuf19c44f2018-11-27 14:38:17 -08007491 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7492 LocationAccessPolicy.checkLocationPermission(mApp,
7493 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7494 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007495 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007496 .setCallingPid(Binder.getCallingPid())
7497 .setCallingUid(Binder.getCallingUid())
7498 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007499 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007500 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7501 .build());
7502
7503 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7504 LocationAccessPolicy.checkLocationPermission(mApp,
7505 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7506 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007507 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007508 .setCallingPid(Binder.getCallingPid())
7509 .setCallingUid(Binder.getCallingUid())
7510 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007511 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007512 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7513 .build());
7514 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7515 boolean hasFinePermission =
7516 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7517 boolean hasCoarsePermission =
7518 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 final long identity = Binder.clearCallingIdentity();
7521 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007522 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7523 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7524 Rlog.d(LOG_TAG,
7525 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7526 return null;
7527 }
7528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final Phone phone = getPhone(subId);
7530 if (phone == null) {
7531 return null;
7532 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007533
Hall Liuf19c44f2018-11-27 14:38:17 -08007534 ServiceState ss = phone.getServiceState();
7535
7536 // Scrub out the location info in ServiceState depending on what level of access
7537 // the caller has.
7538 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007539 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7540 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007544 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007545
7546 /**
7547 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7548 *
7549 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7550 * voicemail ringtone.
7551 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7552 * PhoneAccount.
7553 */
7554 @Override
7555 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7559 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007560 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007567 }
7568
7569 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007570 * Sets the per-account voicemail ringtone.
7571 *
7572 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7573 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7574 *
7575 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7576 * voicemail ringtone.
7577 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7578 * PhoneAccount.
7579 */
7580 @Override
7581 public void setVoicemailRingtoneUri(String callingPackage,
7582 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007585 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7586 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7588 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7589 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591
7592 final long identity = Binder.clearCallingIdentity();
7593 try {
7594 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7595 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007596 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 }
7598 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007601 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007602 }
7603
7604 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007605 * Returns whether vibration is set for voicemail notification in Phone settings.
7606 *
7607 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7608 * voicemail vibration setting.
7609 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7610 */
7611 @Override
7612 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7616 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007617 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007624 }
7625
Youhan Wange64578a2016-05-02 15:32:42 -07007626 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007627 * Sets the per-account voicemail vibration.
7628 *
7629 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7630 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7631 *
7632 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7633 * voicemail vibration setting.
7634 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7635 * specific PhoneAccount.
7636 */
7637 @Override
7638 public void setVoicemailVibrationEnabled(String callingPackage,
7639 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007642 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7643 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7645 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7646 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007647 }
7648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7652 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007653 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 }
7655 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007658 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007659 }
7660
7661 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007662 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7663 *
7664 * @throws SecurityException if the caller does not have the required permission
7665 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007666 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007667 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007668 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007669 }
7670
7671 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007672 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7673 * permission.
7674 *
7675 * @throws SecurityException if the caller does not have the required permission
7676 */
7677 private void enforceSendSmsPermission() {
7678 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7679 }
7680
7681 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007682 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007683 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007684 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007685 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007686 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007690 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 if (componentName == null) {
7692 throw new SecurityException(
7693 "Caller not current active visual voicemail package[null]");
7694 }
7695 String vvmPackage = componentName.getPackageName();
7696 if (!callingPackage.equals(vvmPackage)) {
7697 throw new SecurityException("Caller not current active visual voicemail package["
7698 + vvmPackage + "]");
7699 }
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007702 }
7703 }
7704
7705 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007706 * Return the application ID for the app type.
7707 *
7708 * @param subId the subscription ID that this request applies to.
7709 * @param appType the uicc app type.
7710 * @return Application ID for specificied app type, or null if no uicc.
7711 */
7712 @Override
7713 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007714 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007715 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716
7717 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007718 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 if (phone == null) {
7720 return null;
7721 }
7722 String aid = null;
7723 try {
7724 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7725 .getApplicationByType(appType).getAid();
7726 } catch (Exception e) {
7727 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7728 }
7729 return aid;
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007732 }
Youhan Wange64578a2016-05-02 15:32:42 -07007733 }
7734
Youhan Wang4001d252016-05-11 10:29:41 -07007735 /**
7736 * Return the Electronic Serial Number.
7737 *
7738 * @param subId the subscription ID that this request applies to.
7739 * @return ESN or null if error.
7740 */
7741 @Override
7742 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007743 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007744 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745
7746 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007747 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 if (phone == null) {
7749 return null;
7750 }
7751 String esn = null;
7752 try {
7753 esn = phone.getEsn();
7754 } catch (Exception e) {
7755 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7756 }
7757 return esn;
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007760 }
Youhan Wang4001d252016-05-11 10:29:41 -07007761 }
7762
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007763 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007764 * Return the Preferred Roaming List Version.
7765 *
7766 * @param subId the subscription ID that this request applies to.
7767 * @return PRLVersion or null if error.
7768 */
7769 @Override
7770 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007771 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007772 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773
7774 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007775 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 if (phone == null) {
7777 return null;
7778 }
7779 String cdmaPrlVersion = null;
7780 try {
7781 cdmaPrlVersion = phone.getCdmaPrlVersion();
7782 } catch (Exception e) {
7783 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7784 }
7785 return cdmaPrlVersion;
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007788 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007789 }
7790
7791 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007792 * Get snapshot of Telephony histograms
7793 * @return List of Telephony histograms
7794 * @hide
7795 */
7796 @Override
7797 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7799 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800
7801 final long identity = Binder.clearCallingIdentity();
7802 try {
7803 return RIL.getTelephonyRILTimingHistograms();
7804 } finally {
7805 Binder.restoreCallingIdentity(identity);
7806 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007807 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007808
7809 /**
7810 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007811 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7812 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007813 * Require system privileges. In the future we may add this to carrier APIs.
7814 *
Michele Berionne482f8202018-11-27 18:57:59 -08007815 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007816 */
7817 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007818 @TelephonyManager.SetCarrierRestrictionResult
7819 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007820 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007822
Michele Berionne482f8202018-11-27 18:57:59 -08007823 if (carrierRestrictionRules == null) {
7824 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007825 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 final long identity = Binder.clearCallingIdentity();
7828 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007829 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007830 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007834 }
7835
7836 /**
7837 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007838 * Get the allowed carrier list and the excluded carrier list, including the priority between
7839 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007840 * Require system privileges. In the future we may add this to carrier APIs.
7841 *
Michele Berionne482f8202018-11-27 18:57:59 -08007842 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007843 */
7844 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007845 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007846 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007851 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7852 if (response instanceof CarrierRestrictionRules) {
7853 return (CarrierRestrictionRules) response;
7854 }
7855 // Response is an Exception of some kind,
7856 // which is signalled to the user as a NULL retval
7857 return null;
7858 } catch (Exception e) {
7859 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7860 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007864 }
7865
fionaxu59545b42016-05-25 15:53:37 -07007866 /**
fionaxu59545b42016-05-25 15:53:37 -07007867 * Action set from carrier signalling broadcast receivers to enable/disable radio
7868 * @param subId the subscription ID that this action applies to.
7869 * @param enabled control enable or disable radio.
7870 * {@hide}
7871 */
7872 @Override
7873 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7874 enforceModifyPermission();
7875 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876
7877 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007878 if (phone == null) {
7879 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7880 return;
7881 }
7882 try {
7883 phone.carrierActionSetRadioEnabled(enabled);
7884 } catch (Exception e) {
7885 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 } finally {
7887 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007888 }
7889 }
7890
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007891 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007892 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7893 * network status based on which carrier apps could apply actions accordingly,
7894 * enable/disable default url handler for example.
7895 *
7896 * @param subId the subscription ID that this action applies to.
7897 * @param report control start/stop reporting the default network status.
7898 * {@hide}
7899 */
7900 @Override
7901 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7902 enforceModifyPermission();
7903 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904
7905 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007906 if (phone == null) {
7907 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7908 return;
7909 }
7910 try {
7911 phone.carrierActionReportDefaultNetworkStatus(report);
7912 } catch (Exception e) {
7913 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 } finally {
7915 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007916 }
7917 }
7918
7919 /**
fionaxud9622282017-07-17 17:51:30 -07007920 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7921 * @param subId the subscription ID that this action applies to.
7922 * {@hide}
7923 */
7924 @Override
7925 public void carrierActionResetAll(int subId) {
7926 enforceModifyPermission();
7927 final Phone phone = getPhone(subId);
7928 if (phone == null) {
7929 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7930 return;
7931 }
7932 try {
7933 phone.carrierActionResetAll();
7934 } catch (Exception e) {
7935 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7936 }
7937 }
7938
7939 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007940 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7941 * bug report is being generated.
7942 */
7943 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007944 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007945 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7946 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007947 writer.println("Permission Denial: can't dump Phone from pid="
7948 + Binder.getCallingPid()
7949 + ", uid=" + Binder.getCallingUid()
7950 + "without permission "
7951 + android.Manifest.permission.DUMP);
7952 return;
7953 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007954 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007955 }
Jack Yueb89b242016-06-22 13:27:47 -07007956
Brad Ebingerdac2f002018-04-03 15:17:52 -07007957 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007958 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7959 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7960 @NonNull String[] args) {
7961 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7962 this, in.getFileDescriptor(), out.getFileDescriptor(),
7963 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007964 }
7965
Jack Yueb89b242016-06-22 13:27:47 -07007966 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007967 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007968 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007969 * @param reason the reason the data enable change is taking place
7970 * @param enabled True if enabling the data, otherwise disabling.
7971 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007972 */
7973 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007974 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007975 boolean enabled) {
7976 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7977 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7978 try {
7979 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007980 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007981 } catch (SecurityException se) {
7982 enforceModifyPermission();
7983 }
7984 } else {
7985 enforceModifyPermission();
7986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987
7988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 Phone phone = getPhone(subId);
7991 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007992 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7993 phone.carrierActionSetMeteredApnsEnabled(enabled);
7994 } else {
7995 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 }
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008000 }
8001 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008002
8003 /**
8004 * Get Client request stats
8005 * @return List of Client Request Stats
8006 * @hide
8007 */
8008 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008009 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8010 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008012 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008013 return null;
8014 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008015 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 if (phone != null) {
8020 return phone.getClientRequestStats();
8021 }
8022
8023 return null;
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
8026 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008027 }
8028
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008029 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008030 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008031 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008032 }
Jack Yueb4124c2017-02-16 15:32:43 -08008033
8034 /**
Grace Chen70990072017-03-24 17:21:30 -07008035 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008036 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008037 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008038 * @param state State of SIM (power down, power up, pass through)
8039 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8040 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8041 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008042 *
8043 **/
8044 @Override
Grace Chen70990072017-03-24 17:21:30 -07008045 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008046 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008047 Phone phone = PhoneFactory.getPhone(slotIndex);
8048
vagdeviaf9a5b92018-08-15 16:01:53 -07008049 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008054 phone.setSimPowerState(state, null, workSource);
8055 }
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
8058 }
8059 }
8060
8061 /**
8062 * Set SIM card power state.
8063 *
8064 * @param slotIndex SIM slot id.
8065 * @param state State of SIM (power down, power up, pass through)
8066 * @param callback callback to trigger after success or failure
8067 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8068 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8069 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8070 *
8071 **/
8072 @Override
8073 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8074 IIntegerConsumer callback) {
8075 enforceModifyPermission();
8076 Phone phone = PhoneFactory.getPhone(slotIndex);
8077
8078 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8079
8080 final long identity = Binder.clearCallingIdentity();
8081 try {
8082 if (phone != null) {
8083 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8084 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 }
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008088 }
8089 }
Shuo Qiandd210312017-04-12 22:11:33 +00008090
Tyler Gunn65d45c22017-06-05 11:22:26 -07008091 private boolean isUssdApiAllowed(int subId) {
8092 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008093 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008094 if (configManager == null) {
8095 return false;
8096 }
8097 PersistableBundle pb = configManager.getConfigForSubId(subId);
8098 if (pb == null) {
8099 return false;
8100 }
8101 return pb.getBoolean(
8102 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8103 }
8104
Shuo Qiandd210312017-04-12 22:11:33 +00008105 /**
8106 * Check if phone is in emergency callback mode
8107 * @return true if phone is in emergency callback mode
8108 * @param subId sub id
8109 */
goneil9c5f4872017-12-05 14:07:56 -08008110 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008111 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008112 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114
8115 final long identity = Binder.clearCallingIdentity();
8116 try {
8117 if (phone != null) {
8118 return phone.isInEcm();
8119 } else {
8120 return false;
8121 }
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008124 }
8125 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008126
8127 /**
8128 * Get the current signal strength information for the given subscription.
8129 * Because this information is not updated when the device is in a low power state
8130 * it should not be relied-upon to be current.
8131 * @param subId Subscription index
8132 * @return the most recent cached signal strength info from the modem
8133 */
8134 @Override
8135 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 Phone p = getPhone(subId);
8139 if (p == null) {
8140 return null;
8141 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 return p.getSignalStrength();
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008148
Pengquan Meng77b7f132018-08-22 14:49:57 -07008149 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008150 * Get the current modem radio state for the given slot.
8151 * @param slotIndex slot index.
8152 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008153 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008154 * @return the current radio power state from the modem
8155 */
8156 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008157 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008158 Phone phone = PhoneFactory.getPhone(slotIndex);
8159 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8161 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008162 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8163 }
8164
8165 final long identity = Binder.clearCallingIdentity();
8166 try {
8167 return phone.getRadioPowerState();
8168 } finally {
8169 Binder.restoreCallingIdentity(identity);
8170 }
8171 }
8172 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8173 }
8174
8175 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008176 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8177 *
8178 * <p>Requires one of the following permissions:
8179 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8180 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8181 * privileges.
8182 *
8183 * @param subId subscription id
8184 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8185 * {@code false}.
8186 */
8187 @Override
8188 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008189 try {
8190 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8191 null);
8192 } catch (Exception e) {
8193 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8194 mApp, subId, "isDataRoamingEnabled");
8195 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008196
Pengquan Menga1bb6272018-09-06 09:59:22 -07008197 boolean isEnabled = false;
8198 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008199 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 Phone phone = getPhone(subId);
8201 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008202 } finally {
8203 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008204 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008205 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008206 }
8207
8208
8209 /**
8210 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8211 *
8212 * <p> Requires permission:
8213 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8214 * privileges.
8215 *
8216 * @param subId subscription id
8217 * @param isEnabled {@code true} means enable, {@code false} means disable.
8218 */
8219 @Override
8220 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8222 mApp, subId, "setDataRoamingEnabled");
8223
Pengquan Menga1bb6272018-09-06 09:59:22 -07008224 final long identity = Binder.clearCallingIdentity();
8225 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008226 Phone phone = getPhone(subId);
8227 if (phone != null) {
8228 phone.setDataRoamingEnabled(isEnabled);
8229 }
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008232 }
8233 }
8234
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008235 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008236 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008237 TelephonyPermissions
8238 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008239 mApp, subId, "isManualNetworkSelectionAllowed");
8240
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008241 boolean isAllowed = true;
8242 final long identity = Binder.clearCallingIdentity();
8243 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008244 Phone phone = getPhone(subId);
8245 if (phone != null) {
8246 isAllowed = phone.isCspPlmnEnabled();
8247 }
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
8251 return isAllowed;
8252 }
8253
8254 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008255 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008256 // Verify that tha callingPackage belongs to the calling UID
8257 mApp.getSystemService(AppOpsManager.class)
8258 .checkPackage(Binder.getCallingUid(), callingPackage);
8259
Jordan Liu1e142fc2019-04-22 15:10:43 -07008260 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008261 try {
8262 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008263 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008264 } catch (SecurityException e) {
8265 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8266 // has carrier privileges on an active UICC
8267 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8268 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008269 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008270 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008271 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008272
8273 final long identity = Binder.clearCallingIdentity();
8274 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008275 UiccController uiccController = UiccController.getInstance();
8276 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008277 if (hasReadPermission) {
8278 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008279 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008280
8281 // Remove private info if the caller doesn't have access
8282 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8283 for (UiccCardInfo cardInfo : cardInfos) {
8284 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8285 // is available
8286 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8287 if (card == null || card.getUiccProfile() == null) {
8288 // assume no access if the card or profile is unavailable
8289 filteredInfos.add(cardInfo.getUnprivileged());
8290 continue;
8291 }
8292 UiccProfile profile = card.getUiccProfile();
8293 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8294 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8295 filteredInfos.add(cardInfo);
8296 } else {
8297 filteredInfos.add(cardInfo.getUnprivileged());
8298 }
8299 }
8300 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 }
8305
8306 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008307 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008308 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 final long identity = Binder.clearCallingIdentity();
8311 try {
8312 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8313 if (slots == null) {
8314 Rlog.i(LOG_TAG, "slots is null.");
8315 return null;
8316 }
8317
8318 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8319 for (int i = 0; i < slots.length; i++) {
8320 UiccSlot slot = slots[i];
8321 if (slot == null) {
8322 continue;
8323 }
8324
Jordan Liu7be7e652019-05-06 18:55:02 +00008325 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 UiccCard card = slot.getUiccCard();
8327 if (card != null) {
8328 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008329 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008330 cardId = slot.getEid();
8331 if (TextUtils.isEmpty(cardId)) {
8332 cardId = slot.getIccId();
8333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 }
8335
Jordan Liu857451f2019-05-09 16:35:35 -07008336 if (cardId != null) {
8337 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8338 // if cardId is an EID, it's all digits so this is fine
8339 cardId = IccUtils.stripTrailingFs(cardId);
8340 }
8341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008342 int cardState = 0;
8343 switch (slot.getCardState()) {
8344 case CARDSTATE_ABSENT:
8345 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8346 break;
8347 case CARDSTATE_PRESENT:
8348 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8349 break;
8350 case CARDSTATE_ERROR:
8351 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8352 break;
8353 case CARDSTATE_RESTRICTED:
8354 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8355 break;
8356 default:
8357 break;
8358
8359 }
8360
8361 infos[i] = new UiccSlotInfo(
8362 slot.isActive(),
8363 slot.isEuicc(),
8364 cardId,
8365 cardState,
8366 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008367 slot.isExtendedApduSupported(),
8368 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 }
8370 return infos;
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008373 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008374 }
8375
8376 @Override
8377 public boolean switchSlots(int[] physicalSlots) {
8378 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
8382 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008386 }
Jack Yu4c988042018-02-27 15:30:01 -08008387
8388 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008389 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008390 final long identity = Binder.clearCallingIdentity();
8391 try {
8392 return UiccController.getInstance().getCardIdForDefaultEuicc();
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
8396 }
8397
Pengquan Meng85728fb2018-03-12 16:31:21 -07008398 /**
goneil47ffb6e2018-04-06 15:40:58 -07008399 * A test API to reload the UICC profile.
8400 *
8401 * <p>Requires that the calling app has permission
8402 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8403 * @hide
8404 */
8405 @Override
8406 public void refreshUiccProfile(int subId) {
8407 enforceModifyPermission();
8408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 Phone phone = getPhone(subId);
8412 if (phone == null) {
8413 return;
8414 }
8415 UiccCard uiccCard = phone.getUiccCard();
8416 if (uiccCard == null) {
8417 return;
8418 }
8419 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8420 if (uiccProfile == null) {
8421 return;
8422 }
8423 uiccProfile.refresh();
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
8428
8429 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008430 * Returns false if the mobile data is disabled by default, otherwise return true.
8431 */
8432 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008433 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008434 }
8435
8436 /**
8437 * Returns true if the data roaming is enabled by default, i.e the system property
8438 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8439 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8440 */
8441 private boolean getDefaultDataRoamingEnabled(int subId) {
8442 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008443 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008444 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008445 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8446 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8447 return isDataRoamingEnabled;
8448 }
8449
8450 /**
8451 * Returns the default network type for the given {@code subId}, if the default network type is
8452 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8453 */
8454 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008455 List<Integer> list = TelephonyProperties.default_network();
8456 int phoneId = mSubscriptionController.getPhoneId(subId);
8457 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8458 return list.get(phoneId);
8459 }
8460 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008461 }
fionaxua13278b2018-03-21 00:08:13 -07008462
8463 @Override
8464 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008465 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 final Phone phone = getPhone(subId);
8471 if (phone == null) {
8472 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8473 return;
8474 }
chen xueaba88a2019-03-15 13:15:10 -07008475 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8476 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008477 if (carrierPrivilegeRules == null) {
8478 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8479 } else {
8480 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 } finally {
8483 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008484 }
fionaxua13278b2018-03-21 00:08:13 -07008485 }
8486
8487 @Override
8488 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008489 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 final Phone phone = getPhone(subId);
8494 if (phone == null) {
8495 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8496 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8497 }
8498 return phone.getCarrierIdListVersion();
8499 } finally {
8500 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008501 }
fionaxua13278b2018-03-21 00:08:13 -07008502 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008503
8504 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008505 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8506 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008508 mApp, subId, callingPackage, callingFeatureId,
8509 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008510 return -1;
8511 }
8512
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008520
8521 @Override
8522 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008523 TelephonyPermissions
8524 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008525 mApp, subId, "getCdmaRoamingMode");
8526
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
8535 @Override
8536 public boolean setCdmaRoamingMode(int subId, int mode) {
8537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8538 mApp, subId, "setCdmaRoamingMode");
8539
8540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
8545 }
8546 }
8547
8548 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008549 public int getCdmaSubscriptionMode(int subId) {
8550 TelephonyPermissions
8551 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8552 mApp, subId, "getCdmaSubscriptionMode");
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
8562 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008563 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8565 mApp, subId, "setCdmaSubscriptionMode");
8566
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
8569 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8570 } finally {
8571 Binder.restoreCallingIdentity(identity);
8572 }
8573 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008574
sqianc5eccab2018-10-19 18:46:41 -07008575 @Override
sqian8c685422019-02-22 15:55:18 -08008576 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008577 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008579 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8580 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008581 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8582 }
8583 final long identity = Binder.clearCallingIdentity();
8584 try {
sqian854d44b2018-12-12 16:48:18 -08008585 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8586 for (Phone phone: PhoneFactory.getPhones()) {
8587 if (phone.getEmergencyNumberTracker() != null
8588 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8589 emergencyNumberListInternal.put(
8590 phone.getSubId(),
8591 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8592 }
sqian11b7a0e2018-12-05 18:48:28 -08008593 }
sqian854d44b2018-12-12 16:48:18 -08008594 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
sqianc5eccab2018-10-19 18:46:41 -07008598 }
8599
8600 @Override
sqian8c685422019-02-22 15:55:18 -08008601 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008602 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008603 if (!exactMatch) {
8604 TelephonyPermissions
8605 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008606 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008607 }
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
sqian854d44b2018-12-12 16:48:18 -08008610 for (Phone phone: PhoneFactory.getPhones()) {
8611 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008612 && phone.getEmergencyNumberTracker()
8613 .isEmergencyNumber(number, exactMatch)) {
8614 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008615 }
sqian11b7a0e2018-12-05 18:48:28 -08008616 }
8617 return false;
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
sqianf4ca7ed2019-01-15 18:32:07 -08008623 /**
8624 * Update emergency number list for test mode.
8625 */
8626 @Override
8627 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8629 "updateEmergencyNumberListTestMode");
8630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 for (Phone phone: PhoneFactory.getPhones()) {
8634 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8635 if (tracker != null) {
8636 tracker.executeEmergencyNumberTestModeCommand(action, num);
8637 }
8638 }
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
8643
8644 /**
8645 * Get the full emergency number list for test mode.
8646 */
8647 @Override
8648 public List<String> getEmergencyNumberListTestMode() {
8649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8650 "getEmergencyNumberListTestMode");
8651
8652 final long identity = Binder.clearCallingIdentity();
8653 try {
8654 Set<String> emergencyNumbers = new HashSet<>();
8655 for (Phone phone: PhoneFactory.getPhones()) {
8656 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8657 if (tracker != null) {
8658 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8659 emergencyNumbers.add(num.getNumber());
8660 }
8661 }
8662 }
8663 return new ArrayList<>(emergencyNumbers);
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 }
8668
chen xud6b45bd2018-10-30 22:27:10 -07008669 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008670 public int getEmergencyNumberDbVersion(int subId) {
8671 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8672
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
8675 final Phone phone = getPhone(subId);
8676 if (phone == null) {
8677 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8678 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8679 }
8680 return phone.getEmergencyNumberDbVersion();
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
8683 }
8684 }
8685
8686 @Override
8687 public void notifyOtaEmergencyNumberDbInstalled() {
8688 enforceModifyPermission();
8689
8690 final long identity = Binder.clearCallingIdentity();
8691 try {
8692 for (Phone phone: PhoneFactory.getPhones()) {
8693 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8694 if (tracker != null) {
8695 tracker.updateOtaEmergencyNumberDatabase();
8696 }
8697 }
8698 } finally {
8699 Binder.restoreCallingIdentity(identity);
8700 }
8701 }
8702
8703 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008704 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008705 enforceActiveEmergencySessionPermission();
8706
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
8709 for (Phone phone: PhoneFactory.getPhones()) {
8710 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8711 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008712 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8713 }
8714 }
8715 } finally {
8716 Binder.restoreCallingIdentity(identity);
8717 }
8718 }
8719
8720 @Override
8721 public void resetOtaEmergencyNumberDbFilePath() {
8722 enforceActiveEmergencySessionPermission();
8723
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 for (Phone phone: PhoneFactory.getPhones()) {
8727 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8728 if (tracker != null) {
8729 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008730 }
8731 }
8732 } finally {
8733 Binder.restoreCallingIdentity(identity);
8734 }
8735 }
8736
8737 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008738 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8739 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8740 Phone phone = getPhone(subId);
8741 if (phone == null) {
8742 return null;
8743 }
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 UiccProfile profile = UiccController.getInstance()
8747 .getUiccProfileForPhone(phone.getPhoneId());
8748 if (profile != null) {
8749 return profile.getCertsFromCarrierPrivilegeAccessRules();
8750 }
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
8754 return null;
8755 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008756
8757 /**
8758 * Enable or disable a modem stack.
8759 */
8760 @Override
8761 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8762 enforceModifyPermission();
8763
8764 final long identity = Binder.clearCallingIdentity();
8765 try {
8766 Phone phone = PhoneFactory.getPhone(slotIndex);
8767 if (phone == null) {
8768 return false;
8769 } else {
8770 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8771 }
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
Michelecea4cf22018-12-21 15:00:11 -08008776
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008777 /**
8778 * Whether a modem stack is enabled or not.
8779 */
8780 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008781 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8782 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008783 Phone phone = PhoneFactory.getPhone(slotIndex);
8784 if (phone == null) return false;
8785
8786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008787 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8788 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008789 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8790 }
8791
8792 final long identity = Binder.clearCallingIdentity();
8793 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008794 try {
8795 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8796 } catch (NoSuchElementException ex) {
8797 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8798 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
Michelecea4cf22018-12-21 15:00:11 -08008804 @Override
Michele0ea7d782019-03-19 14:58:42 -07008805 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008806 enforceModifyPermission();
8807
8808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008811 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008812 .commit();
8813 } finally {
8814 Binder.restoreCallingIdentity(identity);
8815 }
8816 }
8817
8818 @Override
Michele0ea7d782019-03-19 14:58:42 -07008819 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008820 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008822 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8823 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008824 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008825 }
Michelecea4cf22018-12-21 15:00:11 -08008826
8827 final long identity = Binder.clearCallingIdentity();
8828 try {
Michele0ea7d782019-03-19 14:58:42 -07008829 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008830 } finally {
8831 Binder.restoreCallingIdentity(identity);
8832 }
8833 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008834
Michele0ea7d782019-03-19 14:58:42 -07008835 @TelephonyManager.IsMultiSimSupportedResult
8836 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008837 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8838 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8839 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008840 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8841 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008842 }
8843 // Check if the hardware supports multisim functionality. If usage of multisim is not
8844 // supported by the modem, indicate that it is restricted.
8845 PhoneCapability staticCapability =
8846 mPhoneConfigurationManager.getStaticPhoneCapability();
8847 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008848 loge("isMultiSimSupportedInternal: no static configuration available");
8849 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008850 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008851 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008852 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8853 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008854 }
8855 // Check if support of multiple SIMs is restricted by carrier
8856 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008857 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008858 }
8859
Michele0ea7d782019-03-19 14:58:42 -07008860 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008861 }
8862
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008863 /**
8864 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008865 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8866 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8867 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008868 * @param numOfSims number of active sims we want to switch to
8869 */
8870 @Override
8871 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008872 if (numOfSims == 1) {
8873 enforceModifyPermission();
8874 } else {
8875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8876 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8877 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008878 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008879
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008880 try {
Michele30b57b22019-03-01 12:01:14 -08008881 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008882 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008883 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8884 return;
8885 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008886 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
8890 }
8891
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008892 @Override
8893 public boolean isApplicationOnUicc(int subId, int appType) {
8894 enforceReadPrivilegedPermission("isApplicationOnUicc");
8895 Phone phone = getPhone(subId);
8896 if (phone == null) {
8897 return false;
8898 }
8899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 UiccCard uiccCard = phone.getUiccCard();
8902 if (uiccCard == null) {
8903 return false;
8904 }
8905 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8906 if (uiccProfile == null) {
8907 return false;
8908 }
8909 if (TelephonyManager.APPTYPE_SIM <= appType
8910 && appType <= TelephonyManager.APPTYPE_ISIM) {
8911 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8912 }
8913 return false;
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
8918
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008919 /**
chen xub4baa772019-04-03 10:23:41 -07008920 * Get whether making changes to modem configurations will trigger reboot.
8921 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008922 */
8923 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008924 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8925 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008927 mApp, subId, callingPackage, callingFeatureId,
8928 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008929 return false;
8930 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8934 } finally {
8935 Binder.restoreCallingIdentity(identity);
8936 }
8937 }
8938
Nathan Harold29f5f052019-02-15 13:41:57 -08008939 private void updateModemStateMetrics() {
8940 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8941 // TODO: check the state for each modem if the api is ready.
8942 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8943 }
8944
Pengquan Meng3889a572019-01-23 11:16:29 -08008945 @Override
8946 public int[] getSlotsMapping() {
8947 enforceReadPrivilegedPermission("getSlotsMapping");
8948
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8952 // All logical slots should have a mapping to a physical slot.
8953 int[] logicalSlotsMapping = new int[phoneCount];
8954 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8955 for (int i = 0; i < slotInfos.length; i++) {
8956 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8957 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8958 }
8959 }
8960 return logicalSlotsMapping;
8961 } finally {
8962 Binder.restoreCallingIdentity(identity);
8963 }
8964 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008965
8966 /**
8967 * Get the IRadio HAL Version
8968 */
8969 @Override
8970 public int getRadioHalVersion() {
8971 Phone phone = getDefaultPhone();
8972 if (phone == null) return -1;
8973 HalVersion hv = phone.getHalVersion();
8974 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8975 return hv.major * 100 + hv.minor;
8976 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008977
8978 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008979 * Get the current calling package name.
8980 * @return the current calling package name
8981 */
8982 @Override
8983 public String getCurrentPackageName() {
8984 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8985 }
8986
8987 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008988 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8989 * corresponding network requests on a subId.
8990 *
8991 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008992 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008993 * 2) APN is un-metered for this subscription, or
8994 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008995 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008996 *
8997 * @return whether data is allowed for a apn type.
8998 *
8999 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009000 */
9001 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009002 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009003 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9004 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009005
9006 // Now that all security checks passes, perform the operation as ourselves.
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 Phone phone = getPhone(subId);
9010 if (phone == null) return false;
9011
Jack Yu41407ee2019-05-13 16:54:09 -07009012 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009013 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
9019 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009020 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009021 enforceReadPrivilegedPermission("isApnMetered");
9022
9023 // Now that all security checks passes, perform the operation as ourselves.
9024 final long identity = Binder.clearCallingIdentity();
9025 try {
9026 Phone phone = getPhone(subId);
9027 if (phone == null) return true; // By default return true.
9028
Jack Yu41407ee2019-05-13 16:54:09 -07009029 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009030 } finally {
9031 Binder.restoreCallingIdentity(identity);
9032 }
9033 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009034
9035 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009036 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9037 int subscriptionId, IBooleanConsumer resultCallback) {
9038 enforceModifyPermission();
9039 long token = Binder.clearCallingIdentity();
9040 try {
9041 Phone phone = getPhone(subscriptionId);
9042 if (phone == null) {
9043 try {
9044 if (resultCallback != null) {
9045 resultCallback.accept(false);
9046 }
9047 } catch (RemoteException e) {
9048 // ignore
9049 }
9050 return;
9051 }
9052 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9053 Pair.create(specifiers, (x) -> {
9054 try {
9055 if (resultCallback != null) {
9056 resultCallback.accept(x);
9057 }
9058 } catch (RemoteException e) {
9059 // ignore
9060 }
9061 });
9062 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9063 } finally {
9064 Binder.restoreCallingIdentity(token);
9065 }
9066 }
9067
9068 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009069 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9070 TelephonyPermissions
9071 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9072 mApp, subId, "getSystemSelectionChannels");
9073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9074 final long identity = Binder.clearCallingIdentity();
9075 try {
9076 List<RadioAccessSpecifier> specifiers =
9077 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9078 null, subId, workSource);
9079 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9080 return specifiers;
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
9086 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009087 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009088 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009089 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9090 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9091 if (iccRecords == null) {
9092 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9093 return false;
9094 }
9095 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9096 }
9097
9098 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009099 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9100 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009101 if (callingPackage == null) {
9102 callingPackage = getCurrentPackageName();
9103 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009104 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9105 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009106 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9107 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009108 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9109 }
9110 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9111 Intent intent = new Intent();
9112 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9113 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9114 // Bring up choose default SMS subscription dialog right now
9115 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9116 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9117 mApp.startActivity(intent);
9118 }
chen xud5ca2d52019-05-28 15:20:57 -07009119
9120 @Override
9121 public String getMmsUAProfUrl(int subId) {
9122 //TODO investigate if this API should require proper permission check in R b/133791609
9123 final long identity = Binder.clearCallingIdentity();
9124 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009125 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9126 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9127 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9128 return carrierUAProfUrl;
9129 }
chen xud5ca2d52019-05-28 15:20:57 -07009130 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9131 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @Override
9138 public String getMmsUserAgent(int subId) {
9139 //TODO investigate if this API should require proper permission check in R b/133791609
9140 final long identity = Binder.clearCallingIdentity();
9141 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009142 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9143 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9144 if (!TextUtils.isEmpty(carrierUserAgent)) {
9145 return carrierUserAgent;
9146 }
chen xud5ca2d52019-05-28 15:20:57 -07009147 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9148 .getString(com.android.internal.R.string.config_mms_user_agent);
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
Jack Yub07d4972019-05-28 16:12:25 -07009153
9154 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009155 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9156 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 Phone phone = getPhone(subscriptionId);
9161 if (phone == null) return false;
9162
9163 switch (policy) {
9164 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9165 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9166 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9167 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9168 default:
9169 throw new IllegalArgumentException(policy + " is not a valid policy");
9170 }
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
9176 @Override
9177 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9178 boolean enabled) {
9179 enforceModifyPermission();
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 Phone phone = getPhone(subscriptionId);
9184 if (phone == null) return;
9185
9186 switch (policy) {
9187 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9188 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9189 break;
9190 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9191 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9192 break;
9193 default:
9194 throw new IllegalArgumentException(policy + " is not a valid policy");
9195 }
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009201 /**
Hall Liub48cf452020-09-25 11:13:49 -07009202 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009203 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9204 * otherwise.
9205 */
9206 @Override
9207 public void setCepEnabled(boolean isCepEnabled) {
9208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9209
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
9212 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9213 for (Phone phone : PhoneFactory.getPhones()) {
9214 Phone defaultPhone = phone.getImsPhone();
9215 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9216 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9217 ImsPhoneCallTracker imsPhoneCallTracker =
9218 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9219 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9220 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9221 + imsPhone.getMsisdn());
9222 }
9223 }
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
9227 }
allenwtsu46dcc572020-01-08 18:24:03 +08009228
9229 /**
9230 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9231 *
9232 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9233 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9234 * before being read.
9235 */
9236 @Override
9237 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9238 isCompressed) {
9239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9240 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009241 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9242 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9243 }
9244 if (!isImsAvailableOnDevice()) {
9245 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9246 "IMS not available on device.");
9247 }
9248
9249 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009250 try {
Hui Wang068ab862020-10-31 05:12:53 +00009251 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009254 }
9255 }
zoey chenf95ca592019-12-30 16:11:23 +08009256
9257 @Override
9258 public boolean isIccLockEnabled(int subId) {
9259 enforceReadPrivilegedPermission("isIccLockEnabled");
9260
9261 // Now that all security checks passes, perform the operation as ourselves.
9262 final long identity = Binder.clearCallingIdentity();
9263 try {
9264 Phone phone = getPhone(subId);
9265 if (phone != null && phone.getIccCard() != null) {
9266 return phone.getIccCard().getIccLockEnabled();
9267 } else {
9268 return false;
9269 }
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
9275 /**
zoey chene02881a2019-12-30 16:11:23 +08009276 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009277 *
zoey chene02881a2019-12-30 16:11:23 +08009278 * @return an integer representing the status of IccLock enabled or disabled in the following
9279 * three cases:
9280 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9281 * successfully.
9282 * - Positive number and zero for remaining password attempts.
9283 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009284 *
9285 */
9286 @Override
9287 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9288 enforceModifyPermission();
9289
9290 Phone phone = getPhone(subId);
9291 if (phone == null) {
9292 return 0;
9293 }
9294 // Now that all security checks passes, perform the operation as ourselves.
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
9297 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9298 new Pair<Boolean, String>(enabled, password), phone, null);
9299 return attemptsRemaining;
9300
9301 } catch (Exception e) {
9302 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9303 } finally {
9304 Binder.restoreCallingIdentity(identity);
9305 }
9306 return 0;
9307 }
9308
9309 /**
9310 * Change the ICC password used in ICC pin lock.
9311 *
zoey chene02881a2019-12-30 16:11:23 +08009312 * @return an integer representing the status of IccLock changed in the following three cases:
9313 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9314 * - Positive number and zero for remaining password attempts.
9315 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009316 *
9317 */
9318 @Override
9319 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9320 enforceModifyPermission();
9321
9322 Phone phone = getPhone(subId);
9323 if (phone == null) {
9324 return 0;
9325 }
9326 // Now that all security checks passes, perform the operation as ourselves.
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9330 new Pair<String, String>(oldPassword, newPassword), phone, null);
9331 return attemptsRemaining;
9332
9333 } catch (Exception e) {
9334 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 return 0;
9339 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009340
Peter Wangdafb9ac2020-01-15 14:13:38 -08009341 /**
9342 * Request for receiving user activity notification
9343 */
9344 @Override
9345 public void requestUserActivityNotification() {
9346 if (!mNotifyUserActivity.get()
9347 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9348 mNotifyUserActivity.set(true);
9349 }
9350 }
9351
9352 /**
9353 * Called when userActivity is signalled in the power manager.
9354 * This is safe to call from any thread, with any window manager locks held or not.
9355 */
9356 @Override
9357 public void userActivity() {
9358 // ***************************************
9359 // * Inherited from PhoneWindowManager *
9360 // ***************************************
9361 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9362 // WITH ITS LOCKS HELD.
9363 //
9364 // This code must be VERY careful about the locks
9365 // it acquires.
9366 // In fact, the current code acquires way too many,
9367 // and probably has lurking deadlocks.
9368
9369 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9370 throw new SecurityException("Only the OS may call notifyUserActivity()");
9371 }
9372
9373 if (mNotifyUserActivity.getAndSet(false)) {
9374 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9375 USER_ACTIVITY_NOTIFICATION_DELAY);
9376 }
9377 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009378
Malcolm Chen884180b2020-04-13 11:59:40 -07009379 @Override
9380 public boolean canConnectTo5GInDsdsMode() {
9381 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9382 }
Jack Yud10cdd42020-09-28 20:28:01 -07009383
9384 @Override
9385 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9386 String callingFeatureId) {
9387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9388 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9389 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9390 }
9391
9392 Phone phone = getPhone(subId);
9393 if (phone == null) {
9394 throw new RuntimeException("phone is not available");
9395 }
9396 // Now that all security checks passes, perform the operation as ourselves.
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 return phone.getEquivalentHomePlmns();
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009404
Hui Wang0866fcc2020-10-12 12:14:23 -07009405 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009406 public boolean isRadioInterfaceCapabilitySupported(
9407 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009408 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009409 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9410 if (radioInterfaceCapabilities == null) {
9411 throw new RuntimeException("radio interface capabilities are not available");
9412 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009413 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009414 }
9415 }
9416
9417 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009418 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9419 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009420 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9421 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9422 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9423 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9424 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009425 if (DBG) {
9426 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9427 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9428 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9429 }
9430
9431 if (!SubscriptionManager.isValidSubscriptionId(subId)
9432 || appType < TelephonyManager.APPTYPE_UNKNOWN
9433 || appType > TelephonyManager.APPTYPE_ISIM
9434 || nafUrl == null || securityProtocol == null || callback == null) {
9435 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9436 if (callback != null) {
9437 try {
9438 callback.onAuthenticationFailure(
9439 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9440 } catch (RemoteException exception) {
9441 log("Fail to notify onAuthenticationFailure due to " + exception);
9442 }
9443 return;
9444 }
9445 }
9446
9447 final long token = Binder.clearCallingIdentity();
9448 try {
9449 getGbaManager(subId).bootstrapAuthenticationRequest(
9450 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9451 forceBootStrapping, callback));
9452 } finally {
9453 Binder.restoreCallingIdentity(token);
9454 }
9455 }
9456
Jack Nudelman24d51a52020-11-24 12:08:04 -08009457 /**
9458 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9459 * requested radio power state will actually be set. See {@link
9460 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9461 *
9462 * @param subId the subscription ID of the phone requesting to set the radio power state.
9463 * @param enable {@code true} if trying to turn radio on.
9464 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9465 * false}.
9466 */
9467 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9468 Phone phone = getPhone(subId);
9469 if (phone != null) {
9470 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9471 return true;
9472 }
9473 return false;
9474 }
9475
9476 private int handleDataThrottlingRequest(int subId,
9477 DataThrottlingRequest dataThrottlingRequest) {
9478 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9479 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9480 if (!setRadioPowerForThermal(subId, true)) {
9481 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9482 }
9483
9484 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9485
9486 int thermalMitigationResult =
9487 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9488 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9489 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9490 }
9491 return thermalMitigationResult;
9492 }
9493
9494 /**
9495 * Thermal mitigation request to control functionalities at modem.
9496 *
9497 * @param subId the id of the subscription.
9498 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9499 *
9500 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9501 */
9502 @Override
9503 @ThermalMitigationResult
9504 public int sendThermalMitigationRequest(
9505 int subId,
9506 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9507 enforceModifyPermission();
9508
9509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9510 final long identity = Binder.clearCallingIdentity();
9511
9512 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9513 try {
9514 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9515 switch (thermalMitigationAction) {
9516 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9517 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009518 handleDataThrottlingRequest(subId,
9519 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009520 break;
9521 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9522 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9523 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9524 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9525 }
9526
9527 // Ensure that radio is on. If not able to power on due to phone being
9528 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9529 if (!setRadioPowerForThermal(subId, true)) {
9530 thermalMitigationResult =
9531 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9532 break;
9533 }
9534
9535 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9536 false);
9537 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9538 break;
9539 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9540 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9541 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9542 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9543 }
9544
9545 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9546 if (registry != null) {
9547 TelephonyConnectionService service =
9548 registry.getTelephonyConnectionService();
9549 Phone phone = getPhone(subId);
9550 if (phone == null) {
9551 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009552 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009553 break;
9554 }
9555
9556 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009557 != TelephonyManager.CALL_STATE_IDLE
9558 || phone.isInEmergencySmsMode() || phone.isInEcm()
9559 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009560 String errorMessage = "Phone state is not valid. call state = "
9561 + PhoneConstantConversions.convertCallState(phone.getState())
9562 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9563 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9564 errorMessage += service == null
9565 ? " TelephonyConnectionService is null"
9566 : " isEmergencyCallPending = "
9567 + service.isEmergencyCallPending();
9568 Log.e(LOG_TAG, errorMessage);
9569 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009570 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009571 break;
9572 }
9573 } else {
9574 thermalMitigationResult =
9575 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9576 break;
9577 }
9578
9579 // Turn radio off. If not able to power off due to phone being unavailable,
9580 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9581 if (!setRadioPowerForThermal(subId, false)) {
9582 thermalMitigationResult =
9583 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9584 break;
9585 }
9586 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009587 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009588 break;
9589 default:
9590 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9591 + "not exist. Requested action: " + thermalMitigationAction);
9592 }
9593 } catch (IllegalArgumentException e) {
9594 throw e;
9595 } catch (Exception e) {
9596 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9597 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9598 } finally {
9599 Binder.restoreCallingIdentity(identity);
9600 }
9601
9602 if (DBG) {
9603 log("thermalMitigationRequest returning with thermalMitigationResult: "
9604 + thermalMitigationResult);
9605 }
9606
9607 return thermalMitigationResult;
9608 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009609
9610 /**
9611 * Set the GbaService Package Name that Telephony will bind to.
9612 *
9613 * @param subId The sim that the GbaService is associated with.
9614 * @param packageName The name of the package to be replaced with.
9615 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9616 */
9617 @Override
9618 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9619 enforceModifyPermission();
9620
9621 final long identity = Binder.clearCallingIdentity();
9622 try {
9623 return getGbaManager(subId).overrideServicePackage(packageName);
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627 }
9628
9629 /**
9630 * Return the package name of the currently bound GbaService.
9631 *
9632 * @param subId The sim that the GbaService is associated with.
9633 * @return the package name of the GbaService configuration, null if GBA is not supported.
9634 */
9635 @Override
9636 public String getBoundGbaService(int subId) {
9637 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9638
9639 final long identity = Binder.clearCallingIdentity();
9640 try {
9641 return getGbaManager(subId).getServicePackage();
9642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
9646
9647 /**
9648 * Set the release time for telephony to unbind GbaService.
9649 *
9650 * @param subId The sim that the GbaService is associated with.
9651 * @param interval The release time to unbind GbaService by millisecond.
9652 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9653 */
9654 @Override
9655 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9656 enforceModifyPermission();
9657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 return getGbaManager(subId).overrideReleaseTime(interval);
9661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 /**
9667 * Return the release time for telephony to unbind GbaService.
9668 *
9669 * @param subId The sim that the GbaService is associated with.
9670 * @return The release time to unbind GbaService by millisecond.
9671 */
9672 @Override
9673 public int getGbaReleaseTime(int subId) {
9674 enforceReadPrivilegedPermission("getGbaReleaseTime");
9675
9676 final long identity = Binder.clearCallingIdentity();
9677 try {
9678 return getGbaManager(subId).getReleaseTime();
9679 } finally {
9680 Binder.restoreCallingIdentity(identity);
9681 }
9682 }
9683
9684 private GbaManager getGbaManager(int subId) {
9685 GbaManager instance = GbaManager.getInstance(subId);
9686 if (instance == null) {
9687 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9688 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9689 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9690 }
9691 return instance;
9692 }
Hui Wang068ab862020-10-31 05:12:53 +00009693
9694 /**
9695 * indicate whether the device and the carrier can support
9696 * RCS VoLTE single registration.
9697 */
9698 @Override
9699 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009700 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9701 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9702 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9703 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009704
9705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9706 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9707 }
9708
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9712 if (rpm != null) {
9713 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9714 }
9715 return false;
9716 } finally {
9717 Binder.restoreCallingIdentity(identity);
9718 }
9719 }
9720
9721 /**
9722 * Register RCS provisioning callback.
9723 */
9724 @Override
9725 public void registerRcsProvisioningChangedCallback(int subId,
9726 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009727 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9728 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9729 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9730 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009731
9732 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9733 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9734 }
9735 if (!isImsAvailableOnDevice()) {
9736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9737 "IMS not available on device.");
9738 }
9739
9740 final long identity = Binder.clearCallingIdentity();
9741 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009742 if (!RcsProvisioningMonitor.getInstance()
9743 .registerRcsProvisioningChangedCallback(subId, callback)) {
9744 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9745 "Service not available for the subscription.");
9746 }
Hui Wang068ab862020-10-31 05:12:53 +00009747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
9751
9752 /**
9753 * Unregister RCS provisioning callback.
9754 */
9755 @Override
9756 public void unregisterRcsProvisioningChangedCallback(int subId,
9757 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009758 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9759 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9760 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9761 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009762
9763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9764 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9765 }
9766 if (!isImsAvailableOnDevice()) {
9767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9768 "IMS not available on device.");
9769 }
9770
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009773 RcsProvisioningMonitor.getInstance()
9774 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 /**
9781 * trigger RCS reconfiguration.
9782 */
9783 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009784 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9785 "triggerRcsReconfiguration",
9786 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009787
9788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9790 }
9791 if (!isImsAvailableOnDevice()) {
9792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9793 "IMS not available on device.");
9794 }
9795
9796 final long identity = Binder.clearCallingIdentity();
9797 try {
9798 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 }
9803
9804 /**
9805 * Provide the client configuration parameters of the RCS application.
9806 */
9807 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009808 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9809 "setRcsClientConfiguration",
9810 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009811
9812 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9813 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9814 }
9815 if (!isImsAvailableOnDevice()) {
9816 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9817 "IMS not available on device.");
9818 }
9819
9820 final long identity = Binder.clearCallingIdentity();
9821
9822 try {
9823 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9824 if (configBinder == null) {
9825 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9826 } else {
9827 configBinder.setRcsClientConfiguration(rcc);
9828 }
9829 } catch (RemoteException e) {
9830 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9831 } finally {
9832 Binder.restoreCallingIdentity(identity);
9833 }
9834 }
9835
9836 /**
Hui Wang19a21872021-02-19 20:45:36 -08009837 * Enables or disables the test mode for RCS VoLTE single registration.
9838 */
9839 @Override
9840 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9842 "setRcsSingleRegistrationTestModeEnabled");
9843
9844 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9845 }
9846
9847 /**
9848 * Gets the test mode for RCS VoLTE single registration.
9849 */
9850 @Override
9851 public boolean getRcsSingleRegistrationTestModeEnabled() {
9852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9853 "getRcsSingleRegistrationTestModeEnabled");
9854
9855 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9856 }
9857
9858 /**
Hui Wang068ab862020-10-31 05:12:53 +00009859 * Overrides the config of RCS VoLTE single registration enabled for the device.
9860 */
9861 @Override
9862 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9864 "setDeviceSingleRegistrationEnabledOverride");
9865 enforceModifyPermission();
9866
9867 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9868 : Boolean.parseBoolean(enabledStr);
9869 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009870 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009871 }
9872
9873 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009874 * Sends a device to device communication message. Only usable via shell.
9875 * @param message message to send.
9876 * @param value message value.
9877 */
9878 @Override
9879 public void sendDeviceToDeviceMessage(int message, int value) {
9880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9881 "setCarrierSingleRegistrationEnabledOverride");
9882 enforceModifyPermission();
9883
9884 final long identity = Binder.clearCallingIdentity();
9885 try {
9886 TelephonyConnectionService service =
9887 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9888 if (service == null) {
9889 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9890 return;
9891 }
9892 service.sendTestDeviceToDeviceMessage(message, value);
9893 } finally {
9894 Binder.restoreCallingIdentity(identity);
9895 }
9896 }
9897
9898
9899 /**
Hui Wang068ab862020-10-31 05:12:53 +00009900 * Gets the config of RCS VoLTE single registration enabled for the device.
9901 */
9902 @Override
9903 public boolean getDeviceSingleRegistrationEnabled() {
9904 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9905 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9906 }
9907
9908 /**
9909 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9910 */
9911 @Override
9912 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9914 "setCarrierSingleRegistrationEnabledOverride");
9915 enforceModifyPermission();
9916
9917 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9918 : Boolean.parseBoolean(enabledStr);
9919 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9920 subId, enabled);
9921 }
9922
9923 /**
9924 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9925 */
9926 @Override
9927 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9928 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9929 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9930 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009931
9932 /**
9933 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9934 * their mobile plan.
9935 */
9936 @Override
9937 public String getMobileProvisioningUrl() {
9938 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 return getDefaultPhone().getMobileProvisioningUrl();
9942 } finally {
9943 Binder.restoreCallingIdentity(identity);
9944 }
9945 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009946
James.cf Linbcdf8b32021-01-14 16:44:13 +08009947 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009948 * Get the EAB contact from the EAB database.
9949 */
9950 @Override
9951 public String getContactFromEab(String contact) {
9952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9953 enforceModifyPermission();
9954 final long identity = Binder.clearCallingIdentity();
9955 try {
9956 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
9961
9962 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009963 * Remove the EAB contacts from the EAB database.
9964 */
9965 @Override
9966 public int removeContactFromEab(int subId, String contacts) {
9967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9968 enforceModifyPermission();
9969 final long identity = Binder.clearCallingIdentity();
9970 try {
9971 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
9976
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009977 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009978 public boolean getDeviceUceEnabled() {
9979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9980 final long identity = Binder.clearCallingIdentity();
9981 try {
9982 return mApp.getDeviceUceEnabled();
9983 } finally {
9984 Binder.restoreCallingIdentity(identity);
9985 }
9986 }
9987
9988 @Override
9989 public void setDeviceUceEnabled(boolean isEnabled) {
9990 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 mApp.setDeviceUceEnabled(isEnabled);
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
9998
9999 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010000 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10001 String callingPackage) {
10002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10003 mApp, subId, "setSignalStrengthUpdateRequest");
10004
10005 final int callingUid = Binder.getCallingUid();
10006 // Verify that tha callingPackage belongs to the calling UID
10007 mApp.getSystemService(AppOpsManager.class)
10008 .checkPackage(callingUid, callingPackage);
10009
10010 validateSignalStrengthUpdateRequest(request, callingUid);
10011
10012 final long identity = Binder.clearCallingIdentity();
10013 try {
10014 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10015 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10016
10017 if (result instanceof IllegalStateException) {
10018 throw (IllegalStateException) result;
10019 }
10020 } finally {
10021 Binder.restoreCallingIdentity(identity);
10022 }
10023 }
10024
10025 @Override
10026 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10027 String callingPackage) {
10028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10029 mApp, subId, "clearSignalStrengthUpdateRequest");
10030
10031 final int callingUid = Binder.getCallingUid();
10032 // Verify that tha callingPackage belongs to the calling UID
10033 mApp.getSystemService(AppOpsManager.class)
10034 .checkPackage(callingUid, callingPackage);
10035
10036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10039 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10040
10041 if (result instanceof IllegalStateException) {
10042 throw (IllegalStateException) result;
10043 }
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
10047 }
10048
10049 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10050 int callingUid) {
10051 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10052 // phone/system process do not have further restriction on request
10053 return;
10054 }
10055
10056 // Applications has restrictions on how to use the request:
10057 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10058 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10059 // This is not system caller which has been checked above
10060 throw new IllegalArgumentException(
10061 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10062 }
10063
10064 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10065 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10066 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10067 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10068 || info.isEnabled()) {
10069 throw new IllegalArgumentException(
10070 "Only system can set hide fields in SignalThresholdInfo");
10071 }
10072
10073 // Thresholds length for each RAN need in range. This has been validated in
10074 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10075 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10076 final int[] thresholds = info.getThresholds();
10077 Objects.requireNonNull(thresholds);
10078 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10079 || thresholds.length
10080 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10081 throw new IllegalArgumentException(
10082 "thresholds length is out of range: " + thresholds.length);
10083 }
10084 }
10085 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010086
10087 /**
10088 * Prepare TelephonyManager for an unattended reboot. The reboot is
10089 * required to be done shortly after the API is invoked.
10090 */
10091 @Override
10092 @TelephonyManager.PrepareUnattendedRebootResult
10093 public int prepareForUnattendedReboot() {
10094 enforceRebootPermission();
10095
10096 final long identity = Binder.clearCallingIdentity();
10097 try {
10098 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10099 } finally {
10100 Binder.restoreCallingIdentity(identity);
10101 }
10102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010103}