blob: d2d97cfae66d163edcfe9dde0736fc58e242b63d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Brad Ebinger4df7e242021-02-17 23:23:21 +000024import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080026import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070027import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080055import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080068import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebingerd4c5bde2021-02-12 06:18:28 +0000113import android.telephony.ims.RcsContactUceCapability;
Brad Ebinger774ba362019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800162import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700163import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700164import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800166import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800167import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700169import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700171import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800172import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700173import com.android.internal.telephony.imsphone.ImsPhone;
174import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800175import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900176import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800178import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700181import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800186import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700187import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700188import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800192import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700193import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700194import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800195import com.android.services.telephony.TelecomAccountRegistry;
196import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800197import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800198
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700199import java.io.FileDescriptor;
200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800211import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800212import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
214/**
215 * Implementation of the ITelephony interface.
216 */
Santos Cordon117fee72014-05-16 17:56:12 -0700217public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 private static final String LOG_TAG = "PhoneInterfaceManager";
219 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
220 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 // Message codes used with mMainThreadHandler
224 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700225 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
226 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227 private static final int CMD_OPEN_CHANNEL = 9;
228 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
229 private static final int CMD_CLOSE_CHANNEL = 11;
230 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800231 private static final int CMD_NV_READ_ITEM = 13;
232 private static final int EVENT_NV_READ_ITEM_DONE = 14;
233 private static final int CMD_NV_WRITE_ITEM = 15;
234 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
235 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
236 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700237 private static final int CMD_RESET_MODEM_CONFIG = 19;
238 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800239 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
240 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800241 private static final int CMD_SEND_ENVELOPE = 25;
242 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000243 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
244 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700245 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
246 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
247 private static final int CMD_EXCHANGE_SIM_IO = 31;
248 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800249 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
250 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700251 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
252 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700253 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
254 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700255 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
256 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
257 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700259 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
260 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
261 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
262 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700263 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800264 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
265 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000266 private static final int CMD_SWITCH_SLOTS = 50;
267 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700268 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
269 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
270 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
271 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
272 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
273 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
274 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
275 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700276 private static final int CMD_GET_ALL_CELL_INFO = 60;
277 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
278 private static final int CMD_GET_CELL_LOCATION = 62;
279 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700280 private static final int CMD_MODEM_REBOOT = 64;
281 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700282 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
283 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800284 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
285 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700286 private static final int CMD_GET_MODEM_STATUS = 70;
287 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700288 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
289 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700290 private static final int CMD_ERASE_MODEM_CONFIG = 74;
291 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800292 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
293 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
294 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
295 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800296 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
297 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800298 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800299 private static final int CMD_GET_CALL_FORWARDING = 83;
300 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
301 private static final int CMD_SET_CALL_FORWARDING = 85;
302 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
303 private static final int CMD_GET_CALL_WAITING = 87;
304 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
305 private static final int CMD_SET_CALL_WAITING = 89;
306 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700307 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
308 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
309 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
310 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700311 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
312 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800313 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
314 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800315 private static final int CMD_SET_DATA_THROTTLING = 99;
316 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800317 private static final int CMD_SET_SIM_POWER = 101;
318 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800319 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
320 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
321 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
322 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800323 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
324 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000325 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800327 // Parameters of select command.
328 private static final int SELECT_COMMAND = 0xA4;
329 private static final int SELECT_P1 = 0x04;
330 private static final int SELECT_P2 = 0;
331 private static final int SELECT_P3 = 0x10;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 /** The singleton instance. */
334 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800335 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800339 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700340 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private AppOpsManager mAppOps;
342 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800343 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800344 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700345 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800346 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
Peter Wangdafb9ac2020-01-15 14:13:38 -0800348 /** User Activity */
349 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
351
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700352 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
353
Derek Tan97ebb422014-09-05 16:55:38 -0700354 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
355 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800356 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800357 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700358
Michelecea4cf22018-12-21 15:00:11 -0800359 // String to store multi SIM allowed
360 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
361
Derek Tan740e1672017-06-27 14:56:27 -0700362 // The AID of ISD-R.
363 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
364
yinxub1bed742017-04-17 11:45:04 -0700365 private NetworkScanRequestTracker mNetworkScanRequestTracker;
366
David Kelly5e06a7f2018-03-12 14:10:59 +0000367 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
368 private static final int MANUFACTURER_CODE_LENGTH = 8;
369
Jack Nudelman24d51a52020-11-24 12:08:04 -0800370 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
371
Derek Tan89e89d42014-07-08 17:00:10 -0700372 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700373 * Experiment flag to enable erase modem config on reset network, default value is false
374 */
375 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
376 "reset_network_erase_modem_config_enabled";
377
Rambo Wang0f050d82021-02-12 11:43:36 -0800378 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
379
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700380 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700381 * A request object to use for transmitting data to an ICC.
382 */
383 private static final class IccAPDUArgument {
384 public int channel, cla, command, p1, p2, p3;
385 public String data;
386
387 public IccAPDUArgument(int channel, int cla, int command,
388 int p1, int p2, int p3, String data) {
389 this.channel = channel;
390 this.cla = cla;
391 this.command = command;
392 this.p1 = p1;
393 this.p2 = p2;
394 this.p3 = p3;
395 this.data = data;
396 }
397 }
398
399 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700400 * A request object to use for transmitting data to an ICC.
401 */
402 private static final class ManualNetworkSelectionArgument {
403 public OperatorInfo operatorInfo;
404 public boolean persistSelection;
405
406 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
407 this.operatorInfo = operatorInfo;
408 this.persistSelection = persistSelection;
409 }
410 }
411
412 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
414 * request after sending. The main thread will notify the request when it is complete.
415 */
416 private static final class MainThreadRequest {
417 /** The argument to use for the request */
418 public Object argument;
419 /** The result of the request that is run on the main thread */
420 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800421 // The subscriber id that this request applies to. Defaults to
422 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
423 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Nathan Harold92bed182018-10-12 18:16:49 -0700425 // In cases where subId is unavailable, the caller needs to specify the phone.
426 public Phone phone;
427
vagdeviaf9a5b92018-08-15 16:01:53 -0700428 public WorkSource workSource;
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 public MainThreadRequest(Object argument) {
431 this.argument = argument;
432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800433
Nathan Harold92bed182018-10-12 18:16:49 -0700434 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
435 this.argument = argument;
436 if (phone != null) {
437 this.phone = phone;
438 }
439 this.workSource = workSource;
440 }
441
vagdeviaf9a5b92018-08-15 16:01:53 -0700442 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800444 if (subId != null) {
445 this.subId = subId;
446 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700447 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 }
450
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800451 private static final class IncomingThirdPartyCallArgs {
452 public final ComponentName component;
453 public final String callId;
454 public final String callerDisplayName;
455
456 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
457 String callerDisplayName) {
458 this.component = component;
459 this.callId = callId;
460 this.callerDisplayName = callerDisplayName;
461 }
462 }
463
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 /**
465 * A handler that processes messages on the main thread in the phone process. Since many
466 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
467 * inbound binder threads to the main thread in the phone process. The Binder thread
468 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
469 * on, which will be notified when the operation completes and will contain the result of the
470 * request.
471 *
472 * <p>If a MainThreadRequest object is provided in the msg.obj field,
473 * note that request.result must be set to something non-null for the calling thread to
474 * unblock.
475 */
476 private final class MainThreadHandler extends Handler {
477 @Override
478 public void handleMessage(Message msg) {
479 MainThreadRequest request;
480 Message onCompleted;
481 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800484 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
486 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 case CMD_HANDLE_USSD_REQUEST: {
488 request = (MainThreadRequest) msg.obj;
489 final Phone phone = getPhoneFromRequest(request);
490 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
491 String ussdRequest = ussdObject.first;
492 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700493
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 if (!isUssdApiAllowed(request.subId)) {
495 // Carrier does not support use of this API, return failure.
496 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
497 UssdResponse response = new UssdResponse(ussdRequest, null);
498 Bundle returnData = new Bundle();
499 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
500 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700501
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 request.result = true;
503 notifyRequester(request);
504 return;
505 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700506
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 try {
508 request.result = phone != null
509 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
510 } catch (CallStateException cse) {
511 request.result = false;
512 }
513 // Wake up the requesting thread
514 notifyRequester(request);
515 break;
pkanwar32d516d2016-10-14 19:37:38 -0700516 }
517
Yorke Lee716f67e2015-06-17 15:39:16 -0700518 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 final Phone phone = getPhoneFromRequest(request);
521 request.result = phone != null ?
522 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
523 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800532 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 if (uiccCard == null) {
534 loge("iccTransmitApduLogicalChannel: No UICC");
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
539 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 iccArgument.channel, iccArgument.cla, iccArgument.command,
542 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 break;
546
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 ar = (AsyncResult) msg.obj;
549 request = (MainThreadRequest) ar.userObj;
550 if (ar.exception == null && ar.result != null) {
551 request.result = ar.result;
552 } else {
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
554 if (ar.result == null) {
555 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800556 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800558 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 } else {
560 loge("iccTransmitApduLogicalChannel: Unknown exception");
561 }
562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
568 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800569 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (uiccCard == null) {
571 loge("iccTransmitApduBasicChannel: No UICC");
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
576 request);
577 uiccCard.iccTransmitApduBasicChannel(
578 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
579 iccArgument.p3, iccArgument.data, onCompleted);
580 }
581 break;
582
583 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
586 if (ar.exception == null && ar.result != null) {
587 request.result = ar.result;
588 } else {
589 request.result = new IccIoResult(0x6F, 0, (byte[])null);
590 if (ar.result == null) {
591 loge("iccTransmitApduBasicChannel: Empty response");
592 } else if (ar.exception instanceof CommandException) {
593 loge("iccTransmitApduBasicChannel: CommandException: " +
594 ar.exception);
595 } else {
596 loge("iccTransmitApduBasicChannel: Unknown exception");
597 }
598 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 break;
601
602 case CMD_EXCHANGE_SIM_IO:
603 request = (MainThreadRequest) msg.obj;
604 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800605 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 if (uiccCard == null) {
607 loge("iccExchangeSimIO: No UICC");
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 } else {
611 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
612 request);
613 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
614 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
615 iccArgument.data, onCompleted);
616 }
617 break;
618
619 case EVENT_EXCHANGE_SIM_IO_DONE:
620 ar = (AsyncResult) msg.obj;
621 request = (MainThreadRequest) ar.userObj;
622 if (ar.exception == null && ar.result != null) {
623 request.result = ar.result;
624 } else {
625 request.result = new IccIoResult(0x6f, 0, (byte[])null);
626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 break;
629
Derek Tan4d5e5c12014-02-04 11:54:58 -0800630 case CMD_SEND_ENVELOPE:
631 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800632 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 if (uiccCard == null) {
634 loge("sendEnvelopeWithStatus: No UICC");
635 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 } else {
638 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
639 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
640 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 break;
642
643 case EVENT_SEND_ENVELOPE_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700649 request.result = new IccIoResult(0x6F, 0, (byte[])null);
650 if (ar.result == null) {
651 loge("sendEnvelopeWithStatus: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("sendEnvelopeWithStatus: CommandException: " +
654 ar.exception);
655 } else {
656 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
657 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 break;
661
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 case CMD_OPEN_CHANNEL:
663 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800664 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800665 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 if (uiccCard == null) {
667 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800668 request.result = new IccOpenLogicalChannelResponse(-1,
669 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 } else {
672 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800673 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
674 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case EVENT_OPEN_CHANNEL_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 int[] result = (int[]) ar.result;
684 int channelId = result[0];
685 byte[] selectResponse = null;
686 if (result.length > 1) {
687 selectResponse = new byte[result.length - 1];
688 for (int i = 1; i < result.length; ++i) {
689 selectResponse[i - 1] = (byte) result[i];
690 }
691 }
692 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700693 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 if (ar.result == null) {
696 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 if (ar.exception != null) {
699 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
700 }
701
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700703 if (ar.exception instanceof CommandException) {
704 CommandException.Error error =
705 ((CommandException) (ar.exception)).getCommandError();
706 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700708 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(
713 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700715 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
719 case CMD_CLOSE_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800721 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 if (uiccCard == null) {
723 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900724 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 } else {
727 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
728 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
729 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 break;
731
732 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800733 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
734 break;
735
736 case CMD_NV_READ_ITEM:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
740 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
743 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 ar = (AsyncResult) msg.obj;
745 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800746 if (ar.exception == null && ar.result != null) {
747 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800749 request.result = "";
750 if (ar.result == null) {
751 loge("nvReadItem: Empty response");
752 } else if (ar.exception instanceof CommandException) {
753 loge("nvReadItem: CommandException: " +
754 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800756 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
Jake Hambye994d462014-02-03 13:10:13 -0800762 case CMD_NV_WRITE_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
765 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700767 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800768 break;
769
770 case EVENT_NV_WRITE_ITEM_DONE:
771 handleNullReturnEvent(msg, "nvWriteItem");
772 break;
773
774 case CMD_NV_WRITE_CDMA_PRL:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800777 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
780 case EVENT_NV_WRITE_CDMA_PRL_DONE:
781 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
782 break;
783
chen xu6dac5ab2018-10-26 17:39:23 -0700784 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800785 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700786 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
chen xu6dac5ab2018-10-26 17:39:23 -0700790 case EVENT_RESET_MODEM_CONFIG_DONE:
791 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700794 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
797 request);
798 Phone phone = getPhoneFromRequest(request);
799 if (phone != null) {
800 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
801 } else {
802 loge("isNRDualConnectivityEnabled: No phone object");
803 request.result = false;
804 notifyRequester(request);
805 }
806 break;
807 }
808
809 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 // request.result must be set to something non-null
816 // for the calling thread to unblock
817 if (request.result != null) {
818 request.result = ar.result;
819 } else {
820 request.result = false;
821 }
822 if (ar.result == null) {
823 loge("isNRDualConnectivityEnabled: Empty response");
824 } else if (ar.exception instanceof CommandException) {
825 loge("isNRDualConnectivityEnabled: CommandException: "
826 + ar.exception);
827 } else {
828 loge("isNRDualConnectivityEnabled: Unknown exception");
829 }
830 }
831 notifyRequester(request);
832 break;
833
834 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
837 Phone phone = getPhoneFromRequest(request);
838 if (phone != null) {
839 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
840 request.workSource);
841 } else {
842 loge("enableNrDualConnectivity: No phone object");
843 request.result =
844 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
845 notifyRequester(request);
846 }
847 break;
848 }
849
850 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null) {
854 request.result =
855 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
856 } else {
857 request.result =
858 TelephonyManager
859 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
860 if (ar.exception instanceof CommandException) {
861 CommandException.Error error =
862 ((CommandException) (ar.exception)).getCommandError();
863 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
864 request.result =
865 TelephonyManager
866 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000867 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
868 request.result =
869 TelephonyManager
870 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700871 }
872 loge("enableNrDualConnectivity" + ": CommandException: "
873 + ar.exception);
874 } else {
875 loge("enableNrDualConnectivity" + ": Unknown exception");
876 }
877 }
878 notifyRequester(request);
879 break;
880 }
881
SongFerngWang9e060372020-12-21 16:41:52 +0800882 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800883 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800884 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
885 request);
886 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 break;
888
SongFerngWang9e060372020-12-21 16:41:52 +0800889 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result; // Integer
894 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530895 // request.result must be set to something non-null
896 // for the calling thread to unblock
897 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800899 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800901 loge("getAllowedNetworkTypesBitmask: CommandException: "
902 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800904 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 break;
909
SongFerngWang9e060372020-12-21 16:41:52 +0800910 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800912 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
913 request);
914 Pair<Integer, Long> reasonWithNetworkTypes =
915 (Pair<Integer, Long>) request.argument;
916 getPhoneFromRequest(request).setAllowedNetworkTypes(
917 reasonWithNetworkTypes.first,
918 reasonWithNetworkTypes.second,
919 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 break;
921
SongFerngWang9e060372020-12-21 16:41:52 +0800922 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
923 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 break;
925
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000926 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
927 request = (MainThreadRequest)msg.obj;
928 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800929 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000930 break;
931
932 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
933 ar = (AsyncResult)msg.obj;
934 request = (MainThreadRequest)ar.userObj;
935 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700936 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000937 break;
938
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800939 case CMD_SET_VOICEMAIL_NUMBER:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
942 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800943 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
944 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800945 break;
946
947 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
948 handleNullReturnEvent(msg, "setVoicemailNumber");
949 break;
950
Stuart Scott54788802015-03-30 13:18:01 -0700951 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
954 request);
955 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
956 break;
957
958 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
959 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
960 break;
961
Shishir Agrawal302c8692015-06-19 13:49:39 -0700962 case CMD_PERFORM_NETWORK_SCAN:
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
965 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
966 break;
967
Hall Liua1acea22020-09-18 19:04:59 -0700968 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700971 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
972 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
973 request.argument;
974 int callForwardingReason = args.first;
975 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800976 break;
Hall Liua1acea22020-09-18 19:04:59 -0700977 }
978 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700981 TelephonyManager.CallForwardingInfoCallback callback =
982 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
983 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800984 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700985 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800986 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
987 for (CallForwardInfo callForwardInfo : callForwardInfos) {
988 // Service Class is a bit mask per 3gpp 27.007. Search for
989 // any service for voice call.
990 if ((callForwardInfo.serviceClass
991 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700992 callForwardingInfo = new CallForwardingInfo(true,
993 callForwardInfo.reason,
994 callForwardInfo.number,
995 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800996 break;
997 }
998 }
999 // Didn't find a call forward info for voice call.
1000 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001001 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1002 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001003 }
Hall Liua1acea22020-09-18 19:04:59 -07001004 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001005 } else {
1006 if (ar.result == null) {
1007 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1008 }
1009 if (ar.exception != null) {
1010 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1011 }
Hall Liuae527aa2020-09-29 17:10:18 -07001012 int errorCode = TelephonyManager
1013 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001014 if (ar.exception instanceof CommandException) {
1015 CommandException.Error error =
1016 ((CommandException) (ar.exception)).getCommandError();
1017 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001020 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001021 errorCode = TelephonyManager
1022 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001023 }
1024 }
Hall Liua1acea22020-09-18 19:04:59 -07001025 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001026 }
sqian80370722020-01-29 15:02:51 -08001027 break;
Hall Liua1acea22020-09-18 19:04:59 -07001028 }
sqian80370722020-01-29 15:02:51 -08001029
Hall Liua1acea22020-09-18 19:04:59 -07001030 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001033 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001034 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001035 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1036 request.argument).first;
1037 request.phone.setCallForwardingOption(
1038 callForwardingInfoToSet.isEnabled()
1039 ? CommandsInterface.CF_ACTION_ENABLE
1040 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001041 callForwardingInfoToSet.getReason(),
1042 callForwardingInfoToSet.getNumber(),
1043 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1044 break;
Hall Liua1acea22020-09-18 19:04:59 -07001045 }
sqian80370722020-01-29 15:02:51 -08001046
Hall Liua1acea22020-09-18 19:04:59 -07001047 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001050 Consumer<Integer> callback =
1051 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1052 request.argument).second;
1053 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001054 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001055 int errorCode = TelephonyManager.CallForwardingInfoCallback
1056 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001057 if (ar.exception instanceof CommandException) {
1058 CommandException.Error error =
1059 ((CommandException) (ar.exception)).getCommandError();
1060 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001061 errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001063 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001064 errorCode = TelephonyManager.CallForwardingInfoCallback
1065 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001066 }
1067 }
1068 callback.accept(errorCode);
1069 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001070 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001071 }
sqian80370722020-01-29 15:02:51 -08001072 break;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
sqian80370722020-01-29 15:02:51 -08001074
Hall Liua1acea22020-09-18 19:04:59 -07001075 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1078 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1079 break;
Hall Liua1acea22020-09-18 19:04:59 -07001080 }
sqian80370722020-01-29 15:02:51 -08001081
Hall Liua1acea22020-09-18 19:04:59 -07001082 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001085 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001086 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1087 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001088 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001089 // Service Class is a bit mask per 3gpp 27.007.
1090 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001091 if (callForwardResults.length > 1
1092 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001093 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001094 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001095 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1096 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001097 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001098 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001099 }
1100 } else {
1101 if (ar.result == null) {
1102 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1103 }
1104 if (ar.exception != null) {
1105 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1106 }
1107 if (ar.exception instanceof CommandException) {
1108 CommandException.Error error =
1109 ((CommandException) (ar.exception)).getCommandError();
1110 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1111 callForwardingStatus =
1112 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1113 }
1114 }
1115 }
Hall Liua1acea22020-09-18 19:04:59 -07001116 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001117 break;
Hall Liua1acea22020-09-18 19:04:59 -07001118 }
sqian80370722020-01-29 15:02:51 -08001119
Hall Liua1acea22020-09-18 19:04:59 -07001120 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001121 request = (MainThreadRequest) msg.obj;
1122 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001123 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1124 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001125 break;
Hall Liua1acea22020-09-18 19:04:59 -07001126 }
sqian80370722020-01-29 15:02:51 -08001127
Hall Liua1acea22020-09-18 19:04:59 -07001128 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001131 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1132 Consumer<Integer> callback =
1133 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1134 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001135 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001136 if (ar.exception instanceof CommandException) {
1137 CommandException.Error error =
1138 ((CommandException) (ar.exception)).getCommandError();
1139 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1140 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1141 } else {
1142 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1143 }
1144 } else {
1145 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1146 }
1147 } else {
1148 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1149 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001150 }
sqian80370722020-01-29 15:02:51 -08001151 break;
Hall Liua1acea22020-09-18 19:04:59 -07001152 }
sqian80370722020-01-29 15:02:51 -08001153
Shishir Agrawal302c8692015-06-19 13:49:39 -07001154 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
1157 CellNetworkScanResult cellScanResult;
1158 if (ar.exception == null && ar.result != null) {
1159 cellScanResult = new CellNetworkScanResult(
1160 CellNetworkScanResult.STATUS_SUCCESS,
1161 (List<OperatorInfo>) ar.result);
1162 } else {
1163 if (ar.result == null) {
1164 loge("getCellNetworkScanResults: Empty response");
1165 }
1166 if (ar.exception != null) {
1167 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1168 }
1169 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1170 if (ar.exception instanceof CommandException) {
1171 CommandException.Error error =
1172 ((CommandException) (ar.exception)).getCommandError();
1173 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1174 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1175 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1176 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1177 }
1178 }
1179 cellScanResult = new CellNetworkScanResult(errorCode, null);
1180 }
1181 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001182 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001183 break;
1184
1185 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1186 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001187 ManualNetworkSelectionArgument selArg =
1188 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1190 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001191 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1192 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 break;
1194
1195 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 if (ar.exception == null) {
1199 request.result = true;
1200 } else {
1201 request.result = false;
1202 loge("setNetworkSelectionModeManual " + ar.exception);
1203 }
1204 notifyRequester(request);
1205 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001206 break;
1207
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001208 case CMD_GET_MODEM_ACTIVITY_INFO:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001211 if (defaultPhone != null) {
1212 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001213 } else {
1214 ResultReceiver result = (ResultReceiver) request.argument;
1215 Bundle bundle = new Bundle();
1216 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1217 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1218 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001219 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 break;
1221
1222 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001225 ResultReceiver result = (ResultReceiver) request.argument;
1226
1227 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001229 // Update the last modem activity info and the result of the request.
1230 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1231 if (isModemActivityInfoValid(info)) {
1232 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1233 int[] txTimeMs = info.getTransmitTimeMillis();
1234 int[] lastModemTxTimeMs = mLastModemActivityInfo
1235 .getTransmitTimeMillis();
1236 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1237 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1238 }
1239 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1240 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1241 + mLastModemActivityInfo.getSleepTimeMillis());
1242 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1243 + mLastModemActivityInfo.getIdleTimeMillis());
1244 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1245 mLastModemActivityInfo.setReceiveTimeMillis(
1246 info.getReceiveTimeMillis()
1247 + mLastModemActivityInfo.getReceiveTimeMillis());
1248 }
1249 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1250 mLastModemActivityInfo.getSleepTimeMillis(),
1251 mLastModemActivityInfo.getIdleTimeMillis(),
1252 mLastModemActivityInfo.getTransmitTimeMillis(),
1253 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001254 } else {
1255 if (ar.result == null) {
1256 loge("queryModemActivityInfo: Empty response");
1257 } else if (ar.exception instanceof CommandException) {
1258 loge("queryModemActivityInfo: CommandException: " +
1259 ar.exception);
1260 } else {
1261 loge("queryModemActivityInfo: Unknown exception");
1262 }
1263 }
sqian1a1be542020-03-05 11:37:28 -08001264 Bundle bundle = new Bundle();
1265 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1266 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001267 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001268 break;
1269
Meng Wang1a7c35a2016-05-05 20:56:15 -07001270 case CMD_SET_ALLOWED_CARRIERS:
1271 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001272 CarrierRestrictionRules argument =
1273 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001274 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001275 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 break;
1277
1278 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1279 ar = (AsyncResult) msg.obj;
1280 request = (MainThreadRequest) ar.userObj;
1281 if (ar.exception == null && ar.result != null) {
1282 request.result = ar.result;
1283 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001284 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1285 if (ar.exception instanceof CommandException) {
1286 loge("setAllowedCarriers: CommandException: " + ar.exception);
1287 CommandException.Error error =
1288 ((CommandException) (ar.exception)).getCommandError();
1289 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1290 request.result =
1291 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1292 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 } else {
1294 loge("setAllowedCarriers: Unknown exception");
1295 }
1296 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001297 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 break;
1299
1300 case CMD_GET_ALLOWED_CARRIERS:
1301 request = (MainThreadRequest) msg.obj;
1302 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001303 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 break;
1305
1306 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
1309 if (ar.exception == null && ar.result != null) {
1310 request.result = ar.result;
1311 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001312 request.result = new IllegalStateException(
1313 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001314 if (ar.result == null) {
1315 loge("getAllowedCarriers: Empty response");
1316 } else if (ar.exception instanceof CommandException) {
1317 loge("getAllowedCarriers: CommandException: " +
1318 ar.exception);
1319 } else {
1320 loge("getAllowedCarriers: Unknown exception");
1321 }
1322 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001323 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001324 break;
1325
Nathan Haroldb3014052017-01-25 15:57:32 -08001326 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1327 ar = (AsyncResult) msg.obj;
1328 request = (MainThreadRequest) ar.userObj;
1329 if (ar.exception == null && ar.result != null) {
1330 request.result = ar.result;
1331 } else {
1332 request.result = new IllegalArgumentException(
1333 "Failed to retrieve Forbidden Plmns");
1334 if (ar.result == null) {
1335 loge("getForbiddenPlmns: Empty response");
1336 } else {
1337 loge("getForbiddenPlmns: Unknown exception");
1338 }
1339 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001340 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001341 break;
1342
1343 case CMD_GET_FORBIDDEN_PLMNS:
1344 request = (MainThreadRequest) msg.obj;
1345 uiccCard = getUiccCardFromRequest(request);
1346 if (uiccCard == null) {
1347 loge("getForbiddenPlmns() UiccCard is null");
1348 request.result = new IllegalArgumentException(
1349 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001351 break;
1352 }
1353 Integer appType = (Integer) request.argument;
1354 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1355 if (uiccApp == null) {
1356 loge("getForbiddenPlmns() no app with specified type -- "
1357 + appType);
1358 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 break;
1361 } else {
1362 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1363 + " specified type -- " + appType);
1364 }
1365 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1366 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1367 onCompleted);
1368 break;
1369
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001370 case CMD_SWITCH_SLOTS:
1371 request = (MainThreadRequest) msg.obj;
1372 int[] physicalSlots = (int[]) request.argument;
1373 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1374 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1375 break;
1376
1377 case EVENT_SWITCH_SLOTS_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001381 notifyRequester(request);
1382 break;
1383 case CMD_GET_NETWORK_SELECTION_MODE:
1384 request = (MainThreadRequest) msg.obj;
1385 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1386 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1387 break;
1388
1389 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 if (ar.exception != null) {
1393 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1394 } else {
1395 int mode = ((int[]) ar.result)[0];
1396 if (mode == 0) {
1397 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1398 } else {
1399 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1400 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001401 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001402 notifyRequester(request);
1403 break;
1404 case CMD_GET_CDMA_ROAMING_MODE:
1405 request = (MainThreadRequest) msg.obj;
1406 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1407 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1408 break;
1409 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 if (ar.exception != null) {
1413 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1414 } else {
1415 request.result = ((int[]) ar.result)[0];
1416 }
1417 notifyRequester(request);
1418 break;
1419 case CMD_SET_CDMA_ROAMING_MODE:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1422 int mode = (int) request.argument;
1423 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1424 break;
1425 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 request.result = ar.exception == null;
1429 notifyRequester(request);
1430 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001431 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1434 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1435 break;
1436 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 if (ar.exception != null) {
1440 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1441 } else {
1442 request.result = ((int[]) ar.result)[0];
1443 }
1444 notifyRequester(request);
1445 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001446 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1449 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001450 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1451 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001452 break;
1453 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 request.result = ar.exception == null;
1457 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001458 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 case CMD_GET_ALL_CELL_INFO:
1460 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001462 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001464 case EVENT_GET_ALL_CELL_INFO_DONE:
1465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001467 // If a timeout occurs, the response will be null
1468 request.result = (ar.exception == null && ar.result != null)
1469 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 synchronized (request) {
1471 request.notifyAll();
1472 }
1473 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001474 case CMD_REQUEST_CELL_INFO_UPDATE:
1475 request = (MainThreadRequest) msg.obj;
1476 request.phone.requestCellInfoUpdate(request.workSource,
1477 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1478 break;
1479 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1483 try {
1484 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001485 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001486 cb.onError(
1487 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1488 ar.exception.getClass().getName(),
1489 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001490 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001491 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001492 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 } else {
1494 // use the result as returned
1495 cb.onCellInfo((List<CellInfo>) ar.result);
1496 }
1497 } catch (RemoteException re) {
1498 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1499 }
1500 break;
Sarah Chincc055732020-11-18 13:39:35 -08001501 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 request = (MainThreadRequest) msg.obj;
1503 WorkSource ws = (WorkSource) request.argument;
1504 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001505 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001506 break;
Sarah Chincc055732020-11-18 13:39:35 -08001507 }
1508 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception == null) {
1512 request.result = ar.result;
1513 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001514 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001515 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001516 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001517 }
1518
1519 synchronized (request) {
1520 request.notifyAll();
1521 }
1522 break;
Sarah Chincc055732020-11-18 13:39:35 -08001523 }
chen xu6dac5ab2018-10-26 17:39:23 -07001524 case CMD_MODEM_REBOOT:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001527 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001528 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001529 case EVENT_CMD_MODEM_REBOOT_DONE:
1530 handleNullReturnEvent(msg, "rebootModem");
1531 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001532 case CMD_REQUEST_ENABLE_MODEM:
1533 request = (MainThreadRequest) msg.obj;
1534 boolean enable = (boolean) request.argument;
1535 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001536 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001537 PhoneConfigurationManager.getInstance()
1538 .enablePhone(request.phone, enable, onCompleted);
1539 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001540 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001544 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001545 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001546 if ((boolean) request.result) {
1547 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1548 updateModemStateMetrics();
1549 } else {
1550 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1551 + ar.exception);
1552 }
1553 notifyRequester(request);
1554 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001555 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001556 case CMD_GET_MODEM_STATUS:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1559 PhoneConfigurationManager.getInstance()
1560 .getPhoneStatusFromModem(request.phone, onCompleted);
1561 break;
1562 case EVENT_GET_MODEM_STATUS_DONE:
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 int id = request.phone.getPhoneId();
1566 if (ar.exception == null && ar.result != null) {
1567 request.result = ar.result;
1568 //update the cache as modem status has changed
1569 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1570 (boolean) request.result);
1571 } else {
1572 // Return true if modem status cannot be retrieved. For most cases,
1573 // modem status is on. And for older version modems, GET_MODEM_STATUS
1574 // and disable modem are not supported. Modem is always on.
1575 // TODO: this should be fixed in R to support a third
1576 // status UNKNOWN b/131631629
1577 request.result = true;
1578 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1579 + ar.exception);
1580 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001581 notifyRequester(request);
1582 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001583 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1586 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1587 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1588 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1589 break;
1590 }
1591 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1592 ar = (AsyncResult) msg.obj;
1593 request = (MainThreadRequest) ar.userObj;
1594 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1595 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1596 args.second.accept(ar.exception == null);
1597 notifyRequester(request);
1598 break;
1599 }
Sarah Chincc055732020-11-18 13:39:35 -08001600 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1601 request = (MainThreadRequest) msg.obj;
1602 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1603 Phone phone = getPhoneFromRequest(request);
1604 if (phone != null) {
1605 phone.getSystemSelectionChannels(onCompleted);
1606 } else {
1607 loge("getSystemSelectionChannels: No phone object");
1608 request.result = new ArrayList<RadioAccessSpecifier>();
1609 notifyRequester(request);
1610 }
1611 break;
1612 }
1613 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 if (ar.exception == null && ar.result != null) {
1617 request.result = ar.result;
1618 } else {
1619 request.result = new IllegalArgumentException(
1620 "Failed to retrieve system selection channels");
1621 if (ar.result == null) {
1622 loge("getSystemSelectionChannels: Empty response");
1623 } else {
1624 loge("getSystemSelectionChannels: Unknown exception");
1625 }
1626 }
1627 notifyRequester(request);
1628 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001629 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null && ar.result != null) {
1633 request.result = ar.result;
1634 } else {
1635 request.result = -1;
1636 loge("Failed to set Forbidden Plmns");
1637 if (ar.result == null) {
1638 loge("setForbidenPlmns: Empty response");
1639 } else if (ar.exception != null) {
1640 loge("setForbiddenPlmns: Exception: " + ar.exception);
1641 request.result = -1;
1642 } else {
1643 loge("setForbiddenPlmns: Unknown exception");
1644 }
1645 }
1646 notifyRequester(request);
1647 break;
1648 case CMD_SET_FORBIDDEN_PLMNS:
1649 request = (MainThreadRequest) msg.obj;
1650 uiccCard = getUiccCardFromRequest(request);
1651 if (uiccCard == null) {
1652 loge("setForbiddenPlmns: UiccCard is null");
1653 request.result = -1;
1654 notifyRequester(request);
1655 break;
1656 }
1657 Pair<Integer, List<String>> setFplmnsArgs =
1658 (Pair<Integer, List<String>>) request.argument;
1659 appType = setFplmnsArgs.first;
1660 List<String> fplmns = setFplmnsArgs.second;
1661 uiccApp = uiccCard.getApplicationByType(appType);
1662 if (uiccApp == null) {
1663 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1664 request.result = -1;
1665 loge("Failed to get UICC App");
1666 notifyRequester(request);
1667 } else {
1668 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1669 ((SIMRecords) uiccApp.getIccRecords())
1670 .setForbiddenPlmns(onCompleted, fplmns);
1671 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001672 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001673 case CMD_ERASE_MODEM_CONFIG:
1674 request = (MainThreadRequest) msg.obj;
1675 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1676 defaultPhone.eraseModemConfig(onCompleted);
1677 break;
1678 case EVENT_ERASE_MODEM_CONFIG_DONE:
1679 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001680 break;
zoey chenf95ca592019-12-30 16:11:23 +08001681
1682 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1685 Pair<String, String> changed = (Pair<String, String>) request.argument;
1686 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1687 changed.first, changed.second, onCompleted);
1688 break;
1689 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
1692 if (ar.exception == null) {
1693 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001694 // If the operation is successful, update the PIN storage
1695 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1696 int phoneId = getPhoneFromRequest(request).getPhoneId();
1697 UiccController.getInstance().getPinStorage()
1698 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001699 } else {
1700 request.result = msg.arg1;
1701 }
1702 notifyRequester(request);
1703 break;
1704
Michele Berionned9fbae52020-11-13 02:36:59 +00001705 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1708 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1709 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1710 enabled.first, enabled.second, onCompleted);
1711 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001712 }
zoey chenf95ca592019-12-30 16:11:23 +08001713 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception == null) {
1717 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001718 // If the operation is successful, update the PIN storage
1719 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1720 int phoneId = getPhoneFromRequest(request).getPhoneId();
1721 if (enabled.first) {
1722 UiccController.getInstance().getPinStorage()
1723 .storePin(enabled.second, phoneId);
1724 } else {
1725 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1726 }
zoey chenf95ca592019-12-30 16:11:23 +08001727 } else {
1728 request.result = msg.arg1;
1729 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001730
1731
zoey chenf95ca592019-12-30 16:11:23 +08001732 notifyRequester(request);
1733 break;
1734
Peter Wangdafb9ac2020-01-15 14:13:38 -08001735 case MSG_NOTIFY_USER_ACTIVITY:
1736 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001737 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001738 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1739 getDefaultPhone().getContext().sendBroadcastAsUser(
1740 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1741 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001742
1743 case CMD_SET_DATA_THROTTLING: {
1744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1746 DataThrottlingRequest dataThrottlingRequest =
1747 (DataThrottlingRequest) request.argument;
1748 Phone phone = getPhoneFromRequest(request);
1749 if (phone != null) {
1750 phone.setDataThrottling(onCompleted,
1751 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1752 dataThrottlingRequest.getCompletionDurationMillis());
1753 } else {
1754 loge("setDataThrottling: No phone object");
1755 request.result =
1756 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1757 notifyRequester(request);
1758 }
1759
1760 break;
1761 }
1762 case EVENT_SET_DATA_THROTTLING_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765
1766 if (ar.exception == null) {
1767 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1768 } else if (ar.exception instanceof CommandException) {
1769 loge("setDataThrottling: CommandException: " + ar.exception);
1770 CommandException.Error error =
1771 ((CommandException) (ar.exception)).getCommandError();
1772
1773 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1774 request.result = TelephonyManager
1775 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1776 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1777 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1778 } else {
1779 request.result =
1780 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1781 }
1782 } else {
1783 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1784 }
1785 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1786 notifyRequester(request);
1787 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001788
1789 case CMD_SET_SIM_POWER: {
1790 request = (MainThreadRequest) msg.obj;
1791 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1792 request = (MainThreadRequest) msg.obj;
1793 int stateToSet =
1794 ((Pair<Integer, IIntegerConsumer>)
1795 request.argument).first;
1796 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1797 break;
1798 }
1799 case EVENT_SET_SIM_POWER_DONE: {
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802 IIntegerConsumer callback =
1803 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1804 if (ar.exception != null) {
1805 loge("setSimPower exception: " + ar.exception);
1806 int errorCode = TelephonyManager.CallForwardingInfoCallback
1807 .RESULT_ERROR_UNKNOWN;
1808 if (ar.exception instanceof CommandException) {
1809 CommandException.Error error =
1810 ((CommandException) (ar.exception)).getCommandError();
1811 if (error == CommandException.Error.SIM_ERR) {
1812 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1813 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1814 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1815 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1816 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1817 } else {
1818 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1819 }
1820 }
1821 try {
1822 callback.accept(errorCode);
1823 } catch (RemoteException e) {
1824 // Ignore if the remote process is no longer available to call back.
1825 Log.w(LOG_TAG, "setSimPower: callback not available.");
1826 }
1827 } else {
1828 try {
1829 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1830 } catch (RemoteException e) {
1831 // Ignore if the remote process is no longer available to call back.
1832 Log.w(LOG_TAG, "setSimPower: callback not available.");
1833 }
1834 }
1835 break;
1836 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001837 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1838 request = (MainThreadRequest) msg.obj;
1839
1840 final Phone phone = getPhoneFromRequest(request);
1841 if (phone == null || phone.getServiceStateTracker() == null) {
1842 request.result = new IllegalStateException("Phone or SST is null");
1843 notifyRequester(request);
1844 break;
1845 }
1846
1847 Pair<Integer, SignalStrengthUpdateRequest> pair =
1848 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1849 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1850 request);
1851 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1852 request.subId, pair.first /*callingUid*/,
1853 pair.second /*request*/, onCompleted);
1854 break;
1855 }
1856 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1857 ar = (AsyncResult) msg.obj;
1858 request = (MainThreadRequest) ar.userObj;
1859 // request.result will be the exception of ar if present, true otherwise.
1860 // Be cautious not to leave result null which will wait() forever
1861 request.result = ar.exception != null ? ar.exception : true;
1862 notifyRequester(request);
1863 break;
1864 }
1865 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1866 request = (MainThreadRequest) msg.obj;
1867
1868 Phone phone = getPhoneFromRequest(request);
1869 if (phone == null || phone.getServiceStateTracker() == null) {
1870 request.result = new IllegalStateException("Phone or SST is null");
1871 notifyRequester(request);
1872 break;
1873 }
1874
1875 Pair<Integer, SignalStrengthUpdateRequest> pair =
1876 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1877 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1878 request);
1879 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1880 request.subId, pair.first /*callingUid*/,
1881 pair.second /*request*/, onCompleted);
1882 break;
1883 }
1884 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1885 ar = (AsyncResult) msg.obj;
1886 request = (MainThreadRequest) ar.userObj;
1887 request.result = ar.exception != null ? ar.exception : true;
1888 notifyRequester(request);
1889 break;
1890 }
Jordan Liud5366d92020-11-24 14:50:34 -08001891
Michele Berionned9fbae52020-11-13 02:36:59 +00001892 case CMD_PREPARE_UNATTENDED_REBOOT:
1893 request = (MainThreadRequest) msg.obj;
1894 request.result =
1895 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1896 notifyRequester(request);
1897 break;
1898
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 default:
1900 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1901 break;
1902 }
1903 }
Jake Hambye994d462014-02-03 13:10:13 -08001904
Pengquan Menga1bb6272018-09-06 09:59:22 -07001905 private void notifyRequester(MainThreadRequest request) {
1906 synchronized (request) {
1907 request.notifyAll();
1908 }
1909 }
1910
Jake Hambye994d462014-02-03 13:10:13 -08001911 private void handleNullReturnEvent(Message msg, String command) {
1912 AsyncResult ar = (AsyncResult) msg.obj;
1913 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1914 if (ar.exception == null) {
1915 request.result = true;
1916 } else {
1917 request.result = false;
1918 if (ar.exception instanceof CommandException) {
1919 loge(command + ": CommandException: " + ar.exception);
1920 } else {
1921 loge(command + ": Unknown exception");
1922 }
1923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001924 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
1928 /**
1929 * Posts the specified command to be executed on the main thread,
1930 * waits for the request to complete, and returns the result.
1931 * @see #sendRequestAsync
1932 */
1933 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001934 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1935 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001936 }
1937
1938 /**
1939 * Posts the specified command to be executed on the main thread,
1940 * waits for the request to complete, and returns the result.
1941 * @see #sendRequestAsync
1942 */
1943 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1944 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001945 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
1948 /**
1949 * Posts the specified command to be executed on the main thread,
1950 * waits for the request to complete, and returns the result.
1951 * @see #sendRequestAsync
1952 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001953 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001954 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1955 }
1956
1957 /**
1958 * Posts the specified command to be executed on the main thread,
1959 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1960 * if not timeout or null otherwise.
1961 * @see #sendRequestAsync
1962 */
1963 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1964 long timeoutInMs) {
1965 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001966 }
1967
1968 /**
1969 * Posts the specified command to be executed on the main thread,
1970 * waits for the request to complete, and returns the result.
1971 * @see #sendRequestAsync
1972 */
Nathan Harold92bed182018-10-12 18:16:49 -07001973 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001974 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001975 }
1976
1977 /**
1978 * Posts the specified command to be executed on the main thread,
1979 * waits for the request to complete, and returns the result.
1980 * @see #sendRequestAsync
1981 */
1982 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001983 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1984 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001985 }
1986
1987 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001988 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1989 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1990 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001991 * @see #sendRequestAsync
1992 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001993 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1994 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1996 throw new RuntimeException("This method will deadlock if called from the main thread.");
1997 }
1998
Nathan Harold92bed182018-10-12 18:16:49 -07001999 MainThreadRequest request = null;
2000 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2001 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2002 } else if (phone != null) {
2003 request = new MainThreadRequest(argument, phone, workSource);
2004 } else {
2005 request = new MainThreadRequest(argument, subId, workSource);
2006 }
2007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 Message msg = mMainThreadHandler.obtainMessage(command, request);
2009 msg.sendToTarget();
2010
Rambo Wang0f050d82021-02-12 11:43:36 -08002011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002013 if (timeoutInMs >= 0) {
2014 // Wait for at least timeoutInMs before returning null request result
2015 long now = SystemClock.elapsedRealtime();
2016 long deadline = now + timeoutInMs;
2017 while (request == null && now < deadline) {
2018 try {
2019 request.wait(deadline - now);
2020 } catch (InterruptedException e) {
2021 // Do nothing, go back and check if request is completed or timeout
2022 } finally {
2023 now = SystemClock.elapsedRealtime();
2024 }
2025 }
2026 } else {
2027 // Wait for the request to complete
2028 while (request.result == null) {
2029 try {
2030 request.wait();
2031 } catch (InterruptedException e) {
2032 // Do nothing, go back and wait until the request is complete
2033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 }
2035 }
2036 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002037 if (request.result == null) {
2038 Log.wtf(LOG_TAG,
2039 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 return request.result;
2042 }
2043
2044 /**
2045 * Asynchronous ("fire and forget") version of sendRequest():
2046 * Posts the specified command to be executed on the main thread, and
2047 * returns immediately.
2048 * @see #sendRequest
2049 */
2050 private void sendRequestAsync(int command) {
2051 mMainThreadHandler.sendEmptyMessage(command);
2052 }
2053
2054 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002055 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002056 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002057 */
2058 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002059 sendRequestAsync(command, argument, null, null);
2060 }
2061
2062 /**
2063 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2064 * @see {@link #sendRequest(int,Object)}
2065 */
2066 private void sendRequestAsync(
2067 int command, Object argument, Phone phone, WorkSource workSource) {
2068 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002069 Message msg = mMainThreadHandler.obtainMessage(command, request);
2070 msg.sendToTarget();
2071 }
2072
2073 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 * Initialize the singleton PhoneInterfaceManager instance.
2075 * This is only done once, at startup, from PhoneApp.onCreate().
2076 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002077 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 synchronized (PhoneInterfaceManager.class) {
2079 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002080 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 } else {
2082 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2083 }
2084 return sInstance;
2085 }
2086 }
2087
2088 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002089 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002092 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002093 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2095 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002096 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002097 mTelephonySharedPreferences =
2098 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002099 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002100 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002101 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002102 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002103
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 publish();
2105 }
2106
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002107 private Phone getDefaultPhone() {
2108 Phone thePhone = getPhone(getDefaultSubscription());
2109 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2110 }
2111
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 private void publish() {
2113 if (DBG) log("publish: " + this);
2114
Peter Wangc035ce42020-01-08 21:00:22 -08002115 TelephonyFrameworkInitializer
2116 .getTelephonyServiceManager()
2117 .getTelephonyServiceRegisterer()
2118 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120
Stuart Scott584921c2015-01-15 17:10:34 -08002121 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002122 if (request.phone != null) {
2123 return request.phone;
2124 } else {
2125 return getPhoneFromSubId(request.subId);
2126 }
2127 }
2128
2129 private Phone getPhoneFromSubId(int subId) {
2130 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2131 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002132 }
2133
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002134 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2135 Phone phone = getPhoneFromRequest(request);
2136 return phone == null ? null :
2137 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2138 }
2139
Wink Saville36469e72014-06-11 15:17:00 -07002140 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002141 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002142 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002145 private void sendEraseModemConfig(Phone phone) {
2146 if (phone != null) {
2147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2148 mApp, phone.getSubId(), "eraseModemConfig");
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2152 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
2156 }
2157 }
2158
Peter Wang050bb052020-01-13 23:33:09 -08002159 private boolean isImsAvailableOnDevice() {
2160 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2161 if (pm == null) {
2162 // For some reason package manger is not available.. This will fail internally anyway,
2163 // so do not throw error and allow.
2164 return true;
2165 }
2166 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2167 }
2168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002170 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002171 }
2172
Wink Savilleb564aae2014-10-23 10:18:09 -07002173 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 if (DBG) log("dial: " + number);
2175 // No permission check needed here: This is just a wrapper around the
2176 // ACTION_DIAL intent, which is available to any app since it puts up
2177 // the UI before it does anything.
2178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 String url = createTelUrl(number);
2182 if (url == null) {
2183 return;
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 // PENDING: should we just silently fail if phone is offhook or ringing?
2187 PhoneConstants.State state = mCM.getState(subId);
2188 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2189 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2191 mApp.startActivity(intent);
2192 }
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196 }
2197
2198 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002199 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002200 }
2201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 if (DBG) log("call: " + number);
2204
2205 // This is just a wrapper around the ACTION_CALL intent, but we still
2206 // need to do a permission check since we're calling startActivity()
2207 // from the context of the phone app.
2208 enforceCallPermission();
2209
Jordan Liu1617b712019-07-10 15:06:26 -07002210 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 != AppOpsManager.MODE_ALLOWED) {
2212 return;
2213 }
2214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 String url = createTelUrl(number);
2218 if (url == null) {
2219 return;
2220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 boolean isValid = false;
2223 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2224 if (slist != null) {
2225 for (SubscriptionInfo subInfoRecord : slist) {
2226 if (subInfoRecord.getSubscriptionId() == subId) {
2227 isValid = true;
2228 break;
2229 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002230 }
Wink Saville08874612014-08-31 19:19:58 -07002231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 if (!isValid) {
2233 return;
2234 }
Wink Saville08874612014-08-31 19:19:58 -07002235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2237 intent.putExtra(SUBSCRIPTION_KEY, subId);
2238 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2239 mApp.startActivity(intent);
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
2242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 }
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002246 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002247 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2248 }
2249
Wink Savilleb564aae2014-10-23 10:18:09 -07002250 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002251 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002252 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2253 }
2254
Wink Savilleb564aae2014-10-23 10:18:09 -07002255 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257
2258 final long identity = Binder.clearCallingIdentity();
2259 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002260 Phone phone = getPhone(subId);
2261 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 checkSimPin.start();
2263 return checkSimPin.unlockSim(null, pin);
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002274 Phone phone = getPhone(subId);
2275 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 checkSimPuk.start();
2277 return checkSimPuk.unlockSim(puk, pin);
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002284 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 * a synchronous one.
2286 */
2287 private static class UnlockSim extends Thread {
2288
2289 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002290 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291
2292 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002293 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2294 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295
2296 // For replies from SimCard interface
2297 private Handler mHandler;
2298
2299 // For async handler to identify request type
2300 private static final int SUPPLY_PIN_COMPLETE = 100;
2301
Michele Berionned9fbae52020-11-13 02:36:59 +00002302 UnlockSim(int phoneId, IccCard simCard) {
2303 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 mSimCard = simCard;
2305 }
2306
2307 @Override
2308 public void run() {
2309 Looper.prepare();
2310 synchronized (UnlockSim.this) {
2311 mHandler = new Handler() {
2312 @Override
2313 public void handleMessage(Message msg) {
2314 AsyncResult ar = (AsyncResult) msg.obj;
2315 switch (msg.what) {
2316 case SUPPLY_PIN_COMPLETE:
2317 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2318 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002319 mRetryCount = msg.arg1;
2320 if (ar.exception != null) {
2321 if (ar.exception instanceof CommandException &&
2322 ((CommandException)(ar.exception)).getCommandError()
2323 == CommandException.Error.PASSWORD_INCORRECT) {
2324 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002325 } //When UiccCardApp dispose,handle message and return exception
2326 else if (ar.exception instanceof CommandException &&
2327 ((CommandException) (ar.exception)).getCommandError()
2328 == CommandException.Error.ABORTED) {
2329 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002330 } else {
2331 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2332 }
2333 } else {
2334 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mDone = true;
2337 UnlockSim.this.notifyAll();
2338 }
2339 break;
2340 }
2341 }
2342 };
2343 UnlockSim.this.notifyAll();
2344 }
2345 Looper.loop();
2346 }
2347
2348 /*
2349 * Use PIN or PUK to unlock SIM card
2350 *
2351 * If PUK is null, unlock SIM card with PIN
2352 *
2353 * If PUK is not null, unlock SIM card with PUK and set PIN code
2354 */
Wink Saville9de0f752013-10-22 19:04:03 -07002355 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356
2357 while (mHandler == null) {
2358 try {
2359 wait();
2360 } catch (InterruptedException e) {
2361 Thread.currentThread().interrupt();
2362 }
2363 }
2364 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2365
2366 if (puk == null) {
2367 mSimCard.supplyPin(pin, callback);
2368 } else {
2369 mSimCard.supplyPuk(puk, pin, callback);
2370 }
2371
2372 while (!mDone) {
2373 try {
2374 Log.d(LOG_TAG, "wait for done");
2375 wait();
2376 } catch (InterruptedException e) {
2377 // Restore the interrupted status
2378 Thread.currentThread().interrupt();
2379 }
2380 }
2381 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002382 int[] resultArray = new int[2];
2383 resultArray[0] = mResult;
2384 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002385
2386 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2387 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2388 }
2389
Wink Saville9de0f752013-10-22 19:04:03 -07002390 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
2392 }
2393
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002394 /**
2395 * This method has been removed due to privacy and stability concerns.
2396 */
2397 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002399 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2400 return;
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Nathan Harold1f889d82020-06-04 17:05:26 -07002403 @Override
2404 public void updateServiceLocationWithPackageName(String callingPackage) {
2405 mApp.getSystemService(AppOpsManager.class)
2406 .checkPackage(Binder.getCallingUid(), callingPackage);
2407
Nathan Haroldf096d982020-11-18 17:18:06 -08002408 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002409 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2410 // Callers targeting S have no business invoking this method.
2411 return;
2412 }
2413
2414 LocationAccessPolicy.LocationPermissionResult locationResult =
2415 LocationAccessPolicy.checkLocationPermission(mApp,
2416 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2417 .setCallingPackage(callingPackage)
2418 .setCallingFeatureId(null)
2419 .setCallingPid(Binder.getCallingPid())
2420 .setCallingUid(Binder.getCallingUid())
2421 .setMethod("updateServiceLocation")
2422 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2423 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2424 .build());
2425 // Apps that lack location permission have no business calling this method;
2426 // however, because no permission was declared in the public API, denials must
2427 // all be "soft".
2428 switch (locationResult) {
2429 case DENIED_HARD: /* fall through */
2430 case DENIED_SOFT:
2431 return;
2432 }
2433
2434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 final long identity = Binder.clearCallingIdentity();
2436 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002437 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002439 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002446 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 @Override
2448 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
2451
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002452
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002454 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2455 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2456 callingFeatureId);
2457 }
2458
2459 @Deprecated
2460 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002461 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002462 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2463 }
2464
2465 @Override
2466 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2467 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002469 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 return false;
2471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 return isRadioOnForSubscriber(subId);
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
2478 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002479 }
2480
2481 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 final Phone phone = getPhone(subId);
2485 if (phone != null) {
2486 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2487 } else {
2488 return false;
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
2495 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
Wink Saville36469e72014-06-11 15:17:00 -07002498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
2504 final Phone phone = getPhone(subId);
2505 if (phone != null) {
2506 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Wink Saville36469e72014-06-11 15:17:00 -07002511 }
2512
2513 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002514 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
2516
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone == null) {
2524 return false;
2525 }
2526 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2527 toggleRadioOnOffForSubscriber(subId);
2528 }
2529 return true;
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 }
Wink Saville36469e72014-06-11 15:17:00 -07002534
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002535 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002536 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002537 /*
2538 * If any of the Radios are available, it will need to be
2539 * shutdown. So return true if any Radio is available.
2540 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2544 Phone phone = PhoneFactory.getPhone(i);
2545 if (phone != null && phone.isRadioAvailable()) return true;
2546 }
2547 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2548 return false;
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002551 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002552 }
2553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002555 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 enforceModifyPermission();
2557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2561 logv("Shutting down Phone " + i);
2562 shutdownRadioUsingPhoneId(i);
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002566 }
2567 }
2568
2569 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002570 Phone phone = PhoneFactory.getPhone(phoneId);
2571 if (phone != null && phone.isRadioAvailable()) {
2572 phone.shutdownRadio();
2573 }
2574 }
2575
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2582 if (defaultPhone != null) {
2583 defaultPhone.setRadioPower(turnOn);
2584 return true;
2585 } else {
2586 loge("There's no default phone.");
2587 return false;
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002591 }
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Wink Savilleb564aae2014-10-23 10:18:09 -07002594 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(subId);
2600 if (phone != null) {
2601 phone.setRadioPower(turnOn);
2602 return true;
2603 } else {
2604 return false;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
Wink Saville36469e72014-06-11 15:17:00 -07002611 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 public boolean enableDataConnectivity() {
2614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 int subId = mSubscriptionController.getDefaultDataSubId();
2619 final Phone phone = getPhone(subId);
2620 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002621 phone.getDataEnabledSettings().setDataEnabled(
2622 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 return true;
2624 } else {
2625 return false;
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Wink Saville36469e72014-06-11 15:17:00 -07002632 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 public boolean disableDataConnectivity() {
2635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 int subId = mSubscriptionController.getDefaultDataSubId();
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002642 phone.getDataEnabledSettings().setDataEnabled(
2643 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 return true;
2645 } else {
2646 return false;
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002654 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002659 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 } else {
2661 return false;
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
2668 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002669 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002670 }
2671
pkanwarae03a6b2016-11-06 20:37:09 -08002672 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673 enforceCallPermission();
2674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2678 return;
2679 }
2680 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2681 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
pkanwar32d516d2016-10-14 19:37:38 -07002685 };
2686
Wink Savilleb564aae2014-10-23 10:18:09 -07002687 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689
2690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2693 return false;
2694 }
2695 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002702 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002703 }
2704
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002705 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 Phone phone = PhoneFactory.getPhone(slotIndex);
2709 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2710 PhoneConstantConversions.convertCallState(phone.getState());
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002717 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002718 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2719 }
2720
2721 @Override
2722 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002725 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 if (phone != null) {
2727 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2728 } else {
2729 return PhoneConstantConversions.convertDataState(
2730 PhoneConstants.DataState.DISCONNECTED);
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002738 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002739 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2740 }
2741
2742 @Override
2743 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 if (phone != null) {
2748 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2749 } else {
2750 return TelephonyManager.DATA_ACTIVITY_NONE;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002758 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002759 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002760 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002761
2762 LocationAccessPolicy.LocationPermissionResult locationResult =
2763 LocationAccessPolicy.checkLocationPermission(mApp,
2764 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2765 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002766 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002767 .setCallingPid(Binder.getCallingPid())
2768 .setCallingUid(Binder.getCallingUid())
2769 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002770 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002771 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2772 .build());
2773 switch (locationResult) {
2774 case DENIED_HARD:
2775 throw new SecurityException("Not allowed to access cell location");
2776 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002777 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2778 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002781 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002785 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002786 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
Svetoslav64fad262015-04-14 14:35:21 -07002790 }
2791
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 @Override
Jack Yu01425032020-02-22 19:38:58 -08002793 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002794 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2795 // registered cell info, so return a NULL country instead.
2796 final long identity = Binder.clearCallingIdentity();
2797 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002798 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2799 // Get default phone in this case.
2800 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2801 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002804 if (phone == null) return "";
2805 ServiceStateTracker sst = phone.getServiceStateTracker();
2806 if (sst == null) return "";
2807 LocaleTracker lt = sst.getLocaleTracker();
2808 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002809 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002813 }
2814
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002815 /**
2816 * This method was removed due to potential issues caused by performing partial
2817 * updates of service state, and lack of a credible use case.
2818 *
2819 * This has the ability to break the telephony implementation by disabling notification of
2820 * changes in device connectivity. DO NOT USE THIS!
2821 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002822 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 public void enableLocationUpdates() {
2824 mApp.enforceCallingOrSelfPermission(
2825 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002828 /**
2829 * This method was removed due to potential issues caused by performing partial
2830 * updates of service state, and lack of a credible use case.
2831 *
2832 * This has the ability to break the telephony implementation by disabling notification of
2833 * changes in device connectivity. DO NOT USE THIS!
2834 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 @Override
2836 public void disableLocationUpdates() {
2837 mApp.enforceCallingOrSelfPermission(
2838 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
2841 @Override
2842 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2844 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002845 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002846 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2847 throw new SecurityException(
2848 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2849 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002850
Jordan Liu1617b712019-07-10 15:06:26 -07002851 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2853 return null;
2854 }
Svetoslav64fad262015-04-14 14:35:21 -07002855
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002856 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002858 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002859 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860
Nathan Haroldf180aac2018-06-01 18:43:55 -07002861 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2862 for (CellInfo ci : info) {
2863 if (ci instanceof CellInfoGsm) {
2864 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2865 } else if (ci instanceof CellInfoWcdma) {
2866 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002869 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 }
2871
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002872 private List<CellInfo> getCachedCellInfo() {
2873 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2874 for (Phone phone : PhoneFactory.getPhones()) {
2875 List<CellInfo> info = phone.getAllCellInfo();
2876 if (info != null) cellInfos.addAll(info);
2877 }
2878 return cellInfos;
2879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880
2881 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002882 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002883 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002884 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002885
2886 LocationAccessPolicy.LocationPermissionResult locationResult =
2887 LocationAccessPolicy.checkLocationPermission(mApp,
2888 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2889 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002891 .setCallingPid(Binder.getCallingPid())
2892 .setCallingUid(Binder.getCallingUid())
2893 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002894 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002895 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2896 .build());
2897 switch (locationResult) {
2898 case DENIED_HARD:
2899 throw new SecurityException("Not allowed to access cell info");
2900 case DENIED_SOFT:
2901 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
Nathan Haroldf096d982020-11-18 17:18:06 -08002904 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002905 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2906 return getCachedCellInfo();
2907 }
2908
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002909 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2914 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002915 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002916 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 if (info != null) cellInfos.addAll(info);
2918 }
2919 return cellInfos;
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923 }
2924
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002925 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002926 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2927 String callingFeatureId) {
2928 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2929 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002930 }
2931
2932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002933 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2934 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002935 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002936 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002937 }
2938
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002939 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2940 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002942 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002943
2944 LocationAccessPolicy.LocationPermissionResult locationResult =
2945 LocationAccessPolicy.checkLocationPermission(mApp,
2946 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2947 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002948 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002949 .setCallingPid(Binder.getCallingPid())
2950 .setCallingUid(Binder.getCallingUid())
2951 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002952 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2953 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002954 .build());
2955 switch (locationResult) {
2956 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002957 if (TelephonyPermissions
2958 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002959 // Safetynet logging for b/154934934
2960 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2961 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 throw new SecurityException("Not allowed to access cell info");
2963 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002964 if (TelephonyPermissions
2965 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002966 // Safetynet logging for b/154934934
2967 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2968 }
Nathan Harold5320c422019-05-09 10:26:08 -07002969 try {
2970 cb.onCellInfo(new ArrayList<CellInfo>());
2971 } catch (RemoteException re) {
2972 // Drop without consequences
2973 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002974 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002975 }
2976
Nathan Harolda939a962019-05-09 10:13:47 -07002977
2978 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002979 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2980
2981 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2982 }
2983
2984 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002986 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
2996
Shishir Agrawala9f32182016-04-12 12:00:16 -07002997 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002998 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002999 Phone phone = PhoneFactory.getPhone(slotIndex);
3000 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003001 return null;
3002 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003003 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003004 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003005 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003006 return null;
3007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 return phone.getImei();
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003015 }
3016
3017 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003018 public String getTypeAllocationCodeForSlot(int slotIndex) {
3019 Phone phone = PhoneFactory.getPhone(slotIndex);
3020 String tac = null;
3021 if (phone != null) {
3022 String imei = phone.getImei();
3023 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3024 }
3025 return tac;
3026 }
3027
3028 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003029 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003030 Phone phone = PhoneFactory.getPhone(slotIndex);
3031 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003032 return null;
3033 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034
Jeff Davidson913390f2018-02-23 17:11:49 -08003035 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003036 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003037 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003038 return null;
3039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040
3041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 return phone.getMeid();
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
Jack Yu2af8d712017-03-15 17:14:14 -07003047 }
3048
3049 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003050 public String getManufacturerCodeForSlot(int slotIndex) {
3051 Phone phone = PhoneFactory.getPhone(slotIndex);
3052 String manufacturerCode = null;
3053 if (phone != null) {
3054 String meid = phone.getMeid();
3055 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3056 }
3057 return manufacturerCode;
3058 }
3059
3060 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003061 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3062 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 Phone phone = PhoneFactory.getPhone(slotIndex);
3064 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003065 return null;
3066 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003067 int subId = phone.getSubId();
3068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003069 mApp, subId, callingPackage, callingFeatureId,
3070 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003071 return null;
3072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 return phone.getDeviceSvn();
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003080 }
3081
fionaxu43304da2017-11-27 22:51:16 -08003082 @Override
3083 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 final Phone phone = getPhone(subId);
3087 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
fionaxu43304da2017-11-27 22:51:16 -08003091 }
3092
3093 @Override
3094 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 final Phone phone = getPhone(subId);
3098 return phone == null ? null : phone.getCarrierName();
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
fionaxu43304da2017-11-27 22:51:16 -08003102 }
3103
calvinpanffe225e2018-11-01 19:43:06 +08003104 @Override
chen xu0026ca62019-03-06 15:28:50 -08003105 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003110 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
3116 @Override
chen xu0026ca62019-03-06 15:28:50 -08003117 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003121 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
chen xu651eec72018-11-11 19:03:44 -08003127 @Override
chen xu864e11c2018-12-06 22:10:03 -08003128 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3129 if (!isSubscriptionMccMnc) {
3130 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3131 }
chen xu651eec72018-11-11 19:03:44 -08003132 final Phone phone = PhoneFactory.getPhone(slotIndex);
3133 if (phone == null) {
3134 return TelephonyManager.UNKNOWN_CARRIER_ID;
3135 }
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
3142 }
3143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 //
3145 // Internal helper methods.
3146 //
3147
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003148 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3150 *
3151 * @throws SecurityException if the caller does not have the required permission
3152 */
3153 private void enforceModifyPermission() {
3154 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3155 }
3156
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003157 /**
3158 * Make sure the caller is system.
3159 *
3160 * @throws SecurityException if the caller is not system.
3161 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003162 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003163 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3164 throw new SecurityException("Caller must be system");
3165 }
3166 }
3167
Shuo Qianf2b2df42019-11-13 17:43:31 -08003168 private void enforceActiveEmergencySessionPermission() {
3169 mApp.enforceCallingOrSelfPermission(
3170 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3171 }
3172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 /**
3174 * Make sure the caller has the CALL_PHONE permission.
3175 *
3176 * @throws SecurityException if the caller does not have the required permission
3177 */
3178 private void enforceCallPermission() {
3179 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3180 }
3181
paulhu423b5f22019-08-23 19:17:33 +08003182 private void enforceSettingsPermission() {
3183 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003184 }
3185
Michele Berionned9fbae52020-11-13 02:36:59 +00003186 private void enforceRebootPermission() {
3187 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3188 }
3189
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 private String createTelUrl(String number) {
3191 if (TextUtils.isEmpty(number)) {
3192 return null;
3193 }
3194
Jake Hambye994d462014-02-03 13:10:13 -08003195 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Ihab Awadf9e92732013-12-05 18:02:52 -08003198 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3200 }
3201
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003202 private static void logv(String msg) {
3203 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3204 }
3205
Ihab Awadf9e92732013-12-05 18:02:52 -08003206 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3208 }
3209
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003210 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003212 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003213 }
3214
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003216 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 final Phone phone = PhoneFactory.getPhone(slotIndex);
3220 if (phone == null) {
3221 return PhoneConstants.PHONE_TYPE_NONE;
3222 } else {
3223 return phone.getPhoneType();
3224 }
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003228 }
3229
3230 /**
3231 * Returns the CDMA ERI icon index to display
3232 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003234 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3235 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3236 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003237 }
3238
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003240 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3241 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003243 mApp, subId, callingPackage, callingFeatureId,
3244 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003245 return -1;
3246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 final Phone phone = getPhone(subId);
3251 if (phone != null) {
3252 return phone.getCdmaEriIconIndex();
3253 } else {
3254 return -1;
3255 }
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
3261 /**
3262 * Returns the CDMA ERI icon mode,
3263 * 0 - ON
3264 * 1 - FLASHING
3265 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003266 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003267 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3268 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3269 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003270 }
3271
Sanket Padawe356d7632015-06-22 14:03:32 -07003272 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003273 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003276 mApp, subId, callingPackage, callingFeatureId,
3277 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003278 return -1;
3279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 final Phone phone = getPhone(subId);
3284 if (phone != null) {
3285 return phone.getCdmaEriIconMode();
3286 } else {
3287 return -1;
3288 }
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
3294 /**
3295 * Returns the CDMA ERI text,
3296 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003298 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3299 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3300 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003301 }
3302
Sanket Padawe356d7632015-06-22 14:03:32 -07003303 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003304 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3305 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003307 mApp, subId, callingPackage, callingFeatureId,
3308 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003309 return null;
3310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 final Phone phone = getPhone(subId);
3315 if (phone != null) {
3316 return phone.getCdmaEriText();
3317 } else {
3318 return null;
3319 }
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 }
3324
3325 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003326 * Returns the CDMA MDN.
3327 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003328 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003329 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3331 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 return phone.getLine1Number();
3338 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 return null;
3341 }
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003344 }
3345 }
3346
3347 /**
3348 * Returns the CDMA MIN.
3349 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003350 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003351 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3353 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 final Phone phone = getPhone(subId);
3358 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3359 return phone.getCdmaMin();
3360 } else {
3361 return null;
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003365 }
3366 }
3367
Hall Liud892bec2018-11-30 14:51:45 -08003368 @Override
3369 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3370 INumberVerificationCallback callback, String callingPackage) {
3371 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3372 != PERMISSION_GRANTED) {
3373 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3374 }
3375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3376
3377 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3378 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003379 throw new SecurityException("Calling package must be configured in the device config: "
3380 + "calling package: " + callingPackage
3381 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003382 }
3383
3384 if (range == null) {
3385 throw new NullPointerException("Range must be non-null");
3386 }
3387
3388 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003389 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003390
3391 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3392 }
3393
Junda Liuca05d5d2014-08-14 22:36:34 -07003394 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395 * Returns true if CDMA provisioning needs to run.
3396 */
3397 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003400 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 }
3405
3406 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003407 * Sets the voice mail number of a given subId.
3408 */
3409 @Override
3410 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003411 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3412 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3417 new Pair<String, String>(alphaTag, number), new Integer(subId));
3418 return success;
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003422 }
3423
Ta-wei Yen87c49842016-05-13 21:19:52 -07003424 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003425 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003427 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3428 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003429 if (!TextUtils.equals(callingPackage, systemDialer)) {
3430 throw new SecurityException("caller must be system dialer");
3431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3436 if (phoneAccountHandle == null) {
3437 return null;
3438 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003442 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003443 }
3444
3445 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003446 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3447 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003450 mApp, subId, callingPackage, callingFeatureId,
3451 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003452 return null;
3453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003455 final long identity = Binder.clearCallingIdentity();
3456 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003461 }
3462
3463 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003464 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3465 VisualVoicemailSmsFilterSettings settings) {
3466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467
3468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003471 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472 } finally {
3473 Binder.restoreCallingIdentity(identity);
3474 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003475 }
3476
3477 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003478 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003484 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003488 }
3489
3490 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003491 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3492 String callingPackage, int subId) {
3493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003498 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499 } finally {
3500 Binder.restoreCallingIdentity(identity);
3501 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003502 }
3503
3504 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003505 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003511 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003515 }
3516
3517 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003518 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3519 String callingAttributionTag, int subId, String number, int port, String text,
3520 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003522 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003523 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003524 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003525 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3526 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003527 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003528
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003529 /**
fionaxu0152e512016-11-14 13:36:14 -08003530 * Sets the voice activation state of a given subId.
3531 */
3532 @Override
3533 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3535 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 phone.setVoiceActivationState(activationState);
3542 } else {
3543 loge("setVoiceActivationState fails with invalid subId: " + subId);
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003547 }
3548 }
3549
3550 /**
3551 * Sets the data activation state of a given subId.
3552 */
3553 @Override
3554 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3556 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone phone = getPhone(subId);
3561 if (phone != null) {
3562 phone.setDataActivationState(activationState);
3563 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003564 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003568 }
3569 }
3570
3571 /**
3572 * Returns the voice activation state of a given subId.
3573 */
3574 @Override
3575 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577
fionaxu0152e512016-11-14 13:36:14 -08003578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 if (phone != null) {
3582 return phone.getVoiceActivationState();
3583 } else {
3584 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003588 }
3589 }
3590
3591 /**
3592 * Returns the data activation state of a given subId.
3593 */
3594 @Override
3595 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597
fionaxu0152e512016-11-14 13:36:14 -08003598 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 if (phone != null) {
3602 return phone.getDataActivationState();
3603 } else {
3604 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3605 }
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003608 }
3609 }
3610
3611 /**
Wink Saville36469e72014-06-11 15:17:00 -07003612 * Returns the unread count of voicemails for a subId
3613 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003615 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3616 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003618 mApp, subId, callingPackage, callingFeatureId,
3619 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003620 return 0;
3621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null) {
3626 return phone.getVoiceMessageCount();
3627 } else {
3628 return 0;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 }
3634
3635 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003636 * returns true, if the device is in a state where both voice and data
3637 * are supported simultaneously. This can change based on location or network condition.
3638 */
3639 @Override
3640 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 final Phone phone = getPhone(subId);
3644 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003648 }
3649
3650 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003651 * Send the dialer code if called from the current default dialer or the caller has
3652 * carrier privilege.
3653 * @param inputCode The dialer code to send
3654 */
3655 @Override
3656 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003659 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3660 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003661 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003662 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
fionaxu235cc5e2017-03-06 22:25:57 -08003672 }
3673
Pengquan Menga1bb6272018-09-06 09:59:22 -07003674 @Override
3675 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003676 TelephonyPermissions
3677 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3678 mApp, subId, "getNetworkSelectionMode");
3679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 if (!isActiveSubscription(subId)) {
3682 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3683 }
3684 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003688 }
3689
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003691 public boolean isInEmergencySmsMode() {
3692 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 for (Phone phone : PhoneFactory.getPhones()) {
3696 if (phone.isInEmergencySmsMode()) {
3697 return true;
3698 }
3699 }
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
3703 return false;
3704 }
3705
shilu366312e2019-12-17 09:28:10 -08003706 /**
3707 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3708 * @param subId The subscription to use to check the configuration.
3709 * @param c The callback that will be used to send the result.
3710 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003711 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003712 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3713 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003714 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3715 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003716
Brad Ebinger77b832e2019-10-17 17:03:22 -07003717 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3719 "IMS not available on device.");
3720 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 final long token = Binder.clearCallingIdentity();
3722 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 } catch (ImsException e) {
3727 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 } finally {
3729 Binder.restoreCallingIdentity(token);
3730 }
3731 }
3732
shilu366312e2019-12-17 09:28:10 -08003733 /**
3734 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3735 * @param subId The subscription to use to check the configuration.
3736 * @param c The callback that will be used to send the result.
3737 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003739 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003740 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3741 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003742 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3743 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3744 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003745 final long token = Binder.clearCallingIdentity();
3746 try {
3747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3748 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3749 .removeRegistrationCallbackForSubscription(c, subId);
3750 } catch (ImsException e) {
3751 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3752 + "is inactive, ignoring unregister.");
3753 // If the subscription is no longer active, just return, since the callback
3754 // will already have been removed internally.
3755 } finally {
3756 Binder.restoreCallingIdentity(token);
3757 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 }
3759
Brad Ebinger774ba362019-10-22 17:36:18 -07003760 /**
3761 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3762 */
3763 @Override
3764 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3765 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3766 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3768 "IMS not available on device.");
3769 }
3770 final long token = Binder.clearCallingIdentity();
3771 try {
3772 Phone phone = getPhone(subId);
3773 if (phone == null) {
3774 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3775 + subId + "'");
3776 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3777 }
3778 phone.getImsRegistrationState(regState -> {
3779 try {
3780 consumer.accept((regState == null)
3781 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3782 } catch (RemoteException e) {
3783 // Ignore if the remote process is no longer available to call back.
3784 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3785 }
3786 });
3787 } finally {
3788 Binder.restoreCallingIdentity(token);
3789 }
3790 }
3791
3792 /**
3793 * Get the transport type for the IMS service registration state.
3794 */
3795 @Override
3796 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003797 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3798 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003799 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3800 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3801 "IMS not available on device.");
3802 }
3803 final long token = Binder.clearCallingIdentity();
3804 try {
3805 Phone phone = getPhone(subId);
3806 if (phone == null) {
3807 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3808 + subId + "'");
3809 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3810 }
3811 phone.getImsRegistrationTech(regTech -> {
3812 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3813 int regTechConverted = (regTech == null)
3814 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3815 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3816 regTechConverted);
3817 try {
3818 consumer.accept(regTechConverted);
3819 } catch (RemoteException e) {
3820 // Ignore if the remote process is no longer available to call back.
3821 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3822 }
3823 });
3824 } finally {
3825 Binder.restoreCallingIdentity(token);
3826 }
3827 }
3828
shilu366312e2019-12-17 09:28:10 -08003829 /**
3830 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3831 * @param subId The subscription to use to check the configuration.
3832 * @param c The callback that will be used to send the result.
3833 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003834 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003835 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3836 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003837 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3838 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003839 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3840 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3841 "IMS not available on device.");
3842 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3844 final long token = Binder.clearCallingIdentity();
3845 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003846 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003848 } catch (ImsException e) {
3849 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 } finally {
3851 Binder.restoreCallingIdentity(token);
3852 }
3853 }
3854
shilu366312e2019-12-17 09:28:10 -08003855 /**
3856 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3857 * @param subId The subscription to use to check the configuration.
3858 * @param c The callback that will be used to send the result.
3859 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003861 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003862 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3863 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3865 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3866 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003867
3868 final long token = Binder.clearCallingIdentity();
3869 try {
3870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3871 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003872 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003873 } catch (ImsException e) {
3874 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3875 + "is inactive, ignoring unregister.");
3876 // If the subscription is no longer active, just return, since the callback
3877 // will already have been removed internally.
3878 } finally {
3879 Binder.restoreCallingIdentity(token);
3880 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 }
3882
3883 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003884 public boolean isCapable(int subId, int capability, int regTech) {
3885 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3887 final long token = Binder.clearCallingIdentity();
3888 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003889 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3893 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003894 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003895 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3896 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 } finally {
3898 Binder.restoreCallingIdentity(token);
3899 }
3900 }
3901
3902 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003903 public boolean isAvailable(int subId, int capability, int regTech) {
3904 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 final long token = Binder.clearCallingIdentity();
3906 try {
3907 Phone phone = getPhone(subId);
3908 if (phone == null) return false;
3909 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003910 } catch (com.android.ims.ImsException e) {
3911 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3912 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(token);
3915 }
3916 }
3917
Brad Ebinger77b832e2019-10-17 17:03:22 -07003918 /**
3919 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3920 * subscription.
3921 * @param subId The subscription to use to check the configuration.
3922 * @param callback The callback that will be used to send the result.
3923 * @param capability The MmTelFeature capability that will be used to send the result.
3924 * @param transportType The transport type of the MmTelFeature capability.
3925 */
3926 @Override
3927 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3928 int transportType) {
3929 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3930 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3932 "IMS not available on device.");
3933 }
3934 final long token = Binder.clearCallingIdentity();
3935 try {
3936 int slotId = getSlotIndex(subId);
3937 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3938 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3939 + subId + "'");
3940 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3941 }
3942 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3943 transportType, aBoolean -> {
3944 try {
3945 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3946 } catch (RemoteException e) {
3947 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3948 + "running. Ignore");
3949 }
3950 });
3951 } finally {
3952 Binder.restoreCallingIdentity(token);
3953 }
3954 }
3955
shilu366312e2019-12-17 09:28:10 -08003956 /**
3957 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3958 * @param subId The subscription to use to check the configuration.
3959 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 @Override
3961 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003962 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3963 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003964
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3966 final long token = Binder.clearCallingIdentity();
3967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
3977 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003978 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003980 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003984 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003986 } catch (ImsException e) {
3987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 } finally {
3989 Binder.restoreCallingIdentity(identity);
3990 }
3991 }
3992
shilu366312e2019-12-17 09:28:10 -08003993 /**
3994 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3995 * @param subId The subscription to use to check the configuration.
3996 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003998 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003999 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4000 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004004 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4005 } catch (ImsException e) {
4006 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
4010 }
4011
4012 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004013 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004015 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004019 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004020 } catch (ImsException e) {
4021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025 }
4026
shilu366312e2019-12-17 09:28:10 -08004027 /**
4028 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4029 * @param subId The subscription to use to check the configuration.
4030 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 @Override
4032 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4034 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004038 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004048 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004050 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 @Override
4067 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004068 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4069 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
4080 }
4081
4082 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004083 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004085 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
4096 }
4097
4098 @Override
4099 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4101 "setVoWiFiNonPersistent");
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004105 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004106 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (ImsException e) {
4108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113
shilu366312e2019-12-17 09:28:10 -08004114 /**
4115 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4116 * @param subId The subscription to use to check the configuration.
4117 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 @Override
4119 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004120 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4121 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004125 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004127 } catch (ImsException e) {
4128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
4132 }
4133
4134 @Override
4135 public void setVoWiFiModeSetting(int subId, int mode) {
4136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4137 "setVoWiFiModeSetting");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
4151 public int getVoWiFiRoamingModeSetting(int subId) {
4152 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
4165 @Override
4166 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4168 "setVoWiFiRoamingModeSetting");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004174 } catch (ImsException e) {
4175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
4179 }
4180
4181 @Override
4182 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4184 "setRttCapabilityEnabled");
4185 final long identity = Binder.clearCallingIdentity();
4186 try {
4187 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4189 } catch (ImsException e) {
4190 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
4194 }
4195
shilu366312e2019-12-17 09:28:10 -08004196 /**
4197 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4198 * @param subId The subscription to use to check the configuration.
4199 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 @Override
4201 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004202 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4203 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 final long identity = Binder.clearCallingIdentity();
4205 try {
4206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004207 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 } catch (ImsException e) {
4210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
4213 }
4214 }
4215
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004216 @Override
4217 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4218 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004221 if (!isImsAvailableOnDevice()) {
4222 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4223 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004224 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004227 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004228 } catch (ImsException e) {
4229 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
4233 }
4234
4235 @Override
4236 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4237 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4238 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004239 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4240 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4241 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004242 try {
4243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004244 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004245 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004246 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004247 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4248 + "is inactive, ignoring unregister.");
4249 // If the subscription is no longer active, just return, since the callback will already
4250 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
allenwtsu99c623b2020-01-03 18:24:23 +08004256
4257 private void checkModifyPhoneStatePermission(int subId, String message) {
4258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4259 message);
4260 }
4261
4262 private boolean isImsProvisioningRequired(int subId, int capability,
4263 boolean isMmtelCapability) {
4264 Phone phone = getPhone(subId);
4265 if (phone == null) {
4266 loge("phone instance null for subid " + subId);
4267 return false;
4268 }
4269 if (isMmtelCapability) {
4270 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4271 return false;
4272 }
4273 } else {
4274 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4275 return false;
4276 }
4277 }
4278 return true;
4279 }
4280
4281 @Override
4282 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4283 boolean isProvisioned) {
4284 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4285
4286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4289 if (!isImsProvisioningRequired(subId, capability, false)) {
4290 return;
4291 }
4292
4293 // this capability requires provisioning, route to the correct API.
4294 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4295 switch (capability) {
4296 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4297 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4298 ims.setEabProvisioned(isProvisioned);
4299 break;
4300 default: {
4301 throw new IllegalArgumentException("Tried to set provisioning for "
4302 + "rcs capability '" + capability + "', which does not require "
4303 + "provisioning.");
4304 }
4305 }
4306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
4309
4310 }
4311
4312
4313 @Override
4314 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4315 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4319 if (!isImsProvisioningRequired(subId, capability, false)) {
4320 return true;
4321 }
4322
4323 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4324 switch (capability) {
4325 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4326 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4327 return ims.isEabProvisionedOnDevice();
4328
4329 default: {
4330 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4331 + "capability '" + capability + "', which does not require "
4332 + "provisioning.");
4333 }
4334 }
4335
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
4339 }
4340
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004341 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004342 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4343 boolean isProvisioned) {
4344 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4345 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4346 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4347 }
allenwtsu99c623b2020-01-03 18:24:23 +08004348 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004352 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 return;
4354 }
4355
4356 // this capability requires provisioning, route to the correct API.
4357 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4358 switch (capability) {
4359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4360 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4361 ims.setVolteProvisioned(isProvisioned);
4362 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4363 ims.setWfcProvisioned(isProvisioned);
4364 }
4365 break;
4366 }
4367 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4368 // There is currently no difference in VT provisioning type.
4369 ims.setVtProvisioned(isProvisioned);
4370 break;
4371 }
4372 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4373 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4374 // change the capability of the feature instead if needed.
4375 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4376 == isProvisioned) {
4377 // No change in provisioning.
4378 return;
4379 }
4380 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4381 try {
4382 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004383 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004384 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4385 + ", Exception" + e.getMessage());
4386 }
4387 break;
4388 }
4389 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004390 throw new IllegalArgumentException("Tried to set provisioning for "
4391 + "MmTel capability '" + capability + "', which does not require "
4392 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004393 }
4394 }
4395
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
4401 @Override
4402 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4403 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4404 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4405 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4406 }
4407 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004411 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004412 return true;
4413 }
4414
4415 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4416 switch (capability) {
4417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4418 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4419 return ims.isVolteProvisionedOnDevice();
4420 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4421 return ims.isWfcProvisionedOnDevice();
4422 }
4423 // This should never happen, since we are checking tech above to make sure it
4424 // is either LTE or IWLAN.
4425 throw new IllegalArgumentException("Invalid radio technology for voice "
4426 + "capability.");
4427 }
4428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4429 // There is currently no difference in VT provisioning type.
4430 return ims.isVtProvisionedOnDevice();
4431 }
4432 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4433 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4434 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4435 }
4436 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004437 throw new IllegalArgumentException(
4438 "Tried to get provisioning for MmTel capability '" + capability
4439 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004440 }
4441 }
4442
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
4448 @Override
4449 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4450 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4451 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4452 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4453 }
4454 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4455 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4456 return (provisionedBits & capability) > 0;
4457 }
4458
4459 @Override
4460 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4461 boolean isProvisioned) {
4462 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4463 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4464 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4465 }
4466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4467 "setProvisioningStatusForCapability");
4468 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4469 // If the current provisioning status for capability already matches isProvisioned,
4470 // do nothing.
4471 if (((provisionedBits & capability) > 0) == isProvisioned) {
4472 return;
4473 }
4474 if (isProvisioned) {
4475 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4476 } else {
4477 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4478 }
4479 }
4480
4481 /**
4482 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4483 * technology. The bitfield should mirror the bitfield defined by
4484 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4485 */
4486 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4487 String key = getMmTelProvisioningKey(subId, tech);
4488 // Default is no capabilities are provisioned.
4489 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4490 }
4491
4492 /**
4493 * Sets the MmTel capability provisioning bitfield (defined by
4494 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4495 * technology specified.
4496 *
4497 * Note: This is a synchronous command and should not be called on UI thread.
4498 */
4499 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4500 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4501 String key = getMmTelProvisioningKey(subId, tech);
4502 editor.putInt(key, newField);
4503 editor.commit();
4504 }
4505
4506 private static String getMmTelProvisioningKey(int subId, int tech) {
4507 // resulting key is provision_ims_mmtel_{subId}_{tech}
4508 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4509 }
4510
4511 /**
4512 * Query CarrierConfig to see if the specified capability requires provisioning for the
4513 * carrier associated with the subscription id.
4514 */
4515 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4516 int capability) {
4517 CarrierConfigManager configManager = new CarrierConfigManager(context);
4518 PersistableBundle c = configManager.getConfigForSubId(subId);
4519 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004520 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4522 false);
4523 boolean requireVoiceVtProvisioning = c.getBoolean(
4524 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4525
4526 // First check to make sure that the capability requires provisioning.
4527 switch (capability) {
4528 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4529 // intentional fallthrough
4530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4531 if (requireVoiceVtProvisioning) {
4532 // Voice and Video requires provisioning
4533 return true;
4534 }
4535 break;
4536 }
4537 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4538 if (requireUtProvisioning) {
4539 // UT requires provisioning
4540 return true;
4541 }
4542 break;
4543 }
4544 }
4545 return false;
4546 }
4547
allenwtsu99c623b2020-01-03 18:24:23 +08004548 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4549 int capability) {
4550 CarrierConfigManager configManager = new CarrierConfigManager(context);
4551 PersistableBundle c = configManager.getConfigForSubId(subId);
4552
4553 boolean requireRcsProvisioning = c.getBoolean(
4554 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4555
4556 // First check to make sure that the capability requires provisioning.
4557 switch (capability) {
4558 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4559 // intentional fallthrough
4560 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4561 if (requireRcsProvisioning) {
4562 // OPTION or PRESENCE requires provisioning
4563 return true;
4564 }
4565 break;
4566 }
4567 }
4568 return false;
4569 }
4570
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004571 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004572 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004573 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4574 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4575 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004576 enforceReadPrivilegedPermission("getImsProvisioningInt");
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 int slotId = getSlotIndex(subId);
4581 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4582 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4583 + subId + "' for key:" + key);
4584 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4585 }
4586 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004587 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004588 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4589 + subId + "' for key:" + key);
4590 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
4594 }
4595
4596 @Override
4597 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4599 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4600 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004601 enforceReadPrivilegedPermission("getImsProvisioningString");
4602 final long identity = Binder.clearCallingIdentity();
4603 try {
4604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 int slotId = getSlotIndex(subId);
4606 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4607 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4608 + subId + "' for key:" + key);
4609 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4610 }
4611 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004612 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004613 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4614 + subId + "' for key:" + key);
4615 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
4619 }
4620
4621 @Override
4622 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4624 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4625 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4627 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 int slotId = getSlotIndex(subId);
4632 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4633 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4634 + subId + "' for key:" + key);
4635 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4636 }
4637 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4640 + "' for key:" + key);
4641 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004642 } finally {
4643 Binder.restoreCallingIdentity(identity);
4644 }
4645 }
4646
4647 @Override
4648 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4650 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4651 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4653 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004654 final long identity = Binder.clearCallingIdentity();
4655 try {
4656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 int slotId = getSlotIndex(subId);
4658 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4659 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4660 + subId + "' for key:" + key);
4661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4662 }
4663 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4666 + "' for key:" + key);
4667 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
4671 }
4672
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 int slotId = SubscriptionManager.getSlotIndex(subId);
4675 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004676 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4677 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004678 }
4679 return slotId;
4680 }
4681
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 private int getSlotIndex(int subId) {
4683 int slotId = SubscriptionManager.getSlotIndex(subId);
4684 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4685 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4686 }
4687 return slotId;
4688 }
4689
Wink Saville36469e72014-06-11 15:17:00 -07004690 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004691 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004692 */
4693 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004694 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4695 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004696 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004697 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004698 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004699 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004700 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004701 mApp, subId, callingPackage, callingFeatureId,
4702 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004703 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4704 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 final Phone phone = getPhone(subId);
4709 if (phone != null) {
4710 return phone.getServiceState().getDataNetworkType();
4711 } else {
4712 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4713 }
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004717 }
4718
4719 /**
4720 * Returns the data network type
4721 */
4722 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004723 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4724 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4725 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004726 }
4727
4728 /**
4729 * Returns the data network type for a subId
4730 */
4731 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004732 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004735 mApp, subId, callingPackage, callingFeatureId,
4736 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004737 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4738 }
4739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 final Phone phone = getPhone(subId);
4743 if (phone != null) {
4744 return phone.getServiceState().getDataNetworkType();
4745 } else {
4746 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4747 }
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004751 }
4752
4753 /**
Wink Saville36469e72014-06-11 15:17:00 -07004754 * Returns the Voice network type for a subId
4755 */
4756 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004757 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4758 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004760 mApp, subId, callingPackage, callingFeatureId,
4761 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4763 }
4764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 final Phone phone = getPhone(subId);
4768 if (phone != null) {
4769 return phone.getServiceState().getVoiceNetworkType();
4770 } else {
4771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4772 }
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004776 }
4777
4778 /**
4779 * @return true if a ICC card is present
4780 */
4781 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004782 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004783 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4784 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004785 }
4786
4787 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004788 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004789 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004790 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004791 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 final long identity = Binder.clearCallingIdentity();
4793 try {
4794 final Phone phone = PhoneFactory.getPhone(slotIndex);
4795 if (phone != null) {
4796 return phone.getIccCard().hasIccCard();
4797 } else {
4798 return false;
4799 }
4800 } finally {
4801 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004802 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004803 }
4804
4805 /**
4806 * Return if the current radio is LTE on CDMA. This
4807 * is a tri-state return value as for a period of time
4808 * the mode may be unknown.
4809 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004810 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004811 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004812 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004813 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004814 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004815 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4816 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4817 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004818 }
4819
Sanket Padawe356d7632015-06-22 14:03:32 -07004820 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004821 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4822 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004823 try {
4824 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4825 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004826 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4827 }
4828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 final Phone phone = getPhone(subId);
4832 if (phone == null) {
4833 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4834 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004835 return TelephonyProperties.lte_on_cdma_device()
4836 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 }
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004840 }
Wink Saville36469e72014-06-11 15:17:00 -07004841 }
4842
Wink Saville36469e72014-06-11 15:17:00 -07004843 /**
4844 * {@hide}
4845 * Returns Default subId, 0 in the case of single standby.
4846 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004847 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004848 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004849 }
4850
Shishir Agrawala9f32182016-04-12 12:00:16 -07004851 private int getSlotForDefaultSubscription() {
4852 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4853 }
4854
Wink Savilleb564aae2014-10-23 10:18:09 -07004855 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004856 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004857 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004858
Pengquan Menge92a50d2018-09-21 15:54:48 -07004859 private boolean isActiveSubscription(int subId) {
4860 return mSubscriptionController.isActiveSubId(subId);
4861 }
4862
Ihab Awadf2177b72013-11-25 13:33:23 -08004863 /**
4864 * @see android.telephony.TelephonyManager.WifiCallingChoices
4865 */
4866 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004869 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4871 getWhenToMakeWifiCallsDefaultPreference());
4872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004875 }
4876
4877 /**
4878 * @see android.telephony.TelephonyManager.WifiCallingChoices
4879 */
4880 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004884 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004889 }
4890
Sailesh Nepald1e68152013-12-12 19:08:02 -08004891 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004892 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004893 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004894 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004895
Jordan Liu4c733742019-02-28 12:03:40 -08004896 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4897 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4898 if (phoneId == -1) {
4899 throw new IllegalArgumentException("Given slot index: " + slotIndex
4900 + " does not correspond to an active phone");
4901 }
4902 return PhoneFactory.getPhone(phoneId);
4903 }
4904
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004906 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4907 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4909 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004911 if (DBG) {
4912 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4913 }
4914 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4915 p2);
4916 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004917
Jordan Liu4c733742019-02-28 12:03:40 -08004918
4919 @Override
4920 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4921 int slotIndex, String callingPackage, String aid, int p2) {
4922 enforceModifyPermission();
4923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4924 if (DBG) {
4925 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4926 }
4927 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4928 callingPackage, aid, p2);
4929 }
4930
4931 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4932 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 if (TextUtils.equals(ISDR_AID, aid)) {
4936 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004937 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4938 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 if (bestComponent == null
4940 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4941 loge("The calling package is not allowed to access ISD-R.");
4942 throw new SecurityException(
4943 "The calling package is not allowed to access ISD-R.");
4944 }
Derek Tan740e1672017-06-27 14:56:27 -07004945 }
Derek Tan740e1672017-06-27 14:56:27 -07004946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004948 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4949 null /* workSource */);
4950 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 return response;
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004955 }
4956
4957 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004958 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004961 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4962 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4963 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004964
Jordan Liu4c733742019-02-28 12:03:40 -08004965 @Override
4966 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4967 enforceModifyPermission();
4968 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4969 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4970 channel);
4971 }
4972
4973 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 final long identity = Binder.clearCallingIdentity();
4975 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 if (channel < 0) {
4977 return false;
4978 }
Jordan Liu4c733742019-02-28 12:03:40 -08004979 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4980 null /* workSource */);
4981 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 return success;
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004986 }
4987
4988 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004989 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004990 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4992 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004993 if (DBG) {
4994 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4995 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4996 + p3 + " data=" + data);
4997 }
4998 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4999 command, p1, p2, p3, data);
5000 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005001
Jordan Liu4c733742019-02-28 12:03:40 -08005002 @Override
5003 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5004 int command, int p1, int p2, int p3, String data) {
5005 enforceModifyPermission();
5006 if (DBG) {
5007 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5008 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5009 + p3 + " data=" + data);
5010 }
5011 return iccTransmitApduLogicalChannelWithPermission(
5012 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5013 data);
5014 }
5015
5016 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5017 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005020 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 return "";
5022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005025 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5026 null /* workSource */);
5027 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 // Append the returned status code to the end of the response payload.
5030 String s = Integer.toHexString(
5031 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5032 if (response.payload != null) {
5033 s = IccUtils.bytesToHexString(response.payload) + s;
5034 }
5035 return s;
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005038 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005039 }
Jake Hambye994d462014-02-03 13:10:13 -08005040
Evan Charltonc66da362014-05-16 14:06:40 -07005041 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005042 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5043 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5045 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005047 if (DBG) {
5048 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5049 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5050 }
5051 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5052 cla, command, p1, p2, p3, data);
5053 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005054
Jordan Liu4c733742019-02-28 12:03:40 -08005055 @Override
5056 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5057 int command, int p1, int p2, int p3, String data) {
5058 enforceModifyPermission();
5059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5060 if (DBG) {
5061 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5062 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5063 + " data=" + data);
5064 }
5065
5066 return iccTransmitApduBasicChannelWithPermission(
5067 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5068 p2, p3, data);
5069 }
5070
5071 // open APDU basic channel assuming the caller has sufficient permissions
5072 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5073 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5077 && TextUtils.equals(ISDR_AID, data)) {
5078 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005079 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5080 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 if (bestComponent == null
5082 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5083 loge("The calling package is not allowed to select ISD-R.");
5084 throw new SecurityException(
5085 "The calling package is not allowed to select ISD-R.");
5086 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005087 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005090 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5091 null /* workSource */);
5092 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 // Append the returned status code to the end of the response payload.
5095 String s = Integer.toHexString(
5096 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5097 if (response.payload != null) {
5098 s = IccUtils.bytesToHexString(response.payload) + s;
5099 }
5100 return s;
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005103 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005104 }
5105
5106 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005107 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005108 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5110 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 if (DBG) {
5115 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5116 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5117 }
5118
5119 IccIoResult response =
5120 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5121 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5122 subId);
5123
5124 if (DBG) {
5125 log("Exchange SIM_IO [R]" + response);
5126 }
5127
5128 byte[] result = null;
5129 int length = 2;
5130 if (response.payload != null) {
5131 length = 2 + response.payload.length;
5132 result = new byte[length];
5133 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5134 } else {
5135 result = new byte[length];
5136 }
5137
5138 result[length - 1] = (byte) response.sw2;
5139 result[length - 2] = (byte) response.sw1;
5140 return result;
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005143 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005144 }
5145
Nathan Haroldb3014052017-01-25 15:57:32 -08005146 /**
5147 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5148 * on a particular subscription
5149 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005150 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5151 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005153 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005154 return null;
5155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156
5157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 if (appType != TelephonyManager.APPTYPE_USIM
5160 && appType != TelephonyManager.APPTYPE_SIM) {
5161 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5162 return null;
5163 }
5164 Object response = sendRequest(
5165 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5166 if (response instanceof String[]) {
5167 return (String[]) response;
5168 }
yincheng zhaod698b842019-09-06 17:06:54 -07005169 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005171 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005174 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005175 }
5176
yincheng zhaod698b842019-09-06 17:06:54 -07005177 /**
5178 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5179 * subscription.
5180 *
5181 * @param subId the id of the subscription.
5182 * @param appType the uicc app type, must be USIM or SIM.
5183 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5184 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005185 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005186 * @return number of fplmns that is successfully written to the SIM.
5187 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005188 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5189 String callingFeatureId) {
5190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5191 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005192 if (DBG) logv("no permissions for setForbiddenplmns");
5193 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5194 }
5195 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5196 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5197 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5198 }
5199 if (fplmns == null) {
5200 throw new IllegalArgumentException("Fplmn List provided is null");
5201 }
5202 for (String fplmn : fplmns) {
5203 if (!CellIdentity.isValidPlmn(fplmn)) {
5204 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5205 }
5206 }
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 Object response = sendRequest(
5210 CMD_SET_FORBIDDEN_PLMNS,
5211 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5212 subId);
5213 return (int) response;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
5217 }
5218
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005220 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5227 if (response.payload == null) {
5228 return "";
5229 }
Evan Charltonc66da362014-05-16 14:06:40 -07005230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 // Append the returned status code to the end of the response payload.
5232 String s = Integer.toHexString(
5233 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5234 s = IccUtils.bytesToHexString(response.payload) + s;
5235 return s;
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Evan Charltonc66da362014-05-16 14:06:40 -07005239 }
5240
Jake Hambye994d462014-02-03 13:10:13 -08005241 /**
5242 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5243 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5244 *
5245 * @param itemID the ID of the item to read
5246 * @return the NV item as a String, or null on error.
5247 */
5248 @Override
5249 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005250 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5252 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253
5254 final long identity = Binder.clearCallingIdentity();
5255 try {
5256 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005257 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5259 return value;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Jake Hambye994d462014-02-03 13:10:13 -08005263 }
5264
5265 /**
5266 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5267 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5268 *
5269 * @param itemID the ID of the item to read
5270 * @param itemValue the value to write, as a String
5271 * @return true on success; false on any failure
5272 */
5273 @Override
5274 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
5279 final long identity = Binder.clearCallingIdentity();
5280 try {
5281 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5282 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005283 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5285 return success;
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Jake Hambye994d462014-02-03 13:10:13 -08005289 }
5290
5291 /**
5292 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5293 * Used for device configuration by some CDMA operators.
5294 *
5295 * @param preferredRoamingList byte array containing the new PRL
5296 * @return true on success; false on any failure
5297 */
5298 @Override
5299 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5301 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302
5303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5306 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5307 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5308 return success;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Jake Hambye994d462014-02-03 13:10:13 -08005312 }
5313
5314 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005315 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005316 * Used for device configuration by some CDMA operators.
5317 *
chen xu6dac5ab2018-10-26 17:39:23 -07005318 * @param slotIndex - device slot.
5319 *
Jake Hambye994d462014-02-03 13:10:13 -08005320 * @return true on success; false on any failure
5321 */
5322 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005323 public boolean resetModemConfig(int slotIndex) {
5324 Phone phone = PhoneFactory.getPhone(slotIndex);
5325 if (phone != null) {
5326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328
chen xu6dac5ab2018-10-26 17:39:23 -07005329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5332 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5333 return success;
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
5336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 }
chen xu6dac5ab2018-10-26 17:39:23 -07005338 return false;
5339 }
5340
5341 /**
5342 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5343 *
5344 * @param slotIndex - device slot.
5345 *
5346 * @return true on success; false on any failure
5347 */
5348 @Override
5349 public boolean rebootModem(int slotIndex) {
5350 Phone phone = PhoneFactory.getPhone(slotIndex);
5351 if (phone != null) {
5352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5353 mApp, phone.getSubId(), "rebootModem");
5354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5358 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5359 return success;
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
5363 }
5364 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005365 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005366
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005367 public String[] getPcscfAddress(String apnType, String callingPackage,
5368 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005369 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5371 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005372 return new String[0];
5373 }
5374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005377 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Wink Saville36469e72014-06-11 15:17:00 -07005381 }
5382
Brad Ebinger51f743a2017-01-23 13:50:20 -08005383 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005384 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5385 * {@link #disableIms(int)}.
5386 * @param slotIndex device slot.
5387 */
5388 public void resetIms(int slotIndex) {
5389 enforceModifyPermission();
5390
5391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 if (mImsResolver == null) {
5394 // may happen if the does not support IMS.
5395 return;
5396 }
5397 mImsResolver.disableIms(slotIndex);
5398 mImsResolver.enableIms(slotIndex);
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
5402 }
5403
5404 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005405 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5406 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005407 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005408 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005409 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005413 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005414 // may happen if the device does not support IMS.
5415 return;
5416 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005417 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005421 }
5422
5423 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005424 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5425 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005426 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005427 public void disableIms(int slotId) {
5428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429
5430 final long identity = Binder.clearCallingIdentity();
5431 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005432 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005433 // may happen if the device does not support IMS.
5434 return;
5435 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005436 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005440 }
5441
5442 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005443 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5444 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005445 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005446 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005447 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005452 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005453 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5454 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005455 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005456 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005460 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005461 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005462 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5463 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005464 @Override
5465 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005466 enforceModifyPermission();
5467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005471 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
5475 }
5476
5477 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005478 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005479 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005480 */
5481 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005486 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005487 // may happen if the device does not support IMS.
5488 return null;
5489 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005494 }
5495
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005496 /**
5497 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005498 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005499 */
5500 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502
5503 final long identity = Binder.clearCallingIdentity();
5504 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005505 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005506 // may happen if the device does not support IMS.
5507 return null;
5508 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005513 }
5514
Brad Ebinger884c07b2018-02-15 16:17:40 -08005515 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005516 * Sets the ImsService Package Name that Telephony will bind to.
5517 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005518 * @param slotIndex the slot ID that the ImsService should bind for.
5519 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005520 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005521 * @param featureTypes An integer array of feature types associated with a packageName.
5522 * @param packageName The name of the package that the current configuration will be replaced
5523 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005524 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005525 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005526 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5527 int[] featureTypes, String packageName) {
5528 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5529 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5531 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005532 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 final long identity = Binder.clearCallingIdentity();
5535 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005536 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005537 // may happen if the device does not support IMS.
5538 return false;
5539 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005540 Map<Integer, String> featureConfig = new HashMap<>();
5541 for (int featureType : featureTypes) {
5542 featureConfig.put(featureType, packageName);
5543 }
5544 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5545 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005549 }
5550
5551 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005552 * Clears any carrier ImsService overrides for the slot index specified that were previously
5553 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5554 *
5555 * This should only be used for testing.
5556 *
5557 * @param slotIndex the slot ID that the ImsService should bind for.
5558 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5559 */
5560 @Override
5561 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5562 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5564 "clearCarrierImsServiceOverride");
5565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5566 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5567 "clearCarrierImsServiceOverride");
5568
5569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 if (mImsResolver == null) {
5572 // may happen if the device does not support IMS.
5573 return false;
5574 }
5575 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
5579 }
5580
5581 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005583 *
5584 * @param slotId The slot that the ImsService is associated with.
5585 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5586 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005587 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005588 * @return the package name of the ImsService configuration.
5589 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005590 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5591 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005592 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005593 TelephonyPermissions
5594 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5595 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5596 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 final long identity = Binder.clearCallingIdentity();
5599 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005600 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005601 // may happen if the device does not support IMS.
5602 return "";
5603 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005604 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005605 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5606 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005610 }
5611
Brad Ebinger77b832e2019-10-17 17:03:22 -07005612 /**
5613 * Get the MmTelFeature state associated with the requested subscription id.
5614 * @param subId The subscription that the MmTelFeature is associated with.
5615 * @param callback A callback with an integer containing the
5616 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5617 */
5618 @Override
5619 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5620 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5621 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5622 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5623 "IMS not available on device.");
5624 }
5625 final long token = Binder.clearCallingIdentity();
5626 try {
5627 int slotId = getSlotIndex(subId);
5628 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5629 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5630 + subId + "'");
5631 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5632 }
5633 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5634 try {
5635 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5636 } catch (RemoteException e) {
5637 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5638 + "Ignore");
5639 }
5640 });
5641 } finally {
5642 Binder.restoreCallingIdentity(token);
5643 }
5644 }
5645
Daniel Brightbb5840b2021-01-12 15:48:18 -08005646 /**
5647 * Sets the ims registration state on all valid {@link Phone}s.
5648 */
5649 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005654 // NOTE: Before S, this method only set the default phone.
5655 for (final Phone phone : PhoneFactory.getPhones()) {
5656 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5657 phone.setImsRegistrationState(registered);
5658 }
5659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
Wink Saville36469e72014-06-11 15:17:00 -07005663 }
5664
5665 /**
Stuart Scott54788802015-03-30 13:18:01 -07005666 * Set the network selection mode to automatic.
5667 *
5668 */
5669 @Override
5670 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
shilufc958392020-01-20 11:36:01 -08005676 if (!isActiveSubscription(subId)) {
5677 return;
5678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005680 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5681 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Stuart Scott54788802015-03-30 13:18:01 -07005685 }
5686
Jack Yud10cdd42020-09-28 20:28:01 -07005687 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005688 * Ask the radio to connect to the input network and change selection mode to manual.
5689 *
5690 * @param subId the id of the subscription.
5691 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5692 * the operator to attach to.
5693 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5694 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5695 * normal network selection next time.
5696 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005697 */
5698 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005699 public boolean setNetworkSelectionModeManual(
5700 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5702 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005703
5704 if (!isActiveSubscription(subId)) {
5705 return false;
5706 }
5707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005710 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005712 if (DBG) {
5713 log("setNetworkSelectionModeManual: subId: " + subId
5714 + " operator: " + operatorInfo);
5715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005720 }
shilu84f6e8b2019-12-19 13:58:01 -08005721 /**
5722 * Get the manual network selection
5723 *
5724 * @param subId the id of the subscription.
5725 *
5726 * @return the previously saved user selected PLMN
5727 */
5728 @Override
5729 public String getManualNetworkSelectionPlmn(int subId) {
5730 TelephonyPermissions
5731 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5732 mApp, subId, "getManualNetworkSelectionPlmn");
5733
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 if (!isActiveSubscription(subId)) {
5737 return "";
5738 }
5739
5740 final Phone phone = getPhone(subId);
5741 if (phone == null) {
5742 return "";
5743 }
5744 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5745 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5746 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005751
5752 /**
5753 * Scans for available networks.
5754 */
5755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005756 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5757 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5759 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005760 LocationAccessPolicy.LocationPermissionResult locationResult =
5761 LocationAccessPolicy.checkLocationPermission(mApp,
5762 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5763 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005764 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005765 .setCallingPid(Binder.getCallingPid())
5766 .setCallingUid(Binder.getCallingUid())
5767 .setMethod("getCellNetworkScanResults")
5768 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5769 .build());
5770 switch (locationResult) {
5771 case DENIED_HARD:
5772 throw new SecurityException("Not allowed to access scan results -- location");
5773 case DENIED_SOFT:
5774 return null;
5775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776
Pengquan Menga1bb6272018-09-06 09:59:22 -07005777 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 try {
5779 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005780 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005785 }
5786
5787 /**
sqian80370722020-01-29 15:02:51 -08005788 * Get the call forwarding info, given the call forwarding reason.
5789 */
5790 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005791 public void getCallForwarding(int subId, int callForwardingReason,
5792 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005793 enforceReadPrivilegedPermission("getCallForwarding");
5794 long identity = Binder.clearCallingIdentity();
5795 try {
5796 if (DBG) {
5797 log("getCallForwarding: subId " + subId
5798 + " callForwardingReason" + callForwardingReason);
5799 }
Hall Liua1acea22020-09-18 19:04:59 -07005800
5801 Phone phone = getPhone(subId);
5802 if (phone == null) {
5803 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005804 callback.onError(
5805 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005806 } catch (RemoteException e) {
5807 // ignore
5808 }
5809 return;
5810 }
5811
5812 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5813 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5814 @Override
5815 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5816 try {
5817 callback.onCallForwardingInfoAvailable(info);
5818 } catch (RemoteException e) {
5819 // ignore
5820 }
5821 }
5822
5823 @Override
5824 public void onError(int error) {
5825 try {
5826 callback.onError(error);
5827 } catch (RemoteException e) {
5828 // ignore
5829 }
5830 }
5831 });
5832 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
5838 /**
5839 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5840 * reason, the number to forward, and the timeout before the forwarding is attempted.
5841 */
5842 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005843 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5844 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005845 enforceModifyPermission();
5846 long identity = Binder.clearCallingIdentity();
5847 try {
5848 if (DBG) {
5849 log("setCallForwarding: subId " + subId
5850 + " callForwardingInfo" + callForwardingInfo);
5851 }
Hall Liua1acea22020-09-18 19:04:59 -07005852
5853 Phone phone = getPhone(subId);
5854 if (phone == null) {
5855 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005856 callback.accept(
5857 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005858 } catch (RemoteException e) {
5859 // ignore
5860 }
5861 return;
5862 }
5863
5864 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5865 FunctionalUtils.ignoreRemoteException(callback::accept));
5866
5867 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
5871 }
5872
5873 /**
Hall Liua1acea22020-09-18 19:04:59 -07005874 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005875 */
5876 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005877 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005878 enforceReadPrivilegedPermission("getCallForwarding");
5879 long identity = Binder.clearCallingIdentity();
5880 try {
Hall Liua1acea22020-09-18 19:04:59 -07005881
5882 Phone phone = getPhone(subId);
5883 if (phone == null) {
5884 try {
5885 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5886 } catch (RemoteException e) {
5887 // ignore
5888 }
5889 return;
5890 }
5891
5892 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5893
sqian80370722020-01-29 15:02:51 -08005894 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005895 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
5899 }
5900
5901 /**
Hall Liua1acea22020-09-18 19:04:59 -07005902 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005903 */
5904 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005905 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005906 enforceModifyPermission();
5907 long identity = Binder.clearCallingIdentity();
5908 try {
Hall Liua1acea22020-09-18 19:04:59 -07005909 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5910
5911 Phone phone = getPhone(subId);
5912 if (phone == null) {
5913 try {
5914 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5915 } catch (RemoteException e) {
5916 // ignore
5917 }
5918 return;
5919 }
5920
5921 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5922 FunctionalUtils.ignoreRemoteException(callback::accept));
5923
5924 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
5928 }
5929
5930 /**
yinxub1bed742017-04-17 11:45:04 -07005931 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005932 *
yinxub1bed742017-04-17 11:45:04 -07005933 * @param subId id of the subscription
5934 * @param request contains the radio access networks with bands/channels to scan
5935 * @param messenger callback messenger for scan results or errors
5936 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005937 * @return the id of the requested scan which can be used to stop the scan.
5938 */
5939 @Override
5940 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005941 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005944 LocationAccessPolicy.LocationPermissionResult locationResult =
5945 LocationAccessPolicy.checkLocationPermission(mApp,
5946 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5947 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005948 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005949 .setCallingPid(Binder.getCallingPid())
5950 .setCallingUid(Binder.getCallingUid())
5951 .setMethod("requestNetworkScan")
5952 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5953 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005954 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005955 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5956 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005957 if (e != null) {
5958 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5959 throw e;
5960 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005961 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005962 return TelephonyScanManager.INVALID_SCAN_ID;
5963 }
5964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 }
Hall Liu912dfd32019-04-25 14:02:26 -07005966 int callingUid = Binder.getCallingUid();
5967 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 return mNetworkScanRequestTracker.startNetworkScan(
5971 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005972 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005973 } finally {
5974 Binder.restoreCallingIdentity(identity);
5975 }
yinxu504e1392017-04-12 16:03:22 -07005976 }
5977
Hall Liub2ac8ef2019-02-28 15:56:23 -08005978 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005979 NetworkScanRequest request, int subId, String callingPackage) {
5980 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005981 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5982 boolean hasNetworkScanPermission =
5983 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5984 == PERMISSION_GRANTED;
5985
5986 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5987 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5988 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005989 }
5990
5991 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5992 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005993 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5994 return new SecurityException("Specific channels must not be"
5995 + " scanned without location access.");
5996 }
5997 }
5998 }
5999
Hall Liub2ac8ef2019-02-28 15:56:23 -08006000 return null;
6001 }
6002
yinxu504e1392017-04-12 16:03:22 -07006003 /**
6004 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006005 *
6006 * @param subId id of the subscription
6007 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006008 */
6009 @Override
6010 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013
Hall Liu912dfd32019-04-25 14:02:26 -07006014 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006017 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
yinxu504e1392017-04-12 16:03:22 -07006021 }
6022
6023 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006024 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006025 *
SongFerngWang9e060372020-12-21 16:41:52 +08006026 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006027 */
6028 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006029 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006030 TelephonyPermissions
6031 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006032 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006036 if (DBG) log("getAllowedNetworkTypesBitmask");
6037 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6038 int networkTypesBitmask = (result != null ? result[0] : -1);
6039 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6040 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006044 }
6045
6046 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006047 * Get the allowed network types for certain reason.
6048 *
6049 * @param subId the id of the subscription.
6050 * @param reason the reason the allowed network type change is taking place
6051 * @return the allowed network types.
6052 */
6053 @Override
6054 public long getAllowedNetworkTypesForReason(int subId,
6055 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6056 TelephonyPermissions
6057 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6058 mApp, subId, "getAllowedNetworkTypesForReason");
6059 final long identity = Binder.clearCallingIdentity();
6060 try {
6061 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 }
6066
6067 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006068 * Enable/Disable E-UTRA-NR Dual Connectivity
6069 * @param subId subscription id of the sim card
6070 * @param nrDualConnectivityState expected NR dual connectivity state
6071 * This can be passed following states
6072 * <ol>
6073 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6074 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6075 * <li>Disable NR dual connectivity and force secondary cell to be released
6076 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6077 * </ol>
6078 * @return operation result.
6079 */
6080 @Override
6081 public int setNrDualConnectivityState(int subId,
6082 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6084 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006085 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006086 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6087 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6088 }
6089
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6094 nrDualConnectivityState, subId,
6095 workSource);
6096 if (DBG) log("enableNRDualConnectivity result: " + result);
6097 return result;
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
6101 }
6102
6103 /**
6104 * Is E-UTRA-NR Dual Connectivity enabled
6105 * @return true if dual connectivity is enabled else false
6106 */
6107 @Override
6108 public boolean isNrDualConnectivityEnabled(int subId) {
6109 TelephonyPermissions
6110 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6111 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006112 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006113 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6114 return false;
6115 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6117 final long identity = Binder.clearCallingIdentity();
6118 try {
6119 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6120 null, subId, workSource);
6121 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6122 return isEnabled;
6123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
6126 }
6127
6128 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006129 * Set the allowed network types of the device and
6130 * provide the reason triggering the allowed network change.
6131 *
6132 * @param subId the id of the subscription.
6133 * @param reason the reason the allowed network type change is taking place
6134 * @param allowedNetworkTypes the allowed network types.
6135 * @return true on success; false on any failure.
6136 */
6137 @Override
6138 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006139 @TelephonyManager.AllowedNetworkTypesReason int reason,
6140 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6142 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006143 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6144 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6145 return false;
6146 }
6147
6148 if (DBG) {
6149 log("setAllowedNetworkTypesForReason: " + reason
6150 + " value: " + allowedNetworkTypes);
6151 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006152 final long identity = Binder.clearCallingIdentity();
6153 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006154 Boolean success = (Boolean) sendRequest(
6155 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6156 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6157
6158 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6159 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006160 } finally {
6161 Binder.restoreCallingIdentity(identity);
6162 }
6163 }
6164
6165 /**
Miaoa84611c2019-03-15 09:21:10 +08006166 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006167 *
Miaoa84611c2019-03-15 09:21:10 +08006168 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006169 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006170 * @hide
6171 */
6172 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006173 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006176 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 try {
Miaoa84611c2019-03-15 09:21:10 +08006178 if (phone != null) {
6179 return phone.hasMatchedTetherApnSetting();
6180 } else {
6181 return false;
6182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 } finally {
6184 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006185 }
Junda Liu475951f2014-11-07 16:45:03 -08006186 }
6187
6188 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006189 * Enable or disable always reporting signal strength changes from radio.
6190 *
6191 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6192 */
6193 @Override
6194 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6195 enforceModifyPermission();
6196 enforceSystemCaller();
6197
6198 final long identity = Binder.clearCallingIdentity();
6199 final Phone phone = getPhone(subId);
6200 try {
6201 if (phone != null) {
6202 if (DBG) {
6203 log("setAlwaysReportSignalStrength: subId=" + subId
6204 + " isEnable=" + isEnable);
6205 }
6206 phone.setAlwaysReportSignalStrength(isEnable);
6207 } else {
6208 loge("setAlwaysReportSignalStrength: no phone found for subId="
6209 + subId);
6210 }
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006217 * Get the user enabled state of Mobile Data.
6218 *
6219 * TODO: remove and use isUserDataEnabled.
6220 * This can't be removed now because some vendor codes
6221 * calls through ITelephony directly while they should
6222 * use TelephonyManager.
6223 *
6224 * @return true on enabled
6225 */
6226 @Override
6227 public boolean getDataEnabled(int subId) {
6228 return isUserDataEnabled(subId);
6229 }
6230
6231 /**
6232 * Get whether mobile data is enabled per user setting.
6233 *
6234 * There are other factors deciding whether mobile data is actually enabled, but they are
6235 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006236 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006237 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006238 *
6239 * @return {@code true} if data is enabled else {@code false}
6240 */
6241 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006242 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006243 try {
6244 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6245 null);
6246 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6248 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250
6251 final long identity = Binder.clearCallingIdentity();
6252 try {
6253 int phoneId = mSubscriptionController.getPhoneId(subId);
6254 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6255 Phone phone = PhoneFactory.getPhone(phoneId);
6256 if (phone != null) {
6257 boolean retVal = phone.isUserDataEnabled();
6258 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6259 return retVal;
6260 } else {
6261 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6262 return false;
6263 }
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006266 }
6267 }
6268
6269 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006270 * Checks if the device is capable of mobile data by considering whether whether the
6271 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6272 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006273 *
Shuo Qian985d1232020-01-08 14:30:06 -08006274 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006275 */
6276 @Override
6277 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006278 try {
6279 try {
6280 mApp.enforceCallingOrSelfPermission(
6281 android.Manifest.permission.ACCESS_NETWORK_STATE,
6282 null);
6283 } catch (Exception e) {
6284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6285 "isDataEnabled");
6286 }
6287 } catch (Exception e) {
6288 enforceReadPrivilegedPermission("isDataEnabled");
6289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 int phoneId = mSubscriptionController.getPhoneId(subId);
6294 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6295 Phone phone = PhoneFactory.getPhone(phoneId);
6296 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006297 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6299 return retVal;
6300 } else {
6301 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6302 return false;
6303 }
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006306 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006307 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006308
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006309 /**
6310 * Check if data is enabled for a specific reason
6311 * @param subId Subscription index
6312 * @param reason the reason the data enable change is taking place
6313 * @return {@code true} if the overall data is enabled; {@code false} if not.
6314 */
6315 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006316 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006317 @TelephonyManager.DataEnabledReason int reason) {
6318 try {
6319 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6320 null);
6321 } catch (Exception e) {
6322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006323 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006324 }
6325
6326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 int phoneId = mSubscriptionController.getPhoneId(subId);
6330 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006331 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006332 + " reason=" + reason);
6333 }
6334 Phone phone = PhoneFactory.getPhone(phoneId);
6335 if (phone != null) {
6336 boolean retVal;
6337 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6338 retVal = phone.isUserDataEnabled();
6339 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006340 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006341 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006342 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006343 return retVal;
6344 } else {
6345 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006346 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006347 + subId + " retVal=false");
6348 }
6349 return false;
6350 }
6351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
6354 }
6355
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006356 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006357 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006358 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6359 // Skip the check if it's one of these special uids
6360 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6361 }
6362
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006363 //load access rules from carrier configs, and check those as well: b/139133814
6364 SubscriptionController subController = SubscriptionController.getInstance();
6365 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6366 || subController == null) return privilegeFromSim;
6367
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006368 PackageManager pkgMgr = phone.getContext().getPackageManager();
6369 String[] packages = pkgMgr.getPackagesForUid(uid);
6370
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006373 int subId = phone.getSubId();
6374 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6375 // A test override is in place for the privileges for this subId, so don't try to
6376 // read the subscription privileges.
6377 return privilegeFromSim;
6378 }
6379 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006380 SubscriptionManager subManager = (SubscriptionManager)
6381 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6382 for (String pkg : packages) {
6383 if (subManager.canManageSubscription(subInfo, pkg)) {
6384 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6385 }
6386 }
6387 return privilegeFromSim;
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
6391 }
6392
6393 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6394 String pkgName) {
6395 //load access rules from carrier configs, and check those as well: b/139133814
6396 SubscriptionController subController = SubscriptionController.getInstance();
6397 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6398 || subController == null) return privilegeFromSim;
6399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006402 int subId = phone.getSubId();
6403 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6404 // A test override is in place for the privileges for this subId, so don't try to
6405 // read the subscription privileges.
6406 return privilegeFromSim;
6407 }
6408 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006409 SubscriptionManager subManager = (SubscriptionManager)
6410 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6411 return subManager.canManageSubscription(subInfo, pkgName)
6412 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
6416 }
6417
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006419 public int getCarrierPrivilegeStatus(int subId) {
6420 final Phone phone = getPhone(subId);
6421 if (phone == null) {
6422 loge("getCarrierPrivilegeStatus: Invalid subId");
6423 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6424 }
6425 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006426 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006427 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006428 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6429 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006430
6431 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6432 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006433 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006434 }
Junda Liu29340342014-07-10 15:23:27 -07006435
6436 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006437 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006438 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006439 final Phone phone = getPhone(subId);
6440 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006441 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006442 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6443 }
6444 UiccProfile profile =
6445 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6446 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006447 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6449 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006450 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006451 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006452 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 }
6454
6455 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006456 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6457 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006459 }
6460
6461 int phoneId = SubscriptionManager.getPhoneId(subId);
6462 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006463 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006464 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006465 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6466 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006467 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6468 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6469 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006470 }
6471
6472 @Override
6473 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006474 if (TextUtils.isEmpty(pkgName))
6475 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006476 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6477 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6478 UiccCard card = UiccController.getInstance().getUiccCard(i);
6479 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006480 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006481 continue;
6482 }
6483
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006484 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6485 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6486 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006487 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6488 break;
6489 }
6490 }
6491
6492 return result;
Junda Liu29340342014-07-10 15:23:27 -07006493 }
Derek Tan89e89d42014-07-08 17:00:10 -07006494
6495 @Override
Junda Liue64de782015-04-16 17:19:16 -07006496 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6497 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6498 loge("phoneId " + phoneId + " is not valid.");
6499 return null;
6500 }
6501 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006502 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006503 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006504 return null ;
6505 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006506 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006507 }
6508
Amith Yamasani6e118872016-02-19 12:53:51 -08006509 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006510 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006512 List<String> privilegedPackages = new ArrayList<>();
6513 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006514 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6515 // has UICC in that slot.
6516 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006517 if (card.hasCarrierPrivilegeRules()) {
6518 if (packages == null) {
6519 // Only check packages in user 0 for now
6520 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006521 PackageManager.MATCH_DISABLED_COMPONENTS
6522 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006523 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006524 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006525 }
6526 for (int p = packages.size() - 1; p >= 0; p--) {
6527 PackageInfo pkgInfo = packages.get(p);
6528 if (pkgInfo != null && pkgInfo.packageName != null
6529 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006530 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006531 privilegedPackages.add(pkgInfo.packageName);
6532 }
6533 }
6534 }
6535 }
6536 return privilegedPackages;
6537 }
6538
chen xuf7e9fe82019-05-09 19:31:02 -07006539 @Override
6540 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006541 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6542
6543 final long identity = Binder.clearCallingIdentity();
6544
chen xuf7e9fe82019-05-09 19:31:02 -07006545 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006546 try {
6547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6548 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6549 }
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006552 }
6553 return privilegedPackages;
6554 }
6555
Wink Savilleb564aae2014-10-23 10:18:09 -07006556 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006557 final Phone phone = getPhone(subId);
6558 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006559 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006560 return null;
6561 }
6562 String iccId = card.getIccId();
6563 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006564 return null;
6565 }
6566 return iccId;
6567 }
6568
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006569 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006570 public void setCallComposerStatus(int subId, int status) {
6571 enforceModifyPermission();
6572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 Phone phone = getPhone(subId);
6576 if (phone != null) {
6577 Phone defaultPhone = phone.getImsPhone();
6578 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6579 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6580 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006581 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6582 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006583 }
6584 }
Shuo Qiand8782462020-12-22 19:10:14 -08006585 } catch (ImsException e) {
6586 throw new ServiceSpecificException(e.getCode());
6587 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006588 Binder.restoreCallingIdentity(identity);
6589 }
6590 }
6591
6592 @Override
6593 public int getCallComposerStatus(int subId) {
6594 enforceReadPrivilegedPermission("getCallComposerStatus");
6595
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
6598 Phone phone = getPhone(subId);
6599 if (phone != null) {
6600 Phone defaultPhone = phone.getImsPhone();
6601 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6602 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6603 return imsPhone.getCallComposerStatus();
6604 }
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6610 }
6611
6612 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006613 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6614 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006615 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006616 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 final String iccId = getIccId(subId);
6621 final Phone phone = getPhone(subId);
6622 if (phone == null) {
6623 return false;
6624 }
6625 final String subscriberId = phone.getSubscriberId();
6626
6627 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006628 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 + subscriberId + " to " + number);
6630 }
6631
6632 if (TextUtils.isEmpty(iccId)) {
6633 return false;
6634 }
6635
6636 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6637
6638 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6639 if (alphaTag == null) {
6640 editor.remove(alphaTagPrefKey);
6641 } else {
6642 editor.putString(alphaTagPrefKey, alphaTag);
6643 }
6644
6645 // Record both the line number and IMSI for this ICCID, since we need to
6646 // track all merged IMSIs based on line number
6647 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6648 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6649 if (number == null) {
6650 editor.remove(numberPrefKey);
6651 editor.remove(subscriberPrefKey);
6652 } else {
6653 editor.putString(numberPrefKey, number);
6654 editor.putString(subscriberPrefKey, subscriberId);
6655 }
6656
6657 editor.commit();
6658 return true;
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006661 }
Derek Tan7226c842014-07-02 17:42:23 -07006662 }
6663
6664 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006665 public String getLine1NumberForDisplay(int subId, String callingPackage,
6666 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006667 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006669 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006670 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006671 return null;
6672 }
Derek Tan97ebb422014-09-05 16:55:38 -07006673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 String iccId = getIccId(subId);
6677 if (iccId != null) {
6678 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6679 if (DBG_MERGE) {
6680 log("getLine1NumberForDisplay returning "
6681 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6682 }
6683 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6686 return null;
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006689 }
Derek Tan7226c842014-07-02 17:42:23 -07006690 }
6691
6692 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006693 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6694 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006696 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006697 return null;
6698 }
Derek Tan97ebb422014-09-05 16:55:38 -07006699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 String iccId = getIccId(subId);
6703 if (iccId != null) {
6704 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6705 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6706 }
6707 return null;
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006710 }
Derek Tan7226c842014-07-02 17:42:23 -07006711 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006712
6713 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006714 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6715 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006716 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6717 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006719 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006720 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006721 return null;
6722 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006723
Jordan Liub49b04b2019-05-06 14:45:15 -07006724 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6725 // the process, where TelephonyManager was instantiated.
6726 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006727 final long identity = Binder.clearCallingIdentity();
6728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006729 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 final TelephonyManager tele = TelephonyManager.from(context);
6731 final SubscriptionManager sub = SubscriptionManager.from(context);
6732
6733 // Figure out what subscribers are currently active
6734 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735
Jordan Liub49b04b2019-05-06 14:45:15 -07006736 // Only consider subs which match the current subId
6737 // This logic can be simplified. See b/131189269 for progress.
6738 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006739 activeSubscriberIds.add(tele.getSubscriberId(subId));
6740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
6742 // First pass, find a number override for an active subscriber
6743 String mergeNumber = null;
6744 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6745 for (String key : prefs.keySet()) {
6746 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6747 final String subscriberId = (String) prefs.get(key);
6748 if (activeSubscriberIds.contains(subscriberId)) {
6749 final String iccId = key.substring(
6750 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6751 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6752 mergeNumber = (String) prefs.get(numberKey);
6753 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006754 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 + " for active subscriber " + subscriberId);
6756 }
6757 if (!TextUtils.isEmpty(mergeNumber)) {
6758 break;
6759 }
6760 }
6761 }
6762 }
6763
6764 // Shortcut when no active merged subscribers
6765 if (TextUtils.isEmpty(mergeNumber)) {
6766 return null;
6767 }
6768
6769 // Second pass, find all subscribers under that line override
6770 final ArraySet<String> result = new ArraySet<>();
6771 for (String key : prefs.keySet()) {
6772 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6773 final String number = (String) prefs.get(key);
6774 if (mergeNumber.equals(number)) {
6775 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6776 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6777 final String subscriberId = (String) prefs.get(subscriberKey);
6778 if (!TextUtils.isEmpty(subscriberId)) {
6779 result.add(subscriberId);
6780 }
6781 }
6782 }
6783 }
6784
6785 final String[] resultArray = result.toArray(new String[result.size()]);
6786 Arrays.sort(resultArray);
6787 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006788 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6790 }
6791 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006792 } finally {
6793 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006794 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006795 }
6796
6797 @Override
zoey chen38003472019-12-13 17:16:31 +08006798 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6799 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 final TelephonyManager telephonyManager = mApp.getSystemService(
6804 TelephonyManager.class);
6805 String subscriberId = telephonyManager.getSubscriberId(subId);
6806 if (subscriberId == null) {
6807 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006808 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006809 + subId);
6810 }
6811 return null;
6812 }
6813
6814 final SubscriptionInfo info = SubscriptionController.getInstance()
6815 .getSubscriptionInfo(subId);
6816 final ParcelUuid groupUuid = info.getGroupUuid();
6817 // If it doesn't belong to any group, return just subscriberId of itself.
6818 if (groupUuid == null) {
6819 return new String[]{subscriberId};
6820 }
6821
6822 // Get all subscriberIds from the group.
6823 final List<String> mergedSubscriberIds = new ArrayList<>();
6824 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006825 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006826 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006827 for (SubscriptionInfo subInfo : groupInfos) {
6828 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6829 if (subscriberId != null) {
6830 mergedSubscriberIds.add(subscriberId);
6831 }
6832 }
6833
6834 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837
6838 }
6839 }
6840
6841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006842 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006843 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
6848 final Phone phone = getPhone(subId);
6849 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006853 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006854
6855 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006856 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006857 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6858 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006859 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6860 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 final Phone phone = getPhone(subId);
6865 if (phone == null) {
6866 return false;
6867 }
6868 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6869 cdmaNonRoamingList);
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006872 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006873 }
6874
6875 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006876 @Deprecated
6877 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6878 enforceModifyPermission();
6879
6880 int returnValue = 0;
6881 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006882 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006883 if(result.exception == null) {
6884 if (result.result != null) {
6885 byte[] responseData = (byte[])(result.result);
6886 if(responseData.length > oemResp.length) {
6887 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6888 responseData.length + "bytes. Buffer Size is " +
6889 oemResp.length + "bytes.");
6890 }
6891 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6892 returnValue = responseData.length;
6893 }
6894 } else {
6895 CommandException ex = (CommandException) result.exception;
6896 returnValue = ex.getCommandError().ordinal();
6897 if(returnValue > 0) returnValue *= -1;
6898 }
6899 } catch (RuntimeException e) {
6900 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6901 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6902 if(returnValue > 0) returnValue *= -1;
6903 }
6904
6905 return returnValue;
6906 }
6907
6908 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006909 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006910 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006911 try {
6912 TelephonyPermissions
6913 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6914 mApp, phone.getSubId(), "getRadioAccessFamily");
6915 } catch (SecurityException e) {
6916 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6917 throw e;
6918 }
chen xub97461a2018-10-26 14:17:57 -07006919 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006920 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006921 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 final long identity = Binder.clearCallingIdentity();
6924 try {
chen xub97461a2018-10-26 14:17:57 -07006925 TelephonyPermissions
6926 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6927 mApp, phone.getSubId(), "getRadioAccessFamily");
6928 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
chen xub97461a2018-10-26 14:17:57 -07006932 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006933 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006934
6935 @Override
6936 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006937 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006942 ImsManager.getInstance(defaultPhone.getContext(),
6943 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 } finally {
6945 Binder.restoreCallingIdentity(identity);
6946 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006947 }
6948
6949 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006950 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006951 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6953 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006954 return false;
6955 }
Svet Ganovb320e182015-04-16 12:30:10 -07006956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 final long identity = Binder.clearCallingIdentity();
6958 try {
6959 // Check the user preference and the system-level IMS setting. Even if the user has
6960 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6961 // In the long run, we may instead need to check if there exists a connection service
6962 // which can support video calling.
6963 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006964 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 return imsManager.isVtEnabledByPlatform()
6966 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6967 && imsManager.isVtEnabledByUser();
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006971 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006972
Andrew Leea1239f22015-03-02 17:44:07 -08006973 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006974 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6975 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006977 mApp, subId, callingPackage, callingFeatureId,
6978 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 return false;
6980 }
6981
6982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 CarrierConfigManager configManager =
6985 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006986 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
6990 }
Andrew Leea1239f22015-03-02 17:44:07 -08006991 }
6992
6993 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006994 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006996 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 return false;
6998 }
6999
7000 final long identity = Binder.clearCallingIdentity();
7001 try {
7002 CarrierConfigManager configManager =
7003 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007004 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
Andrew Leea1239f22015-03-02 17:44:07 -08007009 }
7010
Andrew Lee9431b832015-03-09 18:46:45 -07007011 @Override
7012 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007013 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007014 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007015 }
7016
7017 @Override
7018 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 final long identity = Binder.clearCallingIdentity();
7020 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007021 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
Andrew Lee9431b832015-03-09 18:46:45 -07007025 }
7026
Hall Liuf6668912018-10-31 17:05:23 -07007027 /**
7028 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7029 * support for the feature and device firmware support.
7030 *
7031 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7032 */
7033 @Override
7034 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007036 final Phone phone = getPhone(subscriptionId);
7037 if (phone == null) {
7038 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7039 return false;
7040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007042 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7044 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007045 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 return isCarrierSupported && isDeviceSupported;
7047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
Hall Liu98187582018-01-22 19:15:32 -08007050 }
7051
Hall Liuf6668912018-10-31 17:05:23 -07007052 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007053 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7054 * RTT setting, will return true if the device and carrier both support RTT.
7055 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007056 */
7057 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 final long identity = Binder.clearCallingIdentity();
7059 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007060 boolean isRttSupported = isRttSupported(subscriptionId);
7061 boolean isUserRttSettingOn = Settings.Secure.getInt(
7062 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7063 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7064 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7065 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007069 }
7070
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007071 @Deprecated
7072 @Override
7073 public String getDeviceId(String callingPackage) {
7074 return getDeviceIdWithFeature(callingPackage, null);
7075 }
7076
Sanket Padawe7310cc72015-01-14 09:53:20 -08007077 /**
7078 * Returns the unique device ID of phone, for example, the IMEI for
7079 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7080 *
7081 * <p>Requires Permission:
7082 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7083 */
7084 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007085 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007086 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007087 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007088 return null;
7089 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007090 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007091 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007093 return null;
7094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 return phone.getDeviceId();
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
7101 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007102 }
7103
Ping Sunc67b7c22016-03-02 19:16:45 +08007104 /**
7105 * {@hide}
7106 * Returns the IMS Registration Status on a particular subid
7107 *
7108 * @param subId
7109 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007110 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007111 Phone phone = getPhone(subId);
7112 if (phone != null) {
7113 return phone.isImsRegistered();
7114 } else {
7115 return false;
7116 }
7117 }
7118
Santos Cordon7a1885b2015-02-03 11:15:19 -08007119 @Override
7120 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007127 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007128
Tyler Gunnf70ed162019-04-03 15:28:53 -07007129 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007130 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007131 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007133 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007134 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7135 }
7136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
7142 }
7143
7144 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007145 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007146 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7147 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007148 final long identity = Binder.clearCallingIdentity();
7149 try {
7150 Phone phone = getPhone(subscriptionId);
7151 if (phone == null) {
7152 return null;
7153 }
7154 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
7158 }
7159
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007160 /**
7161 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007162 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007163 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 Phone phone = getPhone(subId);
7167 if (phone != null) {
7168 return phone.isWifiCallingEnabled();
7169 } else {
7170 return false;
7171 }
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007174 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007175 }
7176
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007177 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007178 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007179 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007180 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 Phone phone = getPhone(subId);
7184 if (phone != null) {
7185 return phone.isVideoEnabled();
7186 } else {
7187 return false;
7188 }
7189 } finally {
7190 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007191 }
7192 }
7193
7194 /**
7195 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7196 * defined in {@link ImsRegistrationImplBase}.
7197 */
7198 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 Phone phone = getPhone(subId);
7202 if (phone != null) {
7203 return phone.getImsRegistrationTech();
7204 } else {
7205 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7206 }
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007209 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007210 }
7211
Stuart Scott8eef64f2015-04-08 15:13:54 -07007212 @Override
7213 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007214 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007215 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7216 return;
7217 }
7218
Svet Ganovcc087f82015-05-12 20:35:54 -07007219 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007220
Svet Ganovcc087f82015-05-12 20:35:54 -07007221 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007222 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7223 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007224 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007225 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007226 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007227 setAllowedNetworkTypesForReason(subId,
7228 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7229 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7230 setAllowedNetworkTypesForReason(subId,
7231 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7232 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7233 setAllowedNetworkTypesForReason(subId,
7234 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7235 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Yomna Nassera39e5222021-02-17 03:38:52 +00007236 setAllowedNetworkTypesForReason(subId,
7237 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G,
7238 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007239 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7240 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007241 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007242 // There has been issues when Sms raw table somehow stores orphan
7243 // fragments. They lead to garbled message when new fragments come
7244 // in and combined with those stale ones. In case this happens again,
7245 // user can reset all network settings which will clean up this table.
7246 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007247 // Clean up IMS settings as well here.
7248 int slotId = getSlotIndex(subId);
7249 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7250 ImsManager.getInstance(mApp, slotId).factoryReset();
7251 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007252
7253 // Erase modem config if erase modem on network setting is enabled.
7254 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7255 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7256 if (configValue != null && Boolean.parseBoolean(configValue)) {
7257 sendEraseModemConfig(getDefaultPhone());
7258 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007259 } finally {
7260 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007261 }
7262 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007263
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007264 private void cleanUpSmsRawTable(Context context) {
7265 ContentResolver resolver = context.getContentResolver();
7266 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7267 resolver.delete(uri, null, null);
7268 }
7269
Narayan Kamath1c496c22015-04-16 14:40:19 +01007270 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007271 public String getSimLocaleForSubscriber(int subId) {
7272 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7273 final Phone phone = getPhone(subId);
7274 if (phone == null) {
7275 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007276 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
chen xu5d3637b2019-01-21 23:31:38 -08007280 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007281 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007282 if (info == null) {
7283 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7284 return null;
7285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 // Try and fetch the locale from the carrier properties or from the SIM language
7287 // preferences (EF-PL and EF-LI)...
7288 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007290 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7291 if (localeFromDefaultSim != null) {
7292 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7293 if (DBG) log("Using locale from subId: " + subId + " locale: "
7294 + localeFromDefaultSim);
7295 return localeFromDefaultSim.toLanguageTag();
7296 } else {
7297 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 }
7299 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007301 // The SIM language preferences only store a language (e.g. fr = French), not an
7302 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7303 // the SIM and carrier preferences does not include a country we add the country
7304 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007305 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007307 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 return mccLocale.toLanguageTag();
7309 }
7310
7311 if (DBG) log("No locale found - returning null");
7312 return null;
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007316 }
7317
7318 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007319 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007320 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007321 }
7322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 /**
7324 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7325 */
7326 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007327 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007328 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007329 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007330
Chenjie Yu1ba97252018-01-11 18:16:20 -08007331 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007332 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007333
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007334 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007335 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7336 * representing the state of the modem.
7337 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007338 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7339 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007340 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007341 */
7342 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007343 public void requestModemActivityInfo(ResultReceiver result) {
7344 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007345 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
sqian1a1be542020-03-05 11:37:28 -08007349 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 } finally {
7351 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007352 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007353 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007354
Siddharth Rayb8114062018-06-17 15:02:38 -07007355 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7356 // less than total activity duration.
7357 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7358 if (info == null) {
7359 return false;
7360 }
7361 int activityDurationMs =
7362 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7363 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007364 int[] txTimeMs = info.getTransmitTimeMillis();
7365 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7366 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007367 }
7368 return (info.isValid()
7369 && (info.getSleepTimeMillis() <= activityDurationMs)
7370 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007371 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007372 && (totalTxTimeMs <= activityDurationMs));
7373 }
7374
Jack Yu85bd38a2015-11-09 11:34:32 -08007375 /**
7376 * {@hide}
7377 * Returns the service state information on specified subscription.
7378 */
7379 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007380 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7381 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007383 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007384 return null;
7385 }
7386
Hall Liuf19c44f2018-11-27 14:38:17 -08007387 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7388 LocationAccessPolicy.checkLocationPermission(mApp,
7389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7390 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007392 .setCallingPid(Binder.getCallingPid())
7393 .setCallingUid(Binder.getCallingUid())
7394 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007395 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7397 .build());
7398
7399 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7400 LocationAccessPolicy.checkLocationPermission(mApp,
7401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7402 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007403 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007404 .setCallingPid(Binder.getCallingPid())
7405 .setCallingUid(Binder.getCallingUid())
7406 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007407 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007408 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7409 .build());
7410 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7411 boolean hasFinePermission =
7412 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7413 boolean hasCoarsePermission =
7414 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 final long identity = Binder.clearCallingIdentity();
7417 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007418 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7419 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7420 Rlog.d(LOG_TAG,
7421 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7422 return null;
7423 }
7424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 final Phone phone = getPhone(subId);
7426 if (phone == null) {
7427 return null;
7428 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007429
Hall Liuf19c44f2018-11-27 14:38:17 -08007430 ServiceState ss = phone.getServiceState();
7431
7432 // Scrub out the location info in ServiceState depending on what level of access
7433 // the caller has.
7434 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007435 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7436 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007440 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007441
7442 /**
7443 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7444 *
7445 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7446 * voicemail ringtone.
7447 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7448 * PhoneAccount.
7449 */
7450 @Override
7451 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 final long identity = Binder.clearCallingIdentity();
7453 try {
7454 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7455 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007456 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007463 }
7464
7465 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007466 * Sets the per-account voicemail ringtone.
7467 *
7468 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7469 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7470 *
7471 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7472 * voicemail ringtone.
7473 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7474 * PhoneAccount.
7475 */
7476 @Override
7477 public void setVoicemailRingtoneUri(String callingPackage,
7478 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007480 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007481 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7482 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7484 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7485 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7491 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007492 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 }
7494 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007497 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007498 }
7499
7500 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007501 * Returns whether vibration is set for voicemail notification in Phone settings.
7502 *
7503 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7504 * voicemail vibration setting.
7505 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7506 */
7507 @Override
7508 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 final long identity = Binder.clearCallingIdentity();
7510 try {
7511 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7512 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007513 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007520 }
7521
Youhan Wange64578a2016-05-02 15:32:42 -07007522 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007523 * Sets the per-account voicemail vibration.
7524 *
7525 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7526 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7527 *
7528 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7529 * voicemail vibration setting.
7530 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7531 * specific PhoneAccount.
7532 */
7533 @Override
7534 public void setVoicemailVibrationEnabled(String callingPackage,
7535 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007536 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007537 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007538 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7539 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7541 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7542 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007543 }
7544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7548 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 }
7551 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007554 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007555 }
7556
7557 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007558 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7559 *
7560 * @throws SecurityException if the caller does not have the required permission
7561 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007562 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007563 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007564 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007565 }
7566
7567 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007568 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7569 * permission.
7570 *
7571 * @throws SecurityException if the caller does not have the required permission
7572 */
7573 private void enforceSendSmsPermission() {
7574 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7575 }
7576
7577 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007578 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007579 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007580 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007581 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007582 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 final long identity = Binder.clearCallingIdentity();
7584 try {
7585 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 if (componentName == null) {
7588 throw new SecurityException(
7589 "Caller not current active visual voicemail package[null]");
7590 }
7591 String vvmPackage = componentName.getPackageName();
7592 if (!callingPackage.equals(vvmPackage)) {
7593 throw new SecurityException("Caller not current active visual voicemail package["
7594 + vvmPackage + "]");
7595 }
7596 } finally {
7597 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007598 }
7599 }
7600
7601 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007602 * Return the application ID for the app type.
7603 *
7604 * @param subId the subscription ID that this request applies to.
7605 * @param appType the uicc app type.
7606 * @return Application ID for specificied app type, or null if no uicc.
7607 */
7608 @Override
7609 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007610 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007611 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612
7613 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007614 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 if (phone == null) {
7616 return null;
7617 }
7618 String aid = null;
7619 try {
7620 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7621 .getApplicationByType(appType).getAid();
7622 } catch (Exception e) {
7623 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7624 }
7625 return aid;
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007628 }
Youhan Wange64578a2016-05-02 15:32:42 -07007629 }
7630
Youhan Wang4001d252016-05-11 10:29:41 -07007631 /**
7632 * Return the Electronic Serial Number.
7633 *
7634 * @param subId the subscription ID that this request applies to.
7635 * @return ESN or null if error.
7636 */
7637 @Override
7638 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007639 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007640 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641
7642 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007643 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 if (phone == null) {
7645 return null;
7646 }
7647 String esn = null;
7648 try {
7649 esn = phone.getEsn();
7650 } catch (Exception e) {
7651 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7652 }
7653 return esn;
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007656 }
Youhan Wang4001d252016-05-11 10:29:41 -07007657 }
7658
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007659 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007660 * Return the Preferred Roaming List Version.
7661 *
7662 * @param subId the subscription ID that this request applies to.
7663 * @return PRLVersion or null if error.
7664 */
7665 @Override
7666 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007667 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007668 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669
7670 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007671 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 if (phone == null) {
7673 return null;
7674 }
7675 String cdmaPrlVersion = null;
7676 try {
7677 cdmaPrlVersion = phone.getCdmaPrlVersion();
7678 } catch (Exception e) {
7679 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7680 }
7681 return cdmaPrlVersion;
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007684 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007685 }
7686
7687 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007688 * Get snapshot of Telephony histograms
7689 * @return List of Telephony histograms
7690 * @hide
7691 */
7692 @Override
7693 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7695 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696
7697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 return RIL.getTelephonyRILTimingHistograms();
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007703 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007704
7705 /**
7706 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007707 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7708 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007709 * Require system privileges. In the future we may add this to carrier APIs.
7710 *
Michele Berionne482f8202018-11-27 18:57:59 -08007711 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007712 */
7713 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007714 @TelephonyManager.SetCarrierRestrictionResult
7715 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007716 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007717 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007718
Michele Berionne482f8202018-11-27 18:57:59 -08007719 if (carrierRestrictionRules == null) {
7720 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007721 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 final long identity = Binder.clearCallingIdentity();
7724 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007725 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007726 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007730 }
7731
7732 /**
7733 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007734 * Get the allowed carrier list and the excluded carrier list, including the priority between
7735 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007736 * Require system privileges. In the future we may add this to carrier APIs.
7737 *
Michele Berionne482f8202018-11-27 18:57:59 -08007738 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007739 */
7740 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007741 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007742 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744
7745 final long identity = Binder.clearCallingIdentity();
7746 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007747 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7748 if (response instanceof CarrierRestrictionRules) {
7749 return (CarrierRestrictionRules) response;
7750 }
7751 // Response is an Exception of some kind,
7752 // which is signalled to the user as a NULL retval
7753 return null;
7754 } catch (Exception e) {
7755 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7756 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 } finally {
7758 Binder.restoreCallingIdentity(identity);
7759 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007760 }
7761
fionaxu59545b42016-05-25 15:53:37 -07007762 /**
fionaxu59545b42016-05-25 15:53:37 -07007763 * Action set from carrier signalling broadcast receivers to enable/disable radio
7764 * @param subId the subscription ID that this action applies to.
7765 * @param enabled control enable or disable radio.
7766 * {@hide}
7767 */
7768 @Override
7769 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7770 enforceModifyPermission();
7771 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772
7773 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007774 if (phone == null) {
7775 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7776 return;
7777 }
7778 try {
7779 phone.carrierActionSetRadioEnabled(enabled);
7780 } catch (Exception e) {
7781 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 } finally {
7783 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007784 }
7785 }
7786
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007787 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007788 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7789 * network status based on which carrier apps could apply actions accordingly,
7790 * enable/disable default url handler for example.
7791 *
7792 * @param subId the subscription ID that this action applies to.
7793 * @param report control start/stop reporting the default network status.
7794 * {@hide}
7795 */
7796 @Override
7797 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7798 enforceModifyPermission();
7799 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800
7801 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007802 if (phone == null) {
7803 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7804 return;
7805 }
7806 try {
7807 phone.carrierActionReportDefaultNetworkStatus(report);
7808 } catch (Exception e) {
7809 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 } finally {
7811 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007812 }
7813 }
7814
7815 /**
fionaxud9622282017-07-17 17:51:30 -07007816 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7817 * @param subId the subscription ID that this action applies to.
7818 * {@hide}
7819 */
7820 @Override
7821 public void carrierActionResetAll(int subId) {
7822 enforceModifyPermission();
7823 final Phone phone = getPhone(subId);
7824 if (phone == null) {
7825 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7826 return;
7827 }
7828 try {
7829 phone.carrierActionResetAll();
7830 } catch (Exception e) {
7831 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7832 }
7833 }
7834
7835 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007836 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7837 * bug report is being generated.
7838 */
7839 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007840 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007841 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7842 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007843 writer.println("Permission Denial: can't dump Phone from pid="
7844 + Binder.getCallingPid()
7845 + ", uid=" + Binder.getCallingUid()
7846 + "without permission "
7847 + android.Manifest.permission.DUMP);
7848 return;
7849 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007850 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007851 }
Jack Yueb89b242016-06-22 13:27:47 -07007852
Brad Ebingerdac2f002018-04-03 15:17:52 -07007853 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007854 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7855 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7856 @NonNull String[] args) {
7857 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7858 this, in.getFileDescriptor(), out.getFileDescriptor(),
7859 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007860 }
7861
Jack Yueb89b242016-06-22 13:27:47 -07007862 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007863 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007864 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007865 * @param reason the reason the data enable change is taking place
7866 * @param enabled True if enabling the data, otherwise disabling.
7867 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007868 */
7869 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007870 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007871 boolean enabled) {
7872 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7873 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7874 try {
7875 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007876 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007877 } catch (SecurityException se) {
7878 enforceModifyPermission();
7879 }
7880 } else {
7881 enforceModifyPermission();
7882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007883
7884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 Phone phone = getPhone(subId);
7887 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007888 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7889 phone.carrierActionSetMeteredApnsEnabled(enabled);
7890 } else {
7891 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893 }
7894 } finally {
7895 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007896 }
7897 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007898
7899 /**
7900 * Get Client request stats
7901 * @return List of Client Request Stats
7902 * @hide
7903 */
7904 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007905 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7906 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007908 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007909 return null;
7910 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007911 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 if (phone != null) {
7916 return phone.getClientRequestStats();
7917 }
7918
7919 return null;
7920 } finally {
7921 Binder.restoreCallingIdentity(identity);
7922 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007923 }
7924
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007925 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007926 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007927 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007928 }
Jack Yueb4124c2017-02-16 15:32:43 -08007929
7930 /**
Grace Chen70990072017-03-24 17:21:30 -07007931 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007932 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007933 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007934 * @param state State of SIM (power down, power up, pass through)
7935 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7936 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7937 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007938 *
7939 **/
7940 @Override
Grace Chen70990072017-03-24 17:21:30 -07007941 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007942 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007943 Phone phone = PhoneFactory.getPhone(slotIndex);
7944
vagdeviaf9a5b92018-08-15 16:01:53 -07007945 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947 final long identity = Binder.clearCallingIdentity();
7948 try {
7949 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007950 phone.setSimPowerState(state, null, workSource);
7951 }
7952 } finally {
7953 Binder.restoreCallingIdentity(identity);
7954 }
7955 }
7956
7957 /**
7958 * Set SIM card power state.
7959 *
7960 * @param slotIndex SIM slot id.
7961 * @param state State of SIM (power down, power up, pass through)
7962 * @param callback callback to trigger after success or failure
7963 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7964 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7965 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7966 *
7967 **/
7968 @Override
7969 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7970 IIntegerConsumer callback) {
7971 enforceModifyPermission();
7972 Phone phone = PhoneFactory.getPhone(slotIndex);
7973
7974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7975
7976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 if (phone != null) {
7979 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7980 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 }
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007984 }
7985 }
Shuo Qiandd210312017-04-12 22:11:33 +00007986
Tyler Gunn65d45c22017-06-05 11:22:26 -07007987 private boolean isUssdApiAllowed(int subId) {
7988 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007989 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007990 if (configManager == null) {
7991 return false;
7992 }
7993 PersistableBundle pb = configManager.getConfigForSubId(subId);
7994 if (pb == null) {
7995 return false;
7996 }
7997 return pb.getBoolean(
7998 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7999 }
8000
Shuo Qiandd210312017-04-12 22:11:33 +00008001 /**
8002 * Check if phone is in emergency callback mode
8003 * @return true if phone is in emergency callback mode
8004 * @param subId sub id
8005 */
goneil9c5f4872017-12-05 14:07:56 -08008006 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008007 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008008 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008009 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010
8011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 if (phone != null) {
8014 return phone.isInEcm();
8015 } else {
8016 return false;
8017 }
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008020 }
8021 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008022
8023 /**
8024 * Get the current signal strength information for the given subscription.
8025 * Because this information is not updated when the device is in a low power state
8026 * it should not be relied-upon to be current.
8027 * @param subId Subscription index
8028 * @return the most recent cached signal strength info from the modem
8029 */
8030 @Override
8031 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 Phone p = getPhone(subId);
8035 if (p == null) {
8036 return null;
8037 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 return p.getSignalStrength();
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
8042 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008043 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008044
Pengquan Meng77b7f132018-08-22 14:49:57 -07008045 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008046 * Get the current modem radio state for the given slot.
8047 * @param slotIndex slot index.
8048 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008049 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008050 * @return the current radio power state from the modem
8051 */
8052 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008053 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008054 Phone phone = PhoneFactory.getPhone(slotIndex);
8055 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8057 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008058 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8059 }
8060
8061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 return phone.getRadioPowerState();
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
8067 }
8068 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8069 }
8070
8071 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008072 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8073 *
8074 * <p>Requires one of the following permissions:
8075 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8076 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8077 * privileges.
8078 *
8079 * @param subId subscription id
8080 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8081 * {@code false}.
8082 */
8083 @Override
8084 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008085 try {
8086 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8087 null);
8088 } catch (Exception e) {
8089 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8090 mApp, subId, "isDataRoamingEnabled");
8091 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008092
Pengquan Menga1bb6272018-09-06 09:59:22 -07008093 boolean isEnabled = false;
8094 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008095 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008096 Phone phone = getPhone(subId);
8097 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008098 } finally {
8099 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008100 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008101 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008102 }
8103
8104
8105 /**
8106 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8107 *
8108 * <p> Requires permission:
8109 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8110 * privileges.
8111 *
8112 * @param subId subscription id
8113 * @param isEnabled {@code true} means enable, {@code false} means disable.
8114 */
8115 @Override
8116 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8118 mApp, subId, "setDataRoamingEnabled");
8119
Pengquan Menga1bb6272018-09-06 09:59:22 -07008120 final long identity = Binder.clearCallingIdentity();
8121 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008122 Phone phone = getPhone(subId);
8123 if (phone != null) {
8124 phone.setDataRoamingEnabled(isEnabled);
8125 }
8126 } finally {
8127 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008128 }
8129 }
8130
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008131 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008132 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008133 TelephonyPermissions
8134 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008135 mApp, subId, "isManualNetworkSelectionAllowed");
8136
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008137 boolean isAllowed = true;
8138 final long identity = Binder.clearCallingIdentity();
8139 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008140 Phone phone = getPhone(subId);
8141 if (phone != null) {
8142 isAllowed = phone.isCspPlmnEnabled();
8143 }
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
8147 return isAllowed;
8148 }
8149
8150 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008151 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008152 // Verify that tha callingPackage belongs to the calling UID
8153 mApp.getSystemService(AppOpsManager.class)
8154 .checkPackage(Binder.getCallingUid(), callingPackage);
8155
Jordan Liu1e142fc2019-04-22 15:10:43 -07008156 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008157 try {
8158 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008159 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008160 } catch (SecurityException e) {
8161 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8162 // has carrier privileges on an active UICC
8163 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8164 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008165 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008166 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008167 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008168
8169 final long identity = Binder.clearCallingIdentity();
8170 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008171 UiccController uiccController = UiccController.getInstance();
8172 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008173 if (hasReadPermission) {
8174 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008175 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008176
8177 // Remove private info if the caller doesn't have access
8178 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8179 for (UiccCardInfo cardInfo : cardInfos) {
8180 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8181 // is available
8182 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8183 if (card == null || card.getUiccProfile() == null) {
8184 // assume no access if the card or profile is unavailable
8185 filteredInfos.add(cardInfo.getUnprivileged());
8186 continue;
8187 }
8188 UiccProfile profile = card.getUiccProfile();
8189 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8190 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8191 filteredInfos.add(cardInfo);
8192 } else {
8193 filteredInfos.add(cardInfo.getUnprivileged());
8194 }
8195 }
8196 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
8201
8202 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008203 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008204 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206 final long identity = Binder.clearCallingIdentity();
8207 try {
8208 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8209 if (slots == null) {
8210 Rlog.i(LOG_TAG, "slots is null.");
8211 return null;
8212 }
8213
8214 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8215 for (int i = 0; i < slots.length; i++) {
8216 UiccSlot slot = slots[i];
8217 if (slot == null) {
8218 continue;
8219 }
8220
Jordan Liu7be7e652019-05-06 18:55:02 +00008221 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 UiccCard card = slot.getUiccCard();
8223 if (card != null) {
8224 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008225 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008226 cardId = slot.getEid();
8227 if (TextUtils.isEmpty(cardId)) {
8228 cardId = slot.getIccId();
8229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 }
8231
Jordan Liu857451f2019-05-09 16:35:35 -07008232 if (cardId != null) {
8233 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8234 // if cardId is an EID, it's all digits so this is fine
8235 cardId = IccUtils.stripTrailingFs(cardId);
8236 }
8237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 int cardState = 0;
8239 switch (slot.getCardState()) {
8240 case CARDSTATE_ABSENT:
8241 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8242 break;
8243 case CARDSTATE_PRESENT:
8244 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8245 break;
8246 case CARDSTATE_ERROR:
8247 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8248 break;
8249 case CARDSTATE_RESTRICTED:
8250 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8251 break;
8252 default:
8253 break;
8254
8255 }
8256
8257 infos[i] = new UiccSlotInfo(
8258 slot.isActive(),
8259 slot.isEuicc(),
8260 cardId,
8261 cardState,
8262 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008263 slot.isExtendedApduSupported(),
8264 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 }
8266 return infos;
8267 } finally {
8268 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008269 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008270 }
8271
8272 @Override
8273 public boolean switchSlots(int[] physicalSlots) {
8274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008282 }
Jack Yu4c988042018-02-27 15:30:01 -08008283
8284 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008285 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008286 final long identity = Binder.clearCallingIdentity();
8287 try {
8288 return UiccController.getInstance().getCardIdForDefaultEuicc();
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
8293
Pengquan Meng85728fb2018-03-12 16:31:21 -07008294 /**
goneil47ffb6e2018-04-06 15:40:58 -07008295 * A test API to reload the UICC profile.
8296 *
8297 * <p>Requires that the calling app has permission
8298 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8299 * @hide
8300 */
8301 @Override
8302 public void refreshUiccProfile(int subId) {
8303 enforceModifyPermission();
8304
8305 final long identity = Binder.clearCallingIdentity();
8306 try {
8307 Phone phone = getPhone(subId);
8308 if (phone == null) {
8309 return;
8310 }
8311 UiccCard uiccCard = phone.getUiccCard();
8312 if (uiccCard == null) {
8313 return;
8314 }
8315 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8316 if (uiccProfile == null) {
8317 return;
8318 }
8319 uiccProfile.refresh();
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
8324
8325 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008326 * Returns false if the mobile data is disabled by default, otherwise return true.
8327 */
8328 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008329 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008330 }
8331
8332 /**
8333 * Returns true if the data roaming is enabled by default, i.e the system property
8334 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8335 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8336 */
8337 private boolean getDefaultDataRoamingEnabled(int subId) {
8338 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008339 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008340 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008341 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8342 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8343 return isDataRoamingEnabled;
8344 }
8345
8346 /**
8347 * Returns the default network type for the given {@code subId}, if the default network type is
8348 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8349 */
8350 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008351 List<Integer> list = TelephonyProperties.default_network();
8352 int phoneId = mSubscriptionController.getPhoneId(subId);
8353 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8354 return list.get(phoneId);
8355 }
8356 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008357 }
fionaxua13278b2018-03-21 00:08:13 -07008358
8359 @Override
8360 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008361 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 final Phone phone = getPhone(subId);
8367 if (phone == null) {
8368 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8369 return;
8370 }
chen xueaba88a2019-03-15 13:15:10 -07008371 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8372 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008373 if (carrierPrivilegeRules == null) {
8374 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8375 } else {
8376 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 } finally {
8379 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008380 }
fionaxua13278b2018-03-21 00:08:13 -07008381 }
8382
8383 @Override
8384 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008385 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 final Phone phone = getPhone(subId);
8390 if (phone == null) {
8391 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8392 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8393 }
8394 return phone.getCarrierIdListVersion();
8395 } finally {
8396 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008397 }
fionaxua13278b2018-03-21 00:08:13 -07008398 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008399
8400 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008401 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8402 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008404 mApp, subId, callingPackage, callingFeatureId,
8405 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008406 return -1;
8407 }
8408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008416
8417 @Override
8418 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008419 TelephonyPermissions
8420 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008421 mApp, subId, "getCdmaRoamingMode");
8422
8423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
8429 }
8430
8431 @Override
8432 public boolean setCdmaRoamingMode(int subId, int mode) {
8433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8434 mApp, subId, "setCdmaRoamingMode");
8435
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
8443
8444 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008445 public int getCdmaSubscriptionMode(int subId) {
8446 TelephonyPermissions
8447 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8448 mApp, subId, "getCdmaSubscriptionMode");
8449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 }
8457
8458 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008459 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8461 mApp, subId, "setCdmaSubscriptionMode");
8462
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008470
sqianc5eccab2018-10-19 18:46:41 -07008471 @Override
sqian8c685422019-02-22 15:55:18 -08008472 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008473 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008475 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8476 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008477 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8478 }
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
sqian854d44b2018-12-12 16:48:18 -08008481 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8482 for (Phone phone: PhoneFactory.getPhones()) {
8483 if (phone.getEmergencyNumberTracker() != null
8484 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8485 emergencyNumberListInternal.put(
8486 phone.getSubId(),
8487 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8488 }
sqian11b7a0e2018-12-05 18:48:28 -08008489 }
sqian854d44b2018-12-12 16:48:18 -08008490 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
sqianc5eccab2018-10-19 18:46:41 -07008494 }
8495
8496 @Override
sqian8c685422019-02-22 15:55:18 -08008497 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008498 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008499 if (!exactMatch) {
8500 TelephonyPermissions
8501 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008502 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008503 }
8504 final long identity = Binder.clearCallingIdentity();
8505 try {
sqian854d44b2018-12-12 16:48:18 -08008506 for (Phone phone: PhoneFactory.getPhones()) {
8507 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008508 && phone.getEmergencyNumberTracker()
8509 .isEmergencyNumber(number, exactMatch)) {
8510 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008511 }
sqian11b7a0e2018-12-05 18:48:28 -08008512 }
8513 return false;
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
8518
sqianf4ca7ed2019-01-15 18:32:07 -08008519 /**
8520 * Update emergency number list for test mode.
8521 */
8522 @Override
8523 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8524 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8525 "updateEmergencyNumberListTestMode");
8526
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 for (Phone phone: PhoneFactory.getPhones()) {
8530 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8531 if (tracker != null) {
8532 tracker.executeEmergencyNumberTestModeCommand(action, num);
8533 }
8534 }
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 }
8539
8540 /**
8541 * Get the full emergency number list for test mode.
8542 */
8543 @Override
8544 public List<String> getEmergencyNumberListTestMode() {
8545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8546 "getEmergencyNumberListTestMode");
8547
8548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 Set<String> emergencyNumbers = new HashSet<>();
8551 for (Phone phone: PhoneFactory.getPhones()) {
8552 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8553 if (tracker != null) {
8554 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8555 emergencyNumbers.add(num.getNumber());
8556 }
8557 }
8558 }
8559 return new ArrayList<>(emergencyNumbers);
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
8562 }
8563 }
8564
chen xud6b45bd2018-10-30 22:27:10 -07008565 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008566 public int getEmergencyNumberDbVersion(int subId) {
8567 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8568
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 final Phone phone = getPhone(subId);
8572 if (phone == null) {
8573 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8574 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8575 }
8576 return phone.getEmergencyNumberDbVersion();
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
8580 }
8581
8582 @Override
8583 public void notifyOtaEmergencyNumberDbInstalled() {
8584 enforceModifyPermission();
8585
8586 final long identity = Binder.clearCallingIdentity();
8587 try {
8588 for (Phone phone: PhoneFactory.getPhones()) {
8589 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8590 if (tracker != null) {
8591 tracker.updateOtaEmergencyNumberDatabase();
8592 }
8593 }
8594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
8597 }
8598
8599 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008600 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008601 enforceActiveEmergencySessionPermission();
8602
8603 final long identity = Binder.clearCallingIdentity();
8604 try {
8605 for (Phone phone: PhoneFactory.getPhones()) {
8606 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8607 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008608 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8609 }
8610 }
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
8615
8616 @Override
8617 public void resetOtaEmergencyNumberDbFilePath() {
8618 enforceActiveEmergencySessionPermission();
8619
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 for (Phone phone: PhoneFactory.getPhones()) {
8623 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8624 if (tracker != null) {
8625 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008626 }
8627 }
8628 } finally {
8629 Binder.restoreCallingIdentity(identity);
8630 }
8631 }
8632
8633 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008634 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8635 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8636 Phone phone = getPhone(subId);
8637 if (phone == null) {
8638 return null;
8639 }
8640 final long identity = Binder.clearCallingIdentity();
8641 try {
8642 UiccProfile profile = UiccController.getInstance()
8643 .getUiccProfileForPhone(phone.getPhoneId());
8644 if (profile != null) {
8645 return profile.getCertsFromCarrierPrivilegeAccessRules();
8646 }
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
8650 return null;
8651 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008652
8653 /**
8654 * Enable or disable a modem stack.
8655 */
8656 @Override
8657 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8658 enforceModifyPermission();
8659
8660 final long identity = Binder.clearCallingIdentity();
8661 try {
8662 Phone phone = PhoneFactory.getPhone(slotIndex);
8663 if (phone == null) {
8664 return false;
8665 } else {
8666 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8667 }
8668 } finally {
8669 Binder.restoreCallingIdentity(identity);
8670 }
8671 }
Michelecea4cf22018-12-21 15:00:11 -08008672
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008673 /**
8674 * Whether a modem stack is enabled or not.
8675 */
8676 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008677 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8678 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008679 Phone phone = PhoneFactory.getPhone(slotIndex);
8680 if (phone == null) return false;
8681
8682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008683 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8684 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008685 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8686 }
8687
8688 final long identity = Binder.clearCallingIdentity();
8689 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008690 try {
8691 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8692 } catch (NoSuchElementException ex) {
8693 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8694 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
8698 }
8699
Michelecea4cf22018-12-21 15:00:11 -08008700 @Override
Michele0ea7d782019-03-19 14:58:42 -07008701 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008702 enforceModifyPermission();
8703
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008707 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008708 .commit();
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 }
8713
8714 @Override
Michele0ea7d782019-03-19 14:58:42 -07008715 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008716 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008718 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8719 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008720 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008721 }
Michelecea4cf22018-12-21 15:00:11 -08008722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
Michele0ea7d782019-03-19 14:58:42 -07008725 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008726 } finally {
8727 Binder.restoreCallingIdentity(identity);
8728 }
8729 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008730
Michele0ea7d782019-03-19 14:58:42 -07008731 @TelephonyManager.IsMultiSimSupportedResult
8732 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008733 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8734 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8735 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008736 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8737 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008738 }
8739 // Check if the hardware supports multisim functionality. If usage of multisim is not
8740 // supported by the modem, indicate that it is restricted.
8741 PhoneCapability staticCapability =
8742 mPhoneConfigurationManager.getStaticPhoneCapability();
8743 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008744 loge("isMultiSimSupportedInternal: no static configuration available");
8745 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008746 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008747 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008748 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8749 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008750 }
8751 // Check if support of multiple SIMs is restricted by carrier
8752 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008753 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008754 }
8755
Michele0ea7d782019-03-19 14:58:42 -07008756 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008757 }
8758
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008759 /**
8760 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008761 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8762 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8763 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008764 * @param numOfSims number of active sims we want to switch to
8765 */
8766 @Override
8767 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008768 if (numOfSims == 1) {
8769 enforceModifyPermission();
8770 } else {
8771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8772 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8773 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008774 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008775
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008776 try {
Michele30b57b22019-03-01 12:01:14 -08008777 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008778 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008779 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8780 return;
8781 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008782 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008788 @Override
8789 public boolean isApplicationOnUicc(int subId, int appType) {
8790 enforceReadPrivilegedPermission("isApplicationOnUicc");
8791 Phone phone = getPhone(subId);
8792 if (phone == null) {
8793 return false;
8794 }
8795 final long identity = Binder.clearCallingIdentity();
8796 try {
8797 UiccCard uiccCard = phone.getUiccCard();
8798 if (uiccCard == null) {
8799 return false;
8800 }
8801 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8802 if (uiccProfile == null) {
8803 return false;
8804 }
8805 if (TelephonyManager.APPTYPE_SIM <= appType
8806 && appType <= TelephonyManager.APPTYPE_ISIM) {
8807 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8808 }
8809 return false;
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
8814
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008815 /**
chen xub4baa772019-04-03 10:23:41 -07008816 * Get whether making changes to modem configurations will trigger reboot.
8817 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008818 */
8819 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008820 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8821 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008823 mApp, subId, callingPackage, callingFeatureId,
8824 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008825 return false;
8826 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008827 final long identity = Binder.clearCallingIdentity();
8828 try {
8829 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8830 } finally {
8831 Binder.restoreCallingIdentity(identity);
8832 }
8833 }
8834
Nathan Harold29f5f052019-02-15 13:41:57 -08008835 private void updateModemStateMetrics() {
8836 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8837 // TODO: check the state for each modem if the api is ready.
8838 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8839 }
8840
Pengquan Meng3889a572019-01-23 11:16:29 -08008841 @Override
8842 public int[] getSlotsMapping() {
8843 enforceReadPrivilegedPermission("getSlotsMapping");
8844
8845 final long identity = Binder.clearCallingIdentity();
8846 try {
8847 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8848 // All logical slots should have a mapping to a physical slot.
8849 int[] logicalSlotsMapping = new int[phoneCount];
8850 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8851 for (int i = 0; i < slotInfos.length; i++) {
8852 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8853 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8854 }
8855 }
8856 return logicalSlotsMapping;
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008861
8862 /**
8863 * Get the IRadio HAL Version
8864 */
8865 @Override
8866 public int getRadioHalVersion() {
8867 Phone phone = getDefaultPhone();
8868 if (phone == null) return -1;
8869 HalVersion hv = phone.getHalVersion();
8870 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8871 return hv.major * 100 + hv.minor;
8872 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008873
8874 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008875 * Get the current calling package name.
8876 * @return the current calling package name
8877 */
8878 @Override
8879 public String getCurrentPackageName() {
8880 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8881 }
8882
8883 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008884 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8885 * corresponding network requests on a subId.
8886 *
8887 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008888 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008889 * 2) APN is un-metered for this subscription, or
8890 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008891 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008892 *
8893 * @return whether data is allowed for a apn type.
8894 *
8895 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008896 */
8897 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008898 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008899 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8900 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008901
8902 // Now that all security checks passes, perform the operation as ourselves.
8903 final long identity = Binder.clearCallingIdentity();
8904 try {
8905 Phone phone = getPhone(subId);
8906 if (phone == null) return false;
8907
Jack Yu41407ee2019-05-13 16:54:09 -07008908 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008909 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8910 } finally {
8911 Binder.restoreCallingIdentity(identity);
8912 }
8913 }
8914
8915 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008916 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008917 enforceReadPrivilegedPermission("isApnMetered");
8918
8919 // Now that all security checks passes, perform the operation as ourselves.
8920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 Phone phone = getPhone(subId);
8923 if (phone == null) return true; // By default return true.
8924
Jack Yu41407ee2019-05-13 16:54:09 -07008925 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
8929 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008930
8931 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008932 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8933 int subscriptionId, IBooleanConsumer resultCallback) {
8934 enforceModifyPermission();
8935 long token = Binder.clearCallingIdentity();
8936 try {
8937 Phone phone = getPhone(subscriptionId);
8938 if (phone == null) {
8939 try {
8940 if (resultCallback != null) {
8941 resultCallback.accept(false);
8942 }
8943 } catch (RemoteException e) {
8944 // ignore
8945 }
8946 return;
8947 }
8948 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8949 Pair.create(specifiers, (x) -> {
8950 try {
8951 if (resultCallback != null) {
8952 resultCallback.accept(x);
8953 }
8954 } catch (RemoteException e) {
8955 // ignore
8956 }
8957 });
8958 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8959 } finally {
8960 Binder.restoreCallingIdentity(token);
8961 }
8962 }
8963
8964 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008965 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8966 TelephonyPermissions
8967 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8968 mApp, subId, "getSystemSelectionChannels");
8969 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8970 final long identity = Binder.clearCallingIdentity();
8971 try {
8972 List<RadioAccessSpecifier> specifiers =
8973 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8974 null, subId, workSource);
8975 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8976 return specifiers;
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
8979 }
8980 }
8981
8982 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008983 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008984 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008985 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8986 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8987 if (iccRecords == null) {
8988 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8989 return false;
8990 }
8991 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8992 }
8993
8994 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008995 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8996 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008997 if (callingPackage == null) {
8998 callingPackage = getCurrentPackageName();
8999 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009000 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9001 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009002 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9003 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009004 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9005 }
9006 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9007 Intent intent = new Intent();
9008 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9009 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9010 // Bring up choose default SMS subscription dialog right now
9011 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9012 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9013 mApp.startActivity(intent);
9014 }
chen xud5ca2d52019-05-28 15:20:57 -07009015
9016 @Override
9017 public String getMmsUAProfUrl(int subId) {
9018 //TODO investigate if this API should require proper permission check in R b/133791609
9019 final long identity = Binder.clearCallingIdentity();
9020 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009021 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9022 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9023 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9024 return carrierUAProfUrl;
9025 }
chen xud5ca2d52019-05-28 15:20:57 -07009026 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9027 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 @Override
9034 public String getMmsUserAgent(int subId) {
9035 //TODO investigate if this API should require proper permission check in R b/133791609
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009038 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9039 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9040 if (!TextUtils.isEmpty(carrierUserAgent)) {
9041 return carrierUserAgent;
9042 }
chen xud5ca2d52019-05-28 15:20:57 -07009043 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9044 .getString(com.android.internal.R.string.config_mms_user_agent);
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
9048 }
Jack Yub07d4972019-05-28 16:12:25 -07009049
9050 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009051 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9052 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9053
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
9056 Phone phone = getPhone(subscriptionId);
9057 if (phone == null) return false;
9058
9059 switch (policy) {
9060 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9061 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9062 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9063 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9064 default:
9065 throw new IllegalArgumentException(policy + " is not a valid policy");
9066 }
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071
9072 @Override
9073 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9074 boolean enabled) {
9075 enforceModifyPermission();
9076
9077 final long identity = Binder.clearCallingIdentity();
9078 try {
9079 Phone phone = getPhone(subscriptionId);
9080 if (phone == null) return;
9081
9082 switch (policy) {
9083 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9084 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9085 break;
9086 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9087 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9088 break;
9089 default:
9090 throw new IllegalArgumentException(policy + " is not a valid policy");
9091 }
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009097 /**
Hall Liub48cf452020-09-25 11:13:49 -07009098 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009099 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9100 * otherwise.
9101 */
9102 @Override
9103 public void setCepEnabled(boolean isCepEnabled) {
9104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9105
9106 final long identity = Binder.clearCallingIdentity();
9107 try {
9108 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9109 for (Phone phone : PhoneFactory.getPhones()) {
9110 Phone defaultPhone = phone.getImsPhone();
9111 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9112 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9113 ImsPhoneCallTracker imsPhoneCallTracker =
9114 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9115 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9116 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9117 + imsPhone.getMsisdn());
9118 }
9119 }
9120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
allenwtsu46dcc572020-01-08 18:24:03 +08009124
9125 /**
9126 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9127 *
9128 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9129 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9130 * before being read.
9131 */
9132 @Override
9133 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9134 isCompressed) {
9135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9136 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9138 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9139 }
9140 if (!isImsAvailableOnDevice()) {
9141 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9142 "IMS not available on device.");
9143 }
9144
9145 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009146 try {
Hui Wang068ab862020-10-31 05:12:53 +00009147 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009150 }
9151 }
zoey chenf95ca592019-12-30 16:11:23 +08009152
9153 @Override
9154 public boolean isIccLockEnabled(int subId) {
9155 enforceReadPrivilegedPermission("isIccLockEnabled");
9156
9157 // Now that all security checks passes, perform the operation as ourselves.
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 Phone phone = getPhone(subId);
9161 if (phone != null && phone.getIccCard() != null) {
9162 return phone.getIccCard().getIccLockEnabled();
9163 } else {
9164 return false;
9165 }
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
9170
9171 /**
zoey chene02881a2019-12-30 16:11:23 +08009172 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009173 *
zoey chene02881a2019-12-30 16:11:23 +08009174 * @return an integer representing the status of IccLock enabled or disabled in the following
9175 * three cases:
9176 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9177 * successfully.
9178 * - Positive number and zero for remaining password attempts.
9179 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009180 *
9181 */
9182 @Override
9183 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9184 enforceModifyPermission();
9185
9186 Phone phone = getPhone(subId);
9187 if (phone == null) {
9188 return 0;
9189 }
9190 // Now that all security checks passes, perform the operation as ourselves.
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
9193 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9194 new Pair<Boolean, String>(enabled, password), phone, null);
9195 return attemptsRemaining;
9196
9197 } catch (Exception e) {
9198 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 return 0;
9203 }
9204
9205 /**
9206 * Change the ICC password used in ICC pin lock.
9207 *
zoey chene02881a2019-12-30 16:11:23 +08009208 * @return an integer representing the status of IccLock changed in the following three cases:
9209 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9210 * - Positive number and zero for remaining password attempts.
9211 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009212 *
9213 */
9214 @Override
9215 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9216 enforceModifyPermission();
9217
9218 Phone phone = getPhone(subId);
9219 if (phone == null) {
9220 return 0;
9221 }
9222 // Now that all security checks passes, perform the operation as ourselves.
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9226 new Pair<String, String>(oldPassword, newPassword), phone, null);
9227 return attemptsRemaining;
9228
9229 } catch (Exception e) {
9230 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 return 0;
9235 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009236
Peter Wangdafb9ac2020-01-15 14:13:38 -08009237 /**
9238 * Request for receiving user activity notification
9239 */
9240 @Override
9241 public void requestUserActivityNotification() {
9242 if (!mNotifyUserActivity.get()
9243 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9244 mNotifyUserActivity.set(true);
9245 }
9246 }
9247
9248 /**
9249 * Called when userActivity is signalled in the power manager.
9250 * This is safe to call from any thread, with any window manager locks held or not.
9251 */
9252 @Override
9253 public void userActivity() {
9254 // ***************************************
9255 // * Inherited from PhoneWindowManager *
9256 // ***************************************
9257 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9258 // WITH ITS LOCKS HELD.
9259 //
9260 // This code must be VERY careful about the locks
9261 // it acquires.
9262 // In fact, the current code acquires way too many,
9263 // and probably has lurking deadlocks.
9264
9265 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9266 throw new SecurityException("Only the OS may call notifyUserActivity()");
9267 }
9268
9269 if (mNotifyUserActivity.getAndSet(false)) {
9270 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9271 USER_ACTIVITY_NOTIFICATION_DELAY);
9272 }
9273 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009274
Malcolm Chen884180b2020-04-13 11:59:40 -07009275 @Override
9276 public boolean canConnectTo5GInDsdsMode() {
9277 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9278 }
Jack Yud10cdd42020-09-28 20:28:01 -07009279
9280 @Override
9281 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9282 String callingFeatureId) {
9283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9284 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9285 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9286 }
9287
9288 Phone phone = getPhone(subId);
9289 if (phone == null) {
9290 throw new RuntimeException("phone is not available");
9291 }
9292 // Now that all security checks passes, perform the operation as ourselves.
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 return phone.getEquivalentHomePlmns();
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009300
Hui Wang0866fcc2020-10-12 12:14:23 -07009301 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009302 public boolean isRadioInterfaceCapabilitySupported(
9303 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009304 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009305 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009306 if (radioInterfaceCapabilities == null) {
9307 throw new RuntimeException("radio interface capabilities are not available");
9308 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009309 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009310 }
9311 }
9312
9313 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009314 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9315 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009316 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9317 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9318 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9319 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9320 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009321 if (DBG) {
9322 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9323 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9324 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9325 }
9326
9327 if (!SubscriptionManager.isValidSubscriptionId(subId)
9328 || appType < TelephonyManager.APPTYPE_UNKNOWN
9329 || appType > TelephonyManager.APPTYPE_ISIM
9330 || nafUrl == null || securityProtocol == null || callback == null) {
9331 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9332 if (callback != null) {
9333 try {
9334 callback.onAuthenticationFailure(
9335 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9336 } catch (RemoteException exception) {
9337 log("Fail to notify onAuthenticationFailure due to " + exception);
9338 }
9339 return;
9340 }
9341 }
9342
9343 final long token = Binder.clearCallingIdentity();
9344 try {
9345 getGbaManager(subId).bootstrapAuthenticationRequest(
9346 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9347 forceBootStrapping, callback));
9348 } finally {
9349 Binder.restoreCallingIdentity(token);
9350 }
9351 }
9352
Jack Nudelman24d51a52020-11-24 12:08:04 -08009353 /**
9354 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9355 * requested radio power state will actually be set. See {@link
9356 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9357 *
9358 * @param subId the subscription ID of the phone requesting to set the radio power state.
9359 * @param enable {@code true} if trying to turn radio on.
9360 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9361 * false}.
9362 */
9363 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9364 Phone phone = getPhone(subId);
9365 if (phone != null) {
9366 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9367 return true;
9368 }
9369 return false;
9370 }
9371
9372 private int handleDataThrottlingRequest(int subId,
9373 DataThrottlingRequest dataThrottlingRequest) {
9374 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9375 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9376 if (!setRadioPowerForThermal(subId, true)) {
9377 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9378 }
9379
9380 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9381
9382 int thermalMitigationResult =
9383 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9384 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9385 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9386 }
9387 return thermalMitigationResult;
9388 }
9389
Jack Nudelman644b91a2021-03-12 14:09:48 -08009390 private static List<String> getThermalMitigationAllowlist(Context context) {
9391 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9392 for (String pckg : context.getResources()
9393 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9394 sThermalMitigationAllowlistedPackages.add(pckg);
9395 }
9396 }
9397
9398 return sThermalMitigationAllowlistedPackages;
9399 }
9400
9401 /**
9402 * Used by shell commands to add an authorized package name for thermal mitigation.
9403 * @param packageName name of package to be allowlisted
9404 * @param context
9405 */
9406 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9407 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9408 sThermalMitigationAllowlistedPackages.add(packageName);
9409 }
9410
9411 /**
9412 * Used by shell commands to remove an authorized package name for thermal mitigation.
9413 * @param packageName name of package to remove from allowlist
9414 * @param context
9415 */
9416 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9417 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9418 sThermalMitigationAllowlistedPackages.remove(packageName);
9419 }
9420
Jack Nudelman24d51a52020-11-24 12:08:04 -08009421 /**
9422 * Thermal mitigation request to control functionalities at modem.
9423 *
9424 * @param subId the id of the subscription.
9425 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009426 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009427 *
9428 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9429 */
9430 @Override
9431 @ThermalMitigationResult
9432 public int sendThermalMitigationRequest(
9433 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009434 ThermalMitigationRequest thermalMitigationRequest,
9435 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009436 enforceModifyPermission();
9437
Jack Nudelman644b91a2021-03-12 14:09:48 -08009438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9439 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9440 .contains(callingPackage)) {
9441 throw new SecurityException("Calling package must be configured in the device config. "
9442 + "calling package: " + callingPackage);
9443 }
9444
Jack Nudelman24d51a52020-11-24 12:08:04 -08009445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9446 final long identity = Binder.clearCallingIdentity();
9447
9448 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9449 try {
9450 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9451 switch (thermalMitigationAction) {
9452 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9453 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009454 handleDataThrottlingRequest(subId,
9455 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009456 break;
9457 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9458 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9459 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9460 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9461 }
9462
9463 // Ensure that radio is on. If not able to power on due to phone being
9464 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9465 if (!setRadioPowerForThermal(subId, true)) {
9466 thermalMitigationResult =
9467 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9468 break;
9469 }
9470
9471 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9472 false);
9473 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9474 break;
9475 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9476 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9477 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9478 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9479 }
9480
9481 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9482 if (registry != null) {
9483 TelephonyConnectionService service =
9484 registry.getTelephonyConnectionService();
9485 Phone phone = getPhone(subId);
9486 if (phone == null) {
9487 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009488 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009489 break;
9490 }
9491
9492 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009493 != TelephonyManager.CALL_STATE_IDLE
9494 || phone.isInEmergencySmsMode() || phone.isInEcm()
9495 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009496 String errorMessage = "Phone state is not valid. call state = "
9497 + PhoneConstantConversions.convertCallState(phone.getState())
9498 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9499 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9500 errorMessage += service == null
9501 ? " TelephonyConnectionService is null"
9502 : " isEmergencyCallPending = "
9503 + service.isEmergencyCallPending();
9504 Log.e(LOG_TAG, errorMessage);
9505 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009506 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009507 break;
9508 }
9509 } else {
9510 thermalMitigationResult =
9511 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9512 break;
9513 }
9514
9515 // Turn radio off. If not able to power off due to phone being unavailable,
9516 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9517 if (!setRadioPowerForThermal(subId, false)) {
9518 thermalMitigationResult =
9519 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9520 break;
9521 }
9522 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009523 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009524 break;
9525 default:
9526 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9527 + "not exist. Requested action: " + thermalMitigationAction);
9528 }
9529 } catch (IllegalArgumentException e) {
9530 throw e;
9531 } catch (Exception e) {
9532 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9533 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537
9538 if (DBG) {
9539 log("thermalMitigationRequest returning with thermalMitigationResult: "
9540 + thermalMitigationResult);
9541 }
9542
9543 return thermalMitigationResult;
9544 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009545
9546 /**
9547 * Set the GbaService Package Name that Telephony will bind to.
9548 *
9549 * @param subId The sim that the GbaService is associated with.
9550 * @param packageName The name of the package to be replaced with.
9551 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9552 */
9553 @Override
9554 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9555 enforceModifyPermission();
9556
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 return getGbaManager(subId).overrideServicePackage(packageName);
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
9564
9565 /**
9566 * Return the package name of the currently bound GbaService.
9567 *
9568 * @param subId The sim that the GbaService is associated with.
9569 * @return the package name of the GbaService configuration, null if GBA is not supported.
9570 */
9571 @Override
9572 public String getBoundGbaService(int subId) {
9573 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 return getGbaManager(subId).getServicePackage();
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 }
9582
9583 /**
9584 * Set the release time for telephony to unbind GbaService.
9585 *
9586 * @param subId The sim that the GbaService is associated with.
9587 * @param interval The release time to unbind GbaService by millisecond.
9588 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9589 */
9590 @Override
9591 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9592 enforceModifyPermission();
9593
9594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 return getGbaManager(subId).overrideReleaseTime(interval);
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
9600 }
9601
9602 /**
9603 * Return the release time for telephony to unbind GbaService.
9604 *
9605 * @param subId The sim that the GbaService is associated with.
9606 * @return The release time to unbind GbaService by millisecond.
9607 */
9608 @Override
9609 public int getGbaReleaseTime(int subId) {
9610 enforceReadPrivilegedPermission("getGbaReleaseTime");
9611
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 return getGbaManager(subId).getReleaseTime();
9615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
9619
9620 private GbaManager getGbaManager(int subId) {
9621 GbaManager instance = GbaManager.getInstance(subId);
9622 if (instance == null) {
9623 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9624 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9625 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9626 }
9627 return instance;
9628 }
Hui Wang068ab862020-10-31 05:12:53 +00009629
9630 /**
9631 * indicate whether the device and the carrier can support
9632 * RCS VoLTE single registration.
9633 */
9634 @Override
9635 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009636 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9637 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9638 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9639 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009640
9641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9643 }
9644
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9648 if (rpm != null) {
9649 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9650 }
9651 return false;
9652 } finally {
9653 Binder.restoreCallingIdentity(identity);
9654 }
9655 }
9656
9657 /**
9658 * Register RCS provisioning callback.
9659 */
9660 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009661 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009662 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009663 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009664 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009665 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9666 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009667
9668 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9669 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9670 }
9671 if (!isImsAvailableOnDevice()) {
9672 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9673 "IMS not available on device.");
9674 }
9675
9676 final long identity = Binder.clearCallingIdentity();
9677 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009678 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009679 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9681 "Service not available for the subscription.");
9682 }
Hui Wang068ab862020-10-31 05:12:53 +00009683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
9687
9688 /**
9689 * Unregister RCS provisioning callback.
9690 */
9691 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009692 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009693 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009694 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009695 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009696 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9697 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009698
9699 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9700 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9701 }
9702 if (!isImsAvailableOnDevice()) {
9703 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9704 "IMS not available on device.");
9705 }
9706
9707 final long identity = Binder.clearCallingIdentity();
9708 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009709 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009710 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
9716 /**
9717 * trigger RCS reconfiguration.
9718 */
9719 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009720 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9721 "triggerRcsReconfiguration",
9722 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009723
9724 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9725 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9726 }
9727 if (!isImsAvailableOnDevice()) {
9728 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9729 "IMS not available on device.");
9730 }
9731
9732 final long identity = Binder.clearCallingIdentity();
9733 try {
9734 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 }
9739
9740 /**
9741 * Provide the client configuration parameters of the RCS application.
9742 */
9743 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009744 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9745 "setRcsClientConfiguration",
9746 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009747
9748 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9749 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9750 }
9751 if (!isImsAvailableOnDevice()) {
9752 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9753 "IMS not available on device.");
9754 }
9755
9756 final long identity = Binder.clearCallingIdentity();
9757
9758 try {
9759 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9760 if (configBinder == null) {
9761 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9762 } else {
9763 configBinder.setRcsClientConfiguration(rcc);
9764 }
9765 } catch (RemoteException e) {
9766 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
9771
9772 /**
Hui Wang19a21872021-02-19 20:45:36 -08009773 * Enables or disables the test mode for RCS VoLTE single registration.
9774 */
9775 @Override
9776 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9778 "setRcsSingleRegistrationTestModeEnabled");
9779
9780 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9781 }
9782
9783 /**
9784 * Gets the test mode for RCS VoLTE single registration.
9785 */
9786 @Override
9787 public boolean getRcsSingleRegistrationTestModeEnabled() {
9788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9789 "getRcsSingleRegistrationTestModeEnabled");
9790
9791 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9792 }
9793
9794 /**
Hui Wang068ab862020-10-31 05:12:53 +00009795 * Overrides the config of RCS VoLTE single registration enabled for the device.
9796 */
9797 @Override
9798 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9799 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9800 "setDeviceSingleRegistrationEnabledOverride");
9801 enforceModifyPermission();
9802
9803 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9804 : Boolean.parseBoolean(enabledStr);
9805 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009806 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009807 }
9808
9809 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009810 * Sends a device to device communication message. Only usable via shell.
9811 * @param message message to send.
9812 * @param value message value.
9813 */
9814 @Override
9815 public void sendDeviceToDeviceMessage(int message, int value) {
9816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9817 "setCarrierSingleRegistrationEnabledOverride");
9818 enforceModifyPermission();
9819
9820 final long identity = Binder.clearCallingIdentity();
9821 try {
9822 TelephonyConnectionService service =
9823 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9824 if (service == null) {
9825 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9826 return;
9827 }
9828 service.sendTestDeviceToDeviceMessage(message, value);
9829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
9834
9835 /**
Hui Wang068ab862020-10-31 05:12:53 +00009836 * Gets the config of RCS VoLTE single registration enabled for the device.
9837 */
9838 @Override
9839 public boolean getDeviceSingleRegistrationEnabled() {
9840 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9841 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9842 }
9843
9844 /**
9845 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9846 */
9847 @Override
9848 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9850 "setCarrierSingleRegistrationEnabledOverride");
9851 enforceModifyPermission();
9852
9853 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9854 : Boolean.parseBoolean(enabledStr);
9855 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9856 subId, enabled);
9857 }
9858
9859 /**
9860 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9861 */
9862 @Override
9863 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9864 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9865 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9866 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009867
9868 /**
9869 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9870 * their mobile plan.
9871 */
9872 @Override
9873 public String getMobileProvisioningUrl() {
9874 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9875 final long identity = Binder.clearCallingIdentity();
9876 try {
9877 return getDefaultPhone().getMobileProvisioningUrl();
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009882
James.cf Linbcdf8b32021-01-14 16:44:13 +08009883 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009884 * Get the EAB contact from the EAB database.
9885 */
9886 @Override
9887 public String getContactFromEab(String contact) {
9888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9889 enforceModifyPermission();
9890 final long identity = Binder.clearCallingIdentity();
9891 try {
9892 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9893 } finally {
9894 Binder.restoreCallingIdentity(identity);
9895 }
9896 }
9897
9898 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009899 * Remove the EAB contacts from the EAB database.
9900 */
9901 @Override
9902 public int removeContactFromEab(int subId, String contacts) {
9903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9904 enforceModifyPermission();
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
9907 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 }
9912
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009913 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009914 public boolean getDeviceUceEnabled() {
9915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 return mApp.getDeviceUceEnabled();
9919 } finally {
9920 Binder.restoreCallingIdentity(identity);
9921 }
9922 }
9923
9924 @Override
9925 public void setDeviceUceEnabled(boolean isEnabled) {
9926 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9927 final long identity = Binder.clearCallingIdentity();
9928 try {
9929 mApp.setDeviceUceEnabled(isEnabled);
9930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
9934
Brad Ebingerd4c5bde2021-02-12 06:18:28 +00009935 /**
9936 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
9937 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9938 */
9939 // Used for SHELL command only right now.
9940 @Override
9941 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
9942 List<String> featureTags) {
9943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9944 "addUceRegistrationOverrideShell");
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
9947 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
9948 new ArraySet<>(featureTags));
9949 } catch (ImsException e) {
9950 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9951 } finally {
9952 Binder.restoreCallingIdentity(identity);
9953 }
9954 }
9955
9956 /**
9957 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
9958 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9959 */
9960 // Used for SHELL command only right now.
9961 @Override
9962 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
9963 List<String> featureTags) {
9964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9965 "removeUceRegistrationOverrideShell");
9966 final long identity = Binder.clearCallingIdentity();
9967 try {
9968 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
9969 new ArraySet<>(featureTags));
9970 } catch (ImsException e) {
9971 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
9976
9977 /**
9978 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
9979 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9980 */
9981 // Used for SHELL command only right now.
9982 @Override
9983 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
9984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9985 "clearUceRegistrationOverrideShell");
9986 final long identity = Binder.clearCallingIdentity();
9987 try {
9988 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
9989 } catch (ImsException e) {
9990 throw new ServiceSpecificException(e.getCode(), e.getMessage());
9991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
9995
9996 /**
9997 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
9998 */
9999 // Used for SHELL command only right now.
10000 @Override
10001 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10002 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10003 "getLatestRcsContactUceCapabilityShell");
10004 final long identity = Binder.clearCallingIdentity();
10005 try {
10006 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10007 } catch (ImsException e) {
10008 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10009 } finally {
10010 Binder.restoreCallingIdentity(identity);
10011 }
10012 }
10013
10014 /**
10015 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10016 * device does not have an active PUBLISH.
10017 */
10018 // Used for SHELL command only right now.
10019 @Override
10020 public String getLastUcePidfXmlShell(int subId) {
10021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10022 final long identity = Binder.clearCallingIdentity();
10023 try {
10024 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10025 } catch (ImsException e) {
10026 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10027 } finally {
10028 Binder.restoreCallingIdentity(identity);
10029 }
10030 }
10031
10032
James.cf Lin4b784aa2021-01-31 03:25:15 +080010033 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010034 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10035 String callingPackage) {
10036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10037 mApp, subId, "setSignalStrengthUpdateRequest");
10038
10039 final int callingUid = Binder.getCallingUid();
10040 // Verify that tha callingPackage belongs to the calling UID
10041 mApp.getSystemService(AppOpsManager.class)
10042 .checkPackage(callingUid, callingPackage);
10043
10044 validateSignalStrengthUpdateRequest(request, callingUid);
10045
10046 final long identity = Binder.clearCallingIdentity();
10047 try {
10048 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10049 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10050
10051 if (result instanceof IllegalStateException) {
10052 throw (IllegalStateException) result;
10053 }
10054 } finally {
10055 Binder.restoreCallingIdentity(identity);
10056 }
10057 }
10058
10059 @Override
10060 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10061 String callingPackage) {
10062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10063 mApp, subId, "clearSignalStrengthUpdateRequest");
10064
10065 final int callingUid = Binder.getCallingUid();
10066 // Verify that tha callingPackage belongs to the calling UID
10067 mApp.getSystemService(AppOpsManager.class)
10068 .checkPackage(callingUid, callingPackage);
10069
10070 final long identity = Binder.clearCallingIdentity();
10071 try {
10072 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10073 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10074
10075 if (result instanceof IllegalStateException) {
10076 throw (IllegalStateException) result;
10077 }
10078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
10081 }
10082
10083 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10084 int callingUid) {
10085 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10086 // phone/system process do not have further restriction on request
10087 return;
10088 }
10089
10090 // Applications has restrictions on how to use the request:
10091 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10092 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10093 // This is not system caller which has been checked above
10094 throw new IllegalArgumentException(
10095 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10096 }
10097
10098 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10099 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10100 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10101 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10102 || info.isEnabled()) {
10103 throw new IllegalArgumentException(
10104 "Only system can set hide fields in SignalThresholdInfo");
10105 }
10106
10107 // Thresholds length for each RAN need in range. This has been validated in
10108 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10109 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10110 final int[] thresholds = info.getThresholds();
10111 Objects.requireNonNull(thresholds);
10112 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10113 || thresholds.length
10114 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10115 throw new IllegalArgumentException(
10116 "thresholds length is out of range: " + thresholds.length);
10117 }
10118 }
10119 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010120
10121 /**
10122 * Prepare TelephonyManager for an unattended reboot. The reboot is
10123 * required to be done shortly after the API is invoked.
10124 */
10125 @Override
10126 @TelephonyManager.PrepareUnattendedRebootResult
10127 public int prepareForUnattendedReboot() {
10128 enforceRebootPermission();
10129
10130 final long identity = Binder.clearCallingIdentity();
10131 try {
10132 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10133 } finally {
10134 Binder.restoreCallingIdentity(identity);
10135 }
10136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010137}