blob: 64f88f5b32fcfd0c0b96aaeb14dfa902a6bedc6b [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Brad Ebinger4df7e242021-02-17 23:23:21 +000024import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080026import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070027import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080055import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080068import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070070import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070071import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080072import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070073import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080074import android.telephony.CellIdentityCdma;
75import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070077import android.telephony.CellInfoGsm;
78import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070079import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080080import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070081import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070082import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070083import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080084import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070085import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080086import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070087import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080088import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080089import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070090import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800162import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700163import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700164import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800166import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800167import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700169import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700171import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800172import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700173import com.android.internal.telephony.imsphone.ImsPhone;
174import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800175import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900176import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800178import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700181import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800186import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700187import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700188import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800192import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700193import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700194import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800195import com.android.services.telephony.TelecomAccountRegistry;
196import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800197import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800198
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700199import java.io.FileDescriptor;
200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800211import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800212import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
214/**
215 * Implementation of the ITelephony interface.
216 */
Santos Cordon117fee72014-05-16 17:56:12 -0700217public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 private static final String LOG_TAG = "PhoneInterfaceManager";
219 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
220 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 // Message codes used with mMainThreadHandler
224 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700225 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
226 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227 private static final int CMD_OPEN_CHANNEL = 9;
228 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
229 private static final int CMD_CLOSE_CHANNEL = 11;
230 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800231 private static final int CMD_NV_READ_ITEM = 13;
232 private static final int EVENT_NV_READ_ITEM_DONE = 14;
233 private static final int CMD_NV_WRITE_ITEM = 15;
234 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
235 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
236 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700237 private static final int CMD_RESET_MODEM_CONFIG = 19;
238 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800239 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
240 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800241 private static final int CMD_SEND_ENVELOPE = 25;
242 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000243 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
244 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700245 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
246 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
247 private static final int CMD_EXCHANGE_SIM_IO = 31;
248 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800249 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
250 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700251 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
252 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700253 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
254 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700255 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
256 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
257 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700259 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
260 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
261 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
262 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700263 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800264 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
265 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000266 private static final int CMD_SWITCH_SLOTS = 50;
267 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700268 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
269 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
270 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
271 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
272 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
273 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
274 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
275 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700276 private static final int CMD_GET_ALL_CELL_INFO = 60;
277 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
278 private static final int CMD_GET_CELL_LOCATION = 62;
279 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700280 private static final int CMD_MODEM_REBOOT = 64;
281 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700282 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
283 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800284 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
285 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700286 private static final int CMD_GET_MODEM_STATUS = 70;
287 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700288 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
289 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700290 private static final int CMD_ERASE_MODEM_CONFIG = 74;
291 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800292 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
293 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
294 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
295 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800296 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
297 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800298 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800299 private static final int CMD_GET_CALL_FORWARDING = 83;
300 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
301 private static final int CMD_SET_CALL_FORWARDING = 85;
302 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
303 private static final int CMD_GET_CALL_WAITING = 87;
304 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
305 private static final int CMD_SET_CALL_WAITING = 89;
306 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700307 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
308 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
309 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
310 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700311 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
312 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800313 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
314 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800315 private static final int CMD_SET_DATA_THROTTLING = 99;
316 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800317 private static final int CMD_SET_SIM_POWER = 101;
318 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800319 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
320 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
321 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
322 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800323 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
324 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000325 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800327 // Parameters of select command.
328 private static final int SELECT_COMMAND = 0xA4;
329 private static final int SELECT_P1 = 0x04;
330 private static final int SELECT_P2 = 0;
331 private static final int SELECT_P3 = 0x10;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 /** The singleton instance. */
334 private static PhoneInterfaceManager sInstance;
335
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800338 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700339 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private AppOpsManager mAppOps;
341 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800342 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700344 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800345 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 /** User Activity */
348 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800349 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
350
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700351 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
352
Derek Tan97ebb422014-09-05 16:55:38 -0700353 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
354 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800355 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800356 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700357
Michelecea4cf22018-12-21 15:00:11 -0800358 // String to store multi SIM allowed
359 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
360
Derek Tan740e1672017-06-27 14:56:27 -0700361 // The AID of ISD-R.
362 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
363
yinxub1bed742017-04-17 11:45:04 -0700364 private NetworkScanRequestTracker mNetworkScanRequestTracker;
365
David Kelly5e06a7f2018-03-12 14:10:59 +0000366 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
367 private static final int MANUFACTURER_CODE_LENGTH = 8;
368
Jack Nudelman24d51a52020-11-24 12:08:04 -0800369 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
370
Derek Tan89e89d42014-07-08 17:00:10 -0700371 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700372 * Experiment flag to enable erase modem config on reset network, default value is false
373 */
374 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
375 "reset_network_erase_modem_config_enabled";
376
Rambo Wang0f050d82021-02-12 11:43:36 -0800377 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
378
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700379 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700380 * A request object to use for transmitting data to an ICC.
381 */
382 private static final class IccAPDUArgument {
383 public int channel, cla, command, p1, p2, p3;
384 public String data;
385
386 public IccAPDUArgument(int channel, int cla, int command,
387 int p1, int p2, int p3, String data) {
388 this.channel = channel;
389 this.cla = cla;
390 this.command = command;
391 this.p1 = p1;
392 this.p2 = p2;
393 this.p3 = p3;
394 this.data = data;
395 }
396 }
397
398 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700399 * A request object to use for transmitting data to an ICC.
400 */
401 private static final class ManualNetworkSelectionArgument {
402 public OperatorInfo operatorInfo;
403 public boolean persistSelection;
404
405 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
406 this.operatorInfo = operatorInfo;
407 this.persistSelection = persistSelection;
408 }
409 }
410
411 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
413 * request after sending. The main thread will notify the request when it is complete.
414 */
415 private static final class MainThreadRequest {
416 /** The argument to use for the request */
417 public Object argument;
418 /** The result of the request that is run on the main thread */
419 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800420 // The subscriber id that this request applies to. Defaults to
421 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
422 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Nathan Harold92bed182018-10-12 18:16:49 -0700424 // In cases where subId is unavailable, the caller needs to specify the phone.
425 public Phone phone;
426
vagdeviaf9a5b92018-08-15 16:01:53 -0700427 public WorkSource workSource;
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 public MainThreadRequest(Object argument) {
430 this.argument = argument;
431 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800432
Nathan Harold92bed182018-10-12 18:16:49 -0700433 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
434 this.argument = argument;
435 if (phone != null) {
436 this.phone = phone;
437 }
438 this.workSource = workSource;
439 }
440
vagdeviaf9a5b92018-08-15 16:01:53 -0700441 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800442 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800443 if (subId != null) {
444 this.subId = subId;
445 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700446 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 }
449
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800450 private static final class IncomingThirdPartyCallArgs {
451 public final ComponentName component;
452 public final String callId;
453 public final String callerDisplayName;
454
455 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
456 String callerDisplayName) {
457 this.component = component;
458 this.callId = callId;
459 this.callerDisplayName = callerDisplayName;
460 }
461 }
462
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 /**
464 * A handler that processes messages on the main thread in the phone process. Since many
465 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
466 * inbound binder threads to the main thread in the phone process. The Binder thread
467 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
468 * on, which will be notified when the operation completes and will contain the result of the
469 * request.
470 *
471 * <p>If a MainThreadRequest object is provided in the msg.obj field,
472 * note that request.result must be set to something non-null for the calling thread to
473 * unblock.
474 */
475 private final class MainThreadHandler extends Handler {
476 @Override
477 public void handleMessage(Message msg) {
478 MainThreadRequest request;
479 Message onCompleted;
480 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800483 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484
485 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 case CMD_HANDLE_USSD_REQUEST: {
487 request = (MainThreadRequest) msg.obj;
488 final Phone phone = getPhoneFromRequest(request);
489 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
490 String ussdRequest = ussdObject.first;
491 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700492
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 if (!isUssdApiAllowed(request.subId)) {
494 // Carrier does not support use of this API, return failure.
495 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
496 UssdResponse response = new UssdResponse(ussdRequest, null);
497 Bundle returnData = new Bundle();
498 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
499 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700500
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 request.result = true;
502 notifyRequester(request);
503 return;
504 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700505
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 try {
507 request.result = phone != null
508 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
509 } catch (CallStateException cse) {
510 request.result = false;
511 }
512 // Wake up the requesting thread
513 notifyRequester(request);
514 break;
pkanwar32d516d2016-10-14 19:37:38 -0700515 }
516
Yorke Lee716f67e2015-06-17 15:39:16 -0700517 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 final Phone phone = getPhoneFromRequest(request);
520 request.result = phone != null ?
521 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
522 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("iccTransmitApduLogicalChannel: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
538 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 iccArgument.channel, iccArgument.cla, iccArgument.command,
541 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 break;
545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 ar = (AsyncResult) msg.obj;
548 request = (MainThreadRequest) ar.userObj;
549 if (ar.exception == null && ar.result != null) {
550 request.result = ar.result;
551 } else {
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 if (ar.result == null) {
554 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800555 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800557 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 } else {
559 loge("iccTransmitApduLogicalChannel: Unknown exception");
560 }
561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
566 request = (MainThreadRequest) msg.obj;
567 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 if (uiccCard == null) {
570 loge("iccTransmitApduBasicChannel: No UICC");
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 } else {
574 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
575 request);
576 uiccCard.iccTransmitApduBasicChannel(
577 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
578 iccArgument.p3, iccArgument.data, onCompleted);
579 }
580 break;
581
582 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
583 ar = (AsyncResult) msg.obj;
584 request = (MainThreadRequest) ar.userObj;
585 if (ar.exception == null && ar.result != null) {
586 request.result = ar.result;
587 } else {
588 request.result = new IccIoResult(0x6F, 0, (byte[])null);
589 if (ar.result == null) {
590 loge("iccTransmitApduBasicChannel: Empty response");
591 } else if (ar.exception instanceof CommandException) {
592 loge("iccTransmitApduBasicChannel: CommandException: " +
593 ar.exception);
594 } else {
595 loge("iccTransmitApduBasicChannel: Unknown exception");
596 }
597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 break;
600
601 case CMD_EXCHANGE_SIM_IO:
602 request = (MainThreadRequest) msg.obj;
603 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800604 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 if (uiccCard == null) {
606 loge("iccExchangeSimIO: No UICC");
607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 } else {
610 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
611 request);
612 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
613 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
614 iccArgument.data, onCompleted);
615 }
616 break;
617
618 case EVENT_EXCHANGE_SIM_IO_DONE:
619 ar = (AsyncResult) msg.obj;
620 request = (MainThreadRequest) ar.userObj;
621 if (ar.exception == null && ar.result != null) {
622 request.result = ar.result;
623 } else {
624 request.result = new IccIoResult(0x6f, 0, (byte[])null);
625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 break;
628
Derek Tan4d5e5c12014-02-04 11:54:58 -0800629 case CMD_SEND_ENVELOPE:
630 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 if (uiccCard == null) {
633 loge("sendEnvelopeWithStatus: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
638 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
639 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 break;
641
642 case EVENT_SEND_ENVELOPE_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700648 request.result = new IccIoResult(0x6F, 0, (byte[])null);
649 if (ar.result == null) {
650 loge("sendEnvelopeWithStatus: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("sendEnvelopeWithStatus: CommandException: " +
653 ar.exception);
654 } else {
655 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
656 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 break;
660
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 case CMD_OPEN_CHANNEL:
662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800663 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800664 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 if (uiccCard == null) {
666 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800667 request.result = new IccOpenLogicalChannelResponse(-1,
668 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800672 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
673 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case EVENT_OPEN_CHANNEL_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 int[] result = (int[]) ar.result;
683 int channelId = result[0];
684 byte[] selectResponse = null;
685 if (result.length > 1) {
686 selectResponse = new byte[result.length - 1];
687 for (int i = 1; i < result.length; ++i) {
688 selectResponse[i - 1] = (byte) result[i];
689 }
690 }
691 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 if (ar.result == null) {
695 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.exception != null) {
698 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
699 }
700
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700701 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700702 if (ar.exception instanceof CommandException) {
703 CommandException.Error error =
704 ((CommandException) (ar.exception)).getCommandError();
705 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700706 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700707 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 }
710 }
711 openChannelResp = new IccOpenLogicalChannelResponse(
712 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700714 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 break;
717
718 case CMD_CLOSE_CHANNEL:
719 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800720 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 if (uiccCard == null) {
722 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900723 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 } else {
726 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
727 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
728 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 break;
730
731 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800732 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
733 break;
734
735 case CMD_NV_READ_ITEM:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800738 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
739 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
742 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 ar = (AsyncResult) msg.obj;
744 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800745 if (ar.exception == null && ar.result != null) {
746 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800748 request.result = "";
749 if (ar.result == null) {
750 loge("nvReadItem: Empty response");
751 } else if (ar.exception instanceof CommandException) {
752 loge("nvReadItem: CommandException: " +
753 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800755 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 }
757 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 break;
760
Jake Hambye994d462014-02-03 13:10:13 -0800761 case CMD_NV_WRITE_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
764 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_WRITE_ITEM_DONE:
770 handleNullReturnEvent(msg, "nvWriteItem");
771 break;
772
773 case CMD_NV_WRITE_CDMA_PRL:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800776 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800777 break;
778
779 case EVENT_NV_WRITE_CDMA_PRL_DONE:
780 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
781 break;
782
chen xu6dac5ab2018-10-26 17:39:23 -0700783 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800784 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700785 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
chen xu6dac5ab2018-10-26 17:39:23 -0700789 case EVENT_RESET_MODEM_CONFIG_DONE:
790 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800791 break;
792
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700793 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
794 request = (MainThreadRequest) msg.obj;
795 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
796 request);
797 Phone phone = getPhoneFromRequest(request);
798 if (phone != null) {
799 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
800 } else {
801 loge("isNRDualConnectivityEnabled: No phone object");
802 request.result = false;
803 notifyRequester(request);
804 }
805 break;
806 }
807
808 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
811 if (ar.exception == null && ar.result != null) {
812 request.result = ar.result;
813 } else {
814 // request.result must be set to something non-null
815 // for the calling thread to unblock
816 if (request.result != null) {
817 request.result = ar.result;
818 } else {
819 request.result = false;
820 }
821 if (ar.result == null) {
822 loge("isNRDualConnectivityEnabled: Empty response");
823 } else if (ar.exception instanceof CommandException) {
824 loge("isNRDualConnectivityEnabled: CommandException: "
825 + ar.exception);
826 } else {
827 loge("isNRDualConnectivityEnabled: Unknown exception");
828 }
829 }
830 notifyRequester(request);
831 break;
832
833 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
836 Phone phone = getPhoneFromRequest(request);
837 if (phone != null) {
838 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
839 request.workSource);
840 } else {
841 loge("enableNrDualConnectivity: No phone object");
842 request.result =
843 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
844 notifyRequester(request);
845 }
846 break;
847 }
848
849 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null) {
853 request.result =
854 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
855 } else {
856 request.result =
857 TelephonyManager
858 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
859 if (ar.exception instanceof CommandException) {
860 CommandException.Error error =
861 ((CommandException) (ar.exception)).getCommandError();
862 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
863 request.result =
864 TelephonyManager
865 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000866 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
867 request.result =
868 TelephonyManager
869 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700870 }
871 loge("enableNrDualConnectivity" + ": CommandException: "
872 + ar.exception);
873 } else {
874 loge("enableNrDualConnectivity" + ": Unknown exception");
875 }
876 }
877 notifyRequester(request);
878 break;
879 }
880
SongFerngWang9e060372020-12-21 16:41:52 +0800881 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800882 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800883 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
884 request);
885 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 break;
887
SongFerngWang9e060372020-12-21 16:41:52 +0800888 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result; // Integer
893 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530894 // request.result must be set to something non-null
895 // for the calling thread to unblock
896 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800898 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800900 loge("getAllowedNetworkTypesBitmask: CommandException: "
901 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800903 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
SongFerngWang9e060372020-12-21 16:41:52 +0800909 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800911 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
912 request);
913 Pair<Integer, Long> reasonWithNetworkTypes =
914 (Pair<Integer, Long>) request.argument;
915 getPhoneFromRequest(request).setAllowedNetworkTypes(
916 reasonWithNetworkTypes.first,
917 reasonWithNetworkTypes.second,
918 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 break;
920
SongFerngWang9e060372020-12-21 16:41:52 +0800921 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
922 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 break;
924
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000925 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
926 request = (MainThreadRequest)msg.obj;
927 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800928 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000929 break;
930
931 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
932 ar = (AsyncResult)msg.obj;
933 request = (MainThreadRequest)ar.userObj;
934 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000936 break;
937
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800938 case CMD_SET_VOICEMAIL_NUMBER:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
941 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800942 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
943 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800944 break;
945
946 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
947 handleNullReturnEvent(msg, "setVoicemailNumber");
948 break;
949
Stuart Scott54788802015-03-30 13:18:01 -0700950 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
953 request);
954 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
955 break;
956
957 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
958 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
959 break;
960
Shishir Agrawal302c8692015-06-19 13:49:39 -0700961 case CMD_PERFORM_NETWORK_SCAN:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
964 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
965 break;
966
Hall Liua1acea22020-09-18 19:04:59 -0700967 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700970 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
971 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
972 request.argument;
973 int callForwardingReason = args.first;
974 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800975 break;
Hall Liua1acea22020-09-18 19:04:59 -0700976 }
977 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700980 TelephonyManager.CallForwardingInfoCallback callback =
981 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
982 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800983 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700984 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800985 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
986 for (CallForwardInfo callForwardInfo : callForwardInfos) {
987 // Service Class is a bit mask per 3gpp 27.007. Search for
988 // any service for voice call.
989 if ((callForwardInfo.serviceClass
990 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700991 callForwardingInfo = new CallForwardingInfo(true,
992 callForwardInfo.reason,
993 callForwardInfo.number,
994 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800995 break;
996 }
997 }
998 // Didn't find a call forward info for voice call.
999 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001000 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1001 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001002 }
Hall Liua1acea22020-09-18 19:04:59 -07001003 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001004 } else {
1005 if (ar.result == null) {
1006 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1007 }
1008 if (ar.exception != null) {
1009 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1010 }
Hall Liuae527aa2020-09-29 17:10:18 -07001011 int errorCode = TelephonyManager
1012 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001013 if (ar.exception instanceof CommandException) {
1014 CommandException.Error error =
1015 ((CommandException) (ar.exception)).getCommandError();
1016 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001017 errorCode = TelephonyManager
1018 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001019 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001020 errorCode = TelephonyManager
1021 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001022 }
1023 }
Hall Liua1acea22020-09-18 19:04:59 -07001024 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001025 }
sqian80370722020-01-29 15:02:51 -08001026 break;
Hall Liua1acea22020-09-18 19:04:59 -07001027 }
sqian80370722020-01-29 15:02:51 -08001028
Hall Liua1acea22020-09-18 19:04:59 -07001029 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001032 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001033 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001034 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1035 request.argument).first;
1036 request.phone.setCallForwardingOption(
1037 callForwardingInfoToSet.isEnabled()
1038 ? CommandsInterface.CF_ACTION_ENABLE
1039 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001040 callForwardingInfoToSet.getReason(),
1041 callForwardingInfoToSet.getNumber(),
1042 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1043 break;
Hall Liua1acea22020-09-18 19:04:59 -07001044 }
sqian80370722020-01-29 15:02:51 -08001045
Hall Liua1acea22020-09-18 19:04:59 -07001046 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001049 Consumer<Integer> callback =
1050 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1051 request.argument).second;
1052 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001053 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001054 int errorCode = TelephonyManager.CallForwardingInfoCallback
1055 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001056 if (ar.exception instanceof CommandException) {
1057 CommandException.Error error =
1058 ((CommandException) (ar.exception)).getCommandError();
1059 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001060 errorCode = TelephonyManager.CallForwardingInfoCallback
1061 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001062 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001063 errorCode = TelephonyManager.CallForwardingInfoCallback
1064 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001065 }
1066 }
1067 callback.accept(errorCode);
1068 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001069 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001070 }
sqian80370722020-01-29 15:02:51 -08001071 break;
Hall Liua1acea22020-09-18 19:04:59 -07001072 }
sqian80370722020-01-29 15:02:51 -08001073
Hall Liua1acea22020-09-18 19:04:59 -07001074 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1077 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1078 break;
Hall Liua1acea22020-09-18 19:04:59 -07001079 }
sqian80370722020-01-29 15:02:51 -08001080
Hall Liua1acea22020-09-18 19:04:59 -07001081 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001084 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001085 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1086 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001087 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001088 // Service Class is a bit mask per 3gpp 27.007.
1089 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001090 if (callForwardResults.length > 1
1091 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001092 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001093 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001094 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1095 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001096 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001097 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001098 }
1099 } else {
1100 if (ar.result == null) {
1101 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1102 }
1103 if (ar.exception != null) {
1104 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1105 }
1106 if (ar.exception instanceof CommandException) {
1107 CommandException.Error error =
1108 ((CommandException) (ar.exception)).getCommandError();
1109 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1110 callForwardingStatus =
1111 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1112 }
1113 }
1114 }
Hall Liua1acea22020-09-18 19:04:59 -07001115 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001116 break;
Hall Liua1acea22020-09-18 19:04:59 -07001117 }
sqian80370722020-01-29 15:02:51 -08001118
Hall Liua1acea22020-09-18 19:04:59 -07001119 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001120 request = (MainThreadRequest) msg.obj;
1121 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001122 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1123 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001124 break;
Hall Liua1acea22020-09-18 19:04:59 -07001125 }
sqian80370722020-01-29 15:02:51 -08001126
Hall Liua1acea22020-09-18 19:04:59 -07001127 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001130 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1131 Consumer<Integer> callback =
1132 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1133 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001134 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001135 if (ar.exception instanceof CommandException) {
1136 CommandException.Error error =
1137 ((CommandException) (ar.exception)).getCommandError();
1138 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1140 } else {
1141 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1142 }
1143 } else {
1144 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1145 }
1146 } else {
1147 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1148 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001149 }
sqian80370722020-01-29 15:02:51 -08001150 break;
Hall Liua1acea22020-09-18 19:04:59 -07001151 }
sqian80370722020-01-29 15:02:51 -08001152
Shishir Agrawal302c8692015-06-19 13:49:39 -07001153 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 CellNetworkScanResult cellScanResult;
1157 if (ar.exception == null && ar.result != null) {
1158 cellScanResult = new CellNetworkScanResult(
1159 CellNetworkScanResult.STATUS_SUCCESS,
1160 (List<OperatorInfo>) ar.result);
1161 } else {
1162 if (ar.result == null) {
1163 loge("getCellNetworkScanResults: Empty response");
1164 }
1165 if (ar.exception != null) {
1166 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1167 }
1168 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1169 if (ar.exception instanceof CommandException) {
1170 CommandException.Error error =
1171 ((CommandException) (ar.exception)).getCommandError();
1172 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1173 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1174 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1175 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1176 }
1177 }
1178 cellScanResult = new CellNetworkScanResult(errorCode, null);
1179 }
1180 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001181 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 break;
1183
1184 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1185 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001186 ManualNetworkSelectionArgument selArg =
1187 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001188 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1189 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001190 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1191 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001192 break;
1193
1194 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 if (ar.exception == null) {
1198 request.result = true;
1199 } else {
1200 request.result = false;
1201 loge("setNetworkSelectionModeManual " + ar.exception);
1202 }
1203 notifyRequester(request);
1204 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 break;
1206
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 case CMD_GET_MODEM_ACTIVITY_INFO:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001210 if (defaultPhone != null) {
1211 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001212 } else {
1213 ResultReceiver result = (ResultReceiver) request.argument;
1214 Bundle bundle = new Bundle();
1215 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1216 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1217 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001218 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 break;
1220
1221 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001224 ResultReceiver result = (ResultReceiver) request.argument;
1225
1226 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001228 // Update the last modem activity info and the result of the request.
1229 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1230 if (isModemActivityInfoValid(info)) {
1231 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1232 int[] txTimeMs = info.getTransmitTimeMillis();
1233 int[] lastModemTxTimeMs = mLastModemActivityInfo
1234 .getTransmitTimeMillis();
1235 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1236 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1237 }
1238 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1239 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1240 + mLastModemActivityInfo.getSleepTimeMillis());
1241 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1242 + mLastModemActivityInfo.getIdleTimeMillis());
1243 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1244 mLastModemActivityInfo.setReceiveTimeMillis(
1245 info.getReceiveTimeMillis()
1246 + mLastModemActivityInfo.getReceiveTimeMillis());
1247 }
1248 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1249 mLastModemActivityInfo.getSleepTimeMillis(),
1250 mLastModemActivityInfo.getIdleTimeMillis(),
1251 mLastModemActivityInfo.getTransmitTimeMillis(),
1252 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 } else {
1254 if (ar.result == null) {
1255 loge("queryModemActivityInfo: Empty response");
1256 } else if (ar.exception instanceof CommandException) {
1257 loge("queryModemActivityInfo: CommandException: " +
1258 ar.exception);
1259 } else {
1260 loge("queryModemActivityInfo: Unknown exception");
1261 }
1262 }
sqian1a1be542020-03-05 11:37:28 -08001263 Bundle bundle = new Bundle();
1264 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1265 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001266 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 break;
1268
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 case CMD_SET_ALLOWED_CARRIERS:
1270 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001271 CarrierRestrictionRules argument =
1272 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001274 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001275 break;
1276
1277 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
1280 if (ar.exception == null && ar.result != null) {
1281 request.result = ar.result;
1282 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001283 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1284 if (ar.exception instanceof CommandException) {
1285 loge("setAllowedCarriers: CommandException: " + ar.exception);
1286 CommandException.Error error =
1287 ((CommandException) (ar.exception)).getCommandError();
1288 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1289 request.result =
1290 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1291 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 } else {
1293 loge("setAllowedCarriers: Unknown exception");
1294 }
1295 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001296 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 break;
1298
1299 case CMD_GET_ALLOWED_CARRIERS:
1300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001302 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 break;
1304
1305 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 if (ar.exception == null && ar.result != null) {
1309 request.result = ar.result;
1310 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001311 request.result = new IllegalStateException(
1312 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001313 if (ar.result == null) {
1314 loge("getAllowedCarriers: Empty response");
1315 } else if (ar.exception instanceof CommandException) {
1316 loge("getAllowedCarriers: CommandException: " +
1317 ar.exception);
1318 } else {
1319 loge("getAllowedCarriers: Unknown exception");
1320 }
1321 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 break;
1324
Nathan Haroldb3014052017-01-25 15:57:32 -08001325 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null && ar.result != null) {
1329 request.result = ar.result;
1330 } else {
1331 request.result = new IllegalArgumentException(
1332 "Failed to retrieve Forbidden Plmns");
1333 if (ar.result == null) {
1334 loge("getForbiddenPlmns: Empty response");
1335 } else {
1336 loge("getForbiddenPlmns: Unknown exception");
1337 }
1338 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001339 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001340 break;
1341
1342 case CMD_GET_FORBIDDEN_PLMNS:
1343 request = (MainThreadRequest) msg.obj;
1344 uiccCard = getUiccCardFromRequest(request);
1345 if (uiccCard == null) {
1346 loge("getForbiddenPlmns() UiccCard is null");
1347 request.result = new IllegalArgumentException(
1348 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001349 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001350 break;
1351 }
1352 Integer appType = (Integer) request.argument;
1353 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1354 if (uiccApp == null) {
1355 loge("getForbiddenPlmns() no app with specified type -- "
1356 + appType);
1357 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001358 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001359 break;
1360 } else {
1361 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1362 + " specified type -- " + appType);
1363 }
1364 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1365 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1366 onCompleted);
1367 break;
1368
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001369 case CMD_SWITCH_SLOTS:
1370 request = (MainThreadRequest) msg.obj;
1371 int[] physicalSlots = (int[]) request.argument;
1372 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1373 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1374 break;
1375
1376 case EVENT_SWITCH_SLOTS_DONE:
1377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001380 notifyRequester(request);
1381 break;
1382 case CMD_GET_NETWORK_SELECTION_MODE:
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1385 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1386 break;
1387
1388 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 if (ar.exception != null) {
1392 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1393 } else {
1394 int mode = ((int[]) ar.result)[0];
1395 if (mode == 0) {
1396 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1397 } else {
1398 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1399 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001400 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001401 notifyRequester(request);
1402 break;
1403 case CMD_GET_CDMA_ROAMING_MODE:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1406 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1407 break;
1408 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception != null) {
1412 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1413 } else {
1414 request.result = ((int[]) ar.result)[0];
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_CDMA_ROAMING_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1421 int mode = (int) request.argument;
1422 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1423 break;
1424 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1425 ar = (AsyncResult) msg.obj;
1426 request = (MainThreadRequest) ar.userObj;
1427 request.result = ar.exception == null;
1428 notifyRequester(request);
1429 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001430 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1433 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1434 break;
1435 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
1438 if (ar.exception != null) {
1439 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1440 } else {
1441 request.result = ((int[]) ar.result)[0];
1442 }
1443 notifyRequester(request);
1444 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1448 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001449 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1450 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001451 break;
1452 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 request.result = ar.exception == null;
1456 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001457 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 case CMD_GET_ALL_CELL_INFO:
1459 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001461 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001462 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 case EVENT_GET_ALL_CELL_INFO_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001466 // If a timeout occurs, the response will be null
1467 request.result = (ar.exception == null && ar.result != null)
1468 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 synchronized (request) {
1470 request.notifyAll();
1471 }
1472 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001473 case CMD_REQUEST_CELL_INFO_UPDATE:
1474 request = (MainThreadRequest) msg.obj;
1475 request.phone.requestCellInfoUpdate(request.workSource,
1476 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1477 break;
1478 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1482 try {
1483 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001485 cb.onError(
1486 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1487 ar.exception.getClass().getName(),
1488 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001489 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001490 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001491 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001492 } else {
1493 // use the result as returned
1494 cb.onCellInfo((List<CellInfo>) ar.result);
1495 }
1496 } catch (RemoteException re) {
1497 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1498 }
1499 break;
Sarah Chincc055732020-11-18 13:39:35 -08001500 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 request = (MainThreadRequest) msg.obj;
1502 WorkSource ws = (WorkSource) request.argument;
1503 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001504 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 break;
Sarah Chincc055732020-11-18 13:39:35 -08001506 }
1507 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = ar.result;
1512 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001513 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001514 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001515 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001516 }
1517
1518 synchronized (request) {
1519 request.notifyAll();
1520 }
1521 break;
Sarah Chincc055732020-11-18 13:39:35 -08001522 }
chen xu6dac5ab2018-10-26 17:39:23 -07001523 case CMD_MODEM_REBOOT:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001526 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001527 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001528 case EVENT_CMD_MODEM_REBOOT_DONE:
1529 handleNullReturnEvent(msg, "rebootModem");
1530 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001531 case CMD_REQUEST_ENABLE_MODEM:
1532 request = (MainThreadRequest) msg.obj;
1533 boolean enable = (boolean) request.argument;
1534 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001535 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001536 PhoneConfigurationManager.getInstance()
1537 .enablePhone(request.phone, enable, onCompleted);
1538 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001539 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001543 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001544 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001545 if ((boolean) request.result) {
1546 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1547 updateModemStateMetrics();
1548 } else {
1549 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1550 + ar.exception);
1551 }
1552 notifyRequester(request);
1553 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001554 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001555 case CMD_GET_MODEM_STATUS:
1556 request = (MainThreadRequest) msg.obj;
1557 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1558 PhoneConfigurationManager.getInstance()
1559 .getPhoneStatusFromModem(request.phone, onCompleted);
1560 break;
1561 case EVENT_GET_MODEM_STATUS_DONE:
1562 ar = (AsyncResult) msg.obj;
1563 request = (MainThreadRequest) ar.userObj;
1564 int id = request.phone.getPhoneId();
1565 if (ar.exception == null && ar.result != null) {
1566 request.result = ar.result;
1567 //update the cache as modem status has changed
1568 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1569 (boolean) request.result);
1570 } else {
1571 // Return true if modem status cannot be retrieved. For most cases,
1572 // modem status is on. And for older version modems, GET_MODEM_STATUS
1573 // and disable modem are not supported. Modem is always on.
1574 // TODO: this should be fixed in R to support a third
1575 // status UNKNOWN b/131631629
1576 request.result = true;
1577 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1578 + ar.exception);
1579 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001580 notifyRequester(request);
1581 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001582 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1583 request = (MainThreadRequest) msg.obj;
1584 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1585 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1586 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1587 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1588 break;
1589 }
1590 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1594 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1595 args.second.accept(ar.exception == null);
1596 notifyRequester(request);
1597 break;
1598 }
Sarah Chincc055732020-11-18 13:39:35 -08001599 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1600 request = (MainThreadRequest) msg.obj;
1601 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1602 Phone phone = getPhoneFromRequest(request);
1603 if (phone != null) {
1604 phone.getSystemSelectionChannels(onCompleted);
1605 } else {
1606 loge("getSystemSelectionChannels: No phone object");
1607 request.result = new ArrayList<RadioAccessSpecifier>();
1608 notifyRequester(request);
1609 }
1610 break;
1611 }
1612 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1613 ar = (AsyncResult) msg.obj;
1614 request = (MainThreadRequest) ar.userObj;
1615 if (ar.exception == null && ar.result != null) {
1616 request.result = ar.result;
1617 } else {
1618 request.result = new IllegalArgumentException(
1619 "Failed to retrieve system selection channels");
1620 if (ar.result == null) {
1621 loge("getSystemSelectionChannels: Empty response");
1622 } else {
1623 loge("getSystemSelectionChannels: Unknown exception");
1624 }
1625 }
1626 notifyRequester(request);
1627 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001628 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception == null && ar.result != null) {
1632 request.result = ar.result;
1633 } else {
1634 request.result = -1;
1635 loge("Failed to set Forbidden Plmns");
1636 if (ar.result == null) {
1637 loge("setForbidenPlmns: Empty response");
1638 } else if (ar.exception != null) {
1639 loge("setForbiddenPlmns: Exception: " + ar.exception);
1640 request.result = -1;
1641 } else {
1642 loge("setForbiddenPlmns: Unknown exception");
1643 }
1644 }
1645 notifyRequester(request);
1646 break;
1647 case CMD_SET_FORBIDDEN_PLMNS:
1648 request = (MainThreadRequest) msg.obj;
1649 uiccCard = getUiccCardFromRequest(request);
1650 if (uiccCard == null) {
1651 loge("setForbiddenPlmns: UiccCard is null");
1652 request.result = -1;
1653 notifyRequester(request);
1654 break;
1655 }
1656 Pair<Integer, List<String>> setFplmnsArgs =
1657 (Pair<Integer, List<String>>) request.argument;
1658 appType = setFplmnsArgs.first;
1659 List<String> fplmns = setFplmnsArgs.second;
1660 uiccApp = uiccCard.getApplicationByType(appType);
1661 if (uiccApp == null) {
1662 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1663 request.result = -1;
1664 loge("Failed to get UICC App");
1665 notifyRequester(request);
1666 } else {
1667 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1668 ((SIMRecords) uiccApp.getIccRecords())
1669 .setForbiddenPlmns(onCompleted, fplmns);
1670 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001671 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001672 case CMD_ERASE_MODEM_CONFIG:
1673 request = (MainThreadRequest) msg.obj;
1674 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1675 defaultPhone.eraseModemConfig(onCompleted);
1676 break;
1677 case EVENT_ERASE_MODEM_CONFIG_DONE:
1678 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001679 break;
zoey chenf95ca592019-12-30 16:11:23 +08001680
1681 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1684 Pair<String, String> changed = (Pair<String, String>) request.argument;
1685 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1686 changed.first, changed.second, onCompleted);
1687 break;
1688 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception == null) {
1692 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001693 // If the operation is successful, update the PIN storage
1694 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1695 int phoneId = getPhoneFromRequest(request).getPhoneId();
1696 UiccController.getInstance().getPinStorage()
1697 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001698 } else {
1699 request.result = msg.arg1;
1700 }
1701 notifyRequester(request);
1702 break;
1703
Michele Berionned9fbae52020-11-13 02:36:59 +00001704 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1707 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1708 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1709 enabled.first, enabled.second, onCompleted);
1710 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001711 }
zoey chenf95ca592019-12-30 16:11:23 +08001712 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception == null) {
1716 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001717 // If the operation is successful, update the PIN storage
1718 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1719 int phoneId = getPhoneFromRequest(request).getPhoneId();
1720 if (enabled.first) {
1721 UiccController.getInstance().getPinStorage()
1722 .storePin(enabled.second, phoneId);
1723 } else {
1724 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1725 }
zoey chenf95ca592019-12-30 16:11:23 +08001726 } else {
1727 request.result = msg.arg1;
1728 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001729
1730
zoey chenf95ca592019-12-30 16:11:23 +08001731 notifyRequester(request);
1732 break;
1733
Peter Wangdafb9ac2020-01-15 14:13:38 -08001734 case MSG_NOTIFY_USER_ACTIVITY:
1735 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001736 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001737 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1738 getDefaultPhone().getContext().sendBroadcastAsUser(
1739 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1740 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001741
1742 case CMD_SET_DATA_THROTTLING: {
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1745 DataThrottlingRequest dataThrottlingRequest =
1746 (DataThrottlingRequest) request.argument;
1747 Phone phone = getPhoneFromRequest(request);
1748 if (phone != null) {
1749 phone.setDataThrottling(onCompleted,
1750 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1751 dataThrottlingRequest.getCompletionDurationMillis());
1752 } else {
1753 loge("setDataThrottling: No phone object");
1754 request.result =
1755 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1756 notifyRequester(request);
1757 }
1758
1759 break;
1760 }
1761 case EVENT_SET_DATA_THROTTLING_DONE:
1762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764
1765 if (ar.exception == null) {
1766 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1767 } else if (ar.exception instanceof CommandException) {
1768 loge("setDataThrottling: CommandException: " + ar.exception);
1769 CommandException.Error error =
1770 ((CommandException) (ar.exception)).getCommandError();
1771
1772 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1773 request.result = TelephonyManager
1774 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1775 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1776 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1777 } else {
1778 request.result =
1779 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1780 }
1781 } else {
1782 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1783 }
1784 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1785 notifyRequester(request);
1786 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001787
1788 case CMD_SET_SIM_POWER: {
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1791 request = (MainThreadRequest) msg.obj;
1792 int stateToSet =
1793 ((Pair<Integer, IIntegerConsumer>)
1794 request.argument).first;
1795 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1796 break;
1797 }
1798 case EVENT_SET_SIM_POWER_DONE: {
1799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801 IIntegerConsumer callback =
1802 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1803 if (ar.exception != null) {
1804 loge("setSimPower exception: " + ar.exception);
1805 int errorCode = TelephonyManager.CallForwardingInfoCallback
1806 .RESULT_ERROR_UNKNOWN;
1807 if (ar.exception instanceof CommandException) {
1808 CommandException.Error error =
1809 ((CommandException) (ar.exception)).getCommandError();
1810 if (error == CommandException.Error.SIM_ERR) {
1811 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1812 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1813 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1814 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1815 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1816 } else {
1817 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1818 }
1819 }
1820 try {
1821 callback.accept(errorCode);
1822 } catch (RemoteException e) {
1823 // Ignore if the remote process is no longer available to call back.
1824 Log.w(LOG_TAG, "setSimPower: callback not available.");
1825 }
1826 } else {
1827 try {
1828 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1829 } catch (RemoteException e) {
1830 // Ignore if the remote process is no longer available to call back.
1831 Log.w(LOG_TAG, "setSimPower: callback not available.");
1832 }
1833 }
1834 break;
1835 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001836 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1837 request = (MainThreadRequest) msg.obj;
1838
1839 final Phone phone = getPhoneFromRequest(request);
1840 if (phone == null || phone.getServiceStateTracker() == null) {
1841 request.result = new IllegalStateException("Phone or SST is null");
1842 notifyRequester(request);
1843 break;
1844 }
1845
1846 Pair<Integer, SignalStrengthUpdateRequest> pair =
1847 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1848 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1849 request);
1850 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1851 request.subId, pair.first /*callingUid*/,
1852 pair.second /*request*/, onCompleted);
1853 break;
1854 }
1855 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1856 ar = (AsyncResult) msg.obj;
1857 request = (MainThreadRequest) ar.userObj;
1858 // request.result will be the exception of ar if present, true otherwise.
1859 // Be cautious not to leave result null which will wait() forever
1860 request.result = ar.exception != null ? ar.exception : true;
1861 notifyRequester(request);
1862 break;
1863 }
1864 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1865 request = (MainThreadRequest) msg.obj;
1866
1867 Phone phone = getPhoneFromRequest(request);
1868 if (phone == null || phone.getServiceStateTracker() == null) {
1869 request.result = new IllegalStateException("Phone or SST is null");
1870 notifyRequester(request);
1871 break;
1872 }
1873
1874 Pair<Integer, SignalStrengthUpdateRequest> pair =
1875 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1876 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1877 request);
1878 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1879 request.subId, pair.first /*callingUid*/,
1880 pair.second /*request*/, onCompleted);
1881 break;
1882 }
1883 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 request.result = ar.exception != null ? ar.exception : true;
1887 notifyRequester(request);
1888 break;
1889 }
Jordan Liud5366d92020-11-24 14:50:34 -08001890
Michele Berionned9fbae52020-11-13 02:36:59 +00001891 case CMD_PREPARE_UNATTENDED_REBOOT:
1892 request = (MainThreadRequest) msg.obj;
1893 request.result =
1894 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1895 notifyRequester(request);
1896 break;
1897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 default:
1899 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1900 break;
1901 }
1902 }
Jake Hambye994d462014-02-03 13:10:13 -08001903
Pengquan Menga1bb6272018-09-06 09:59:22 -07001904 private void notifyRequester(MainThreadRequest request) {
1905 synchronized (request) {
1906 request.notifyAll();
1907 }
1908 }
1909
Jake Hambye994d462014-02-03 13:10:13 -08001910 private void handleNullReturnEvent(Message msg, String command) {
1911 AsyncResult ar = (AsyncResult) msg.obj;
1912 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1913 if (ar.exception == null) {
1914 request.result = true;
1915 } else {
1916 request.result = false;
1917 if (ar.exception instanceof CommandException) {
1918 loge(command + ": CommandException: " + ar.exception);
1919 } else {
1920 loge(command + ": Unknown exception");
1921 }
1922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001923 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
1927 /**
1928 * Posts the specified command to be executed on the main thread,
1929 * waits for the request to complete, and returns the result.
1930 * @see #sendRequestAsync
1931 */
1932 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001933 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1934 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001935 }
1936
1937 /**
1938 * Posts the specified command to be executed on the main thread,
1939 * waits for the request to complete, and returns the result.
1940 * @see #sendRequestAsync
1941 */
1942 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1943 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001944 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001945 }
1946
1947 /**
1948 * Posts the specified command to be executed on the main thread,
1949 * waits for the request to complete, and returns the result.
1950 * @see #sendRequestAsync
1951 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001952 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001953 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1954 }
1955
1956 /**
1957 * Posts the specified command to be executed on the main thread,
1958 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1959 * if not timeout or null otherwise.
1960 * @see #sendRequestAsync
1961 */
1962 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1963 long timeoutInMs) {
1964 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001965 }
1966
1967 /**
1968 * Posts the specified command to be executed on the main thread,
1969 * waits for the request to complete, and returns the result.
1970 * @see #sendRequestAsync
1971 */
Nathan Harold92bed182018-10-12 18:16:49 -07001972 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001973 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001974 }
1975
1976 /**
1977 * Posts the specified command to be executed on the main thread,
1978 * waits for the request to complete, and returns the result.
1979 * @see #sendRequestAsync
1980 */
1981 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001982 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1983 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001984 }
1985
1986 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001987 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1988 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1989 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001990 * @see #sendRequestAsync
1991 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001992 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1993 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1995 throw new RuntimeException("This method will deadlock if called from the main thread.");
1996 }
1997
Nathan Harold92bed182018-10-12 18:16:49 -07001998 MainThreadRequest request = null;
1999 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2000 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2001 } else if (phone != null) {
2002 request = new MainThreadRequest(argument, phone, workSource);
2003 } else {
2004 request = new MainThreadRequest(argument, subId, workSource);
2005 }
2006
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 Message msg = mMainThreadHandler.obtainMessage(command, request);
2008 msg.sendToTarget();
2009
Rambo Wang0f050d82021-02-12 11:43:36 -08002010
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 if (timeoutInMs >= 0) {
2013 // Wait for at least timeoutInMs before returning null request result
2014 long now = SystemClock.elapsedRealtime();
2015 long deadline = now + timeoutInMs;
2016 while (request == null && now < deadline) {
2017 try {
2018 request.wait(deadline - now);
2019 } catch (InterruptedException e) {
2020 // Do nothing, go back and check if request is completed or timeout
2021 } finally {
2022 now = SystemClock.elapsedRealtime();
2023 }
2024 }
2025 } else {
2026 // Wait for the request to complete
2027 while (request.result == null) {
2028 try {
2029 request.wait();
2030 } catch (InterruptedException e) {
2031 // Do nothing, go back and wait until the request is complete
2032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034 }
2035 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002036 if (request.result == null) {
2037 Log.wtf(LOG_TAG,
2038 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 return request.result;
2041 }
2042
2043 /**
2044 * Asynchronous ("fire and forget") version of sendRequest():
2045 * Posts the specified command to be executed on the main thread, and
2046 * returns immediately.
2047 * @see #sendRequest
2048 */
2049 private void sendRequestAsync(int command) {
2050 mMainThreadHandler.sendEmptyMessage(command);
2051 }
2052
2053 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002054 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002055 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002056 */
2057 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002058 sendRequestAsync(command, argument, null, null);
2059 }
2060
2061 /**
2062 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2063 * @see {@link #sendRequest(int,Object)}
2064 */
2065 private void sendRequestAsync(
2066 int command, Object argument, Phone phone, WorkSource workSource) {
2067 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002068 Message msg = mMainThreadHandler.obtainMessage(command, request);
2069 msg.sendToTarget();
2070 }
2071
2072 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 * Initialize the singleton PhoneInterfaceManager instance.
2074 * This is only done once, at startup, from PhoneApp.onCreate().
2075 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002076 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 synchronized (PhoneInterfaceManager.class) {
2078 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002079 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 } else {
2081 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2082 }
2083 return sInstance;
2084 }
2085 }
2086
2087 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002088 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002091 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002092 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2094 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002095 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002096 mTelephonySharedPreferences =
2097 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002098 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002099 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002100 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002101 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002102
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 publish();
2104 }
2105
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002106 private Phone getDefaultPhone() {
2107 Phone thePhone = getPhone(getDefaultSubscription());
2108 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2109 }
2110
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 private void publish() {
2112 if (DBG) log("publish: " + this);
2113
Peter Wangc035ce42020-01-08 21:00:22 -08002114 TelephonyFrameworkInitializer
2115 .getTelephonyServiceManager()
2116 .getTelephonyServiceRegisterer()
2117 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Stuart Scott584921c2015-01-15 17:10:34 -08002120 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002121 if (request.phone != null) {
2122 return request.phone;
2123 } else {
2124 return getPhoneFromSubId(request.subId);
2125 }
2126 }
2127
2128 private Phone getPhoneFromSubId(int subId) {
2129 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2130 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002131 }
2132
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002133 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2134 Phone phone = getPhoneFromRequest(request);
2135 return phone == null ? null :
2136 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2137 }
2138
Wink Saville36469e72014-06-11 15:17:00 -07002139 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002140 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002141 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002144 private void sendEraseModemConfig(Phone phone) {
2145 if (phone != null) {
2146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2147 mApp, phone.getSubId(), "eraseModemConfig");
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2151 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
2155 }
2156 }
2157
Peter Wang050bb052020-01-13 23:33:09 -08002158 private boolean isImsAvailableOnDevice() {
2159 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2160 if (pm == null) {
2161 // For some reason package manger is not available.. This will fail internally anyway,
2162 // so do not throw error and allow.
2163 return true;
2164 }
2165 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2166 }
2167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002169 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002170 }
2171
Wink Savilleb564aae2014-10-23 10:18:09 -07002172 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 if (DBG) log("dial: " + number);
2174 // No permission check needed here: This is just a wrapper around the
2175 // ACTION_DIAL intent, which is available to any app since it puts up
2176 // the UI before it does anything.
2177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 String url = createTelUrl(number);
2181 if (url == null) {
2182 return;
2183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185 // PENDING: should we just silently fail if phone is offhook or ringing?
2186 PhoneConstants.State state = mCM.getState(subId);
2187 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2188 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2189 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2190 mApp.startActivity(intent);
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195 }
2196
2197 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002198 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Wink Savilleb564aae2014-10-23 10:18:09 -07002201 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 if (DBG) log("call: " + number);
2203
2204 // This is just a wrapper around the ACTION_CALL intent, but we still
2205 // need to do a permission check since we're calling startActivity()
2206 // from the context of the phone app.
2207 enforceCallPermission();
2208
Jordan Liu1617b712019-07-10 15:06:26 -07002209 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 != AppOpsManager.MODE_ALLOWED) {
2211 return;
2212 }
2213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 String url = createTelUrl(number);
2217 if (url == null) {
2218 return;
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221 boolean isValid = false;
2222 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2223 if (slist != null) {
2224 for (SubscriptionInfo subInfoRecord : slist) {
2225 if (subInfoRecord.getSubscriptionId() == subId) {
2226 isValid = true;
2227 break;
2228 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002229 }
Wink Saville08874612014-08-31 19:19:58 -07002230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 if (!isValid) {
2232 return;
2233 }
Wink Saville08874612014-08-31 19:19:58 -07002234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2236 intent.putExtra(SUBSCRIPTION_KEY, subId);
2237 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2238 mApp.startActivity(intent);
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
2241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
Wink Savilleb564aae2014-10-23 10:18:09 -07002244 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002245 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002246 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2247 }
2248
Wink Savilleb564aae2014-10-23 10:18:09 -07002249 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002250 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002251 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2252 }
2253
Wink Savilleb564aae2014-10-23 10:18:09 -07002254 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002259 Phone phone = getPhone(subId);
2260 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 checkSimPin.start();
2262 return checkSimPin.unlockSim(null, pin);
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002273 Phone phone = getPhone(subId);
2274 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 checkSimPuk.start();
2276 return checkSimPuk.unlockSim(puk, pin);
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
2282 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002283 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 * a synchronous one.
2285 */
2286 private static class UnlockSim extends Thread {
2287
2288 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002289 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290
2291 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002292 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2293 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294
2295 // For replies from SimCard interface
2296 private Handler mHandler;
2297
2298 // For async handler to identify request type
2299 private static final int SUPPLY_PIN_COMPLETE = 100;
2300
Michele Berionned9fbae52020-11-13 02:36:59 +00002301 UnlockSim(int phoneId, IccCard simCard) {
2302 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 mSimCard = simCard;
2304 }
2305
2306 @Override
2307 public void run() {
2308 Looper.prepare();
2309 synchronized (UnlockSim.this) {
2310 mHandler = new Handler() {
2311 @Override
2312 public void handleMessage(Message msg) {
2313 AsyncResult ar = (AsyncResult) msg.obj;
2314 switch (msg.what) {
2315 case SUPPLY_PIN_COMPLETE:
2316 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2317 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002318 mRetryCount = msg.arg1;
2319 if (ar.exception != null) {
2320 if (ar.exception instanceof CommandException &&
2321 ((CommandException)(ar.exception)).getCommandError()
2322 == CommandException.Error.PASSWORD_INCORRECT) {
2323 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002324 } //When UiccCardApp dispose,handle message and return exception
2325 else if (ar.exception instanceof CommandException &&
2326 ((CommandException) (ar.exception)).getCommandError()
2327 == CommandException.Error.ABORTED) {
2328 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002329 } else {
2330 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2331 }
2332 } else {
2333 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mDone = true;
2336 UnlockSim.this.notifyAll();
2337 }
2338 break;
2339 }
2340 }
2341 };
2342 UnlockSim.this.notifyAll();
2343 }
2344 Looper.loop();
2345 }
2346
2347 /*
2348 * Use PIN or PUK to unlock SIM card
2349 *
2350 * If PUK is null, unlock SIM card with PIN
2351 *
2352 * If PUK is not null, unlock SIM card with PUK and set PIN code
2353 */
Wink Saville9de0f752013-10-22 19:04:03 -07002354 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355
2356 while (mHandler == null) {
2357 try {
2358 wait();
2359 } catch (InterruptedException e) {
2360 Thread.currentThread().interrupt();
2361 }
2362 }
2363 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2364
2365 if (puk == null) {
2366 mSimCard.supplyPin(pin, callback);
2367 } else {
2368 mSimCard.supplyPuk(puk, pin, callback);
2369 }
2370
2371 while (!mDone) {
2372 try {
2373 Log.d(LOG_TAG, "wait for done");
2374 wait();
2375 } catch (InterruptedException e) {
2376 // Restore the interrupted status
2377 Thread.currentThread().interrupt();
2378 }
2379 }
2380 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002381 int[] resultArray = new int[2];
2382 resultArray[0] = mResult;
2383 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002384
2385 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2386 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2387 }
2388
Wink Saville9de0f752013-10-22 19:04:03 -07002389 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391 }
2392
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002393 /**
2394 * This method has been removed due to privacy and stability concerns.
2395 */
2396 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002398 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2399 return;
Wink Saville36469e72014-06-11 15:17:00 -07002400 }
2401
Nathan Harold1f889d82020-06-04 17:05:26 -07002402 @Override
2403 public void updateServiceLocationWithPackageName(String callingPackage) {
2404 mApp.getSystemService(AppOpsManager.class)
2405 .checkPackage(Binder.getCallingUid(), callingPackage);
2406
Nathan Haroldf096d982020-11-18 17:18:06 -08002407 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002408 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2409 // Callers targeting S have no business invoking this method.
2410 return;
2411 }
2412
2413 LocationAccessPolicy.LocationPermissionResult locationResult =
2414 LocationAccessPolicy.checkLocationPermission(mApp,
2415 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2416 .setCallingPackage(callingPackage)
2417 .setCallingFeatureId(null)
2418 .setCallingPid(Binder.getCallingPid())
2419 .setCallingUid(Binder.getCallingUid())
2420 .setMethod("updateServiceLocation")
2421 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2422 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2423 .build());
2424 // Apps that lack location permission have no business calling this method;
2425 // however, because no permission was declared in the public API, denials must
2426 // all be "soft".
2427 switch (locationResult) {
2428 case DENIED_HARD: /* fall through */
2429 case DENIED_SOFT:
2430 return;
2431 }
2432
2433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002436 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002438 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002445 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 @Override
2447 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002448 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002449 }
2450
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002451
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002452 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002453 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2454 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2455 callingFeatureId);
2456 }
2457
2458 @Deprecated
2459 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002461 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2462 }
2463
2464 @Override
2465 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2466 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002468 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 return false;
2470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 return isRadioOnForSubscriber(subId);
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
2477 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 }
2479
2480 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 final Phone phone = getPhone(subId);
2484 if (phone != null) {
2485 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2486 } else {
2487 return false;
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493
2494 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002495 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
Wink Saville36469e72014-06-11 15:17:00 -07002497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 final Phone phone = getPhone(subId);
2504 if (phone != null) {
2505 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Wink Saville36469e72014-06-11 15:17:00 -07002510 }
2511
2512 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002513 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002514 }
2515
Wink Savilleb564aae2014-10-23 10:18:09 -07002516 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 final Phone phone = getPhone(subId);
2522 if (phone == null) {
2523 return false;
2524 }
2525 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2526 toggleRadioOnOffForSubscriber(subId);
2527 }
2528 return true;
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
Wink Saville36469e72014-06-11 15:17:00 -07002533
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002534 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002535 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002536 /*
2537 * If any of the Radios are available, it will need to be
2538 * shutdown. So return true if any Radio is available.
2539 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2543 Phone phone = PhoneFactory.getPhone(i);
2544 if (phone != null && phone.isRadioAvailable()) return true;
2545 }
2546 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2547 return false;
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002550 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002551 }
2552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002554 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 enforceModifyPermission();
2556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2560 logv("Shutting down Phone " + i);
2561 shutdownRadioUsingPhoneId(i);
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002565 }
2566 }
2567
2568 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002569 Phone phone = PhoneFactory.getPhone(phoneId);
2570 if (phone != null && phone.isRadioAvailable()) {
2571 phone.shutdownRadio();
2572 }
2573 }
2574
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2581 if (defaultPhone != null) {
2582 defaultPhone.setRadioPower(turnOn);
2583 return true;
2584 } else {
2585 loge("There's no default phone.");
2586 return false;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002590 }
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
Wink Savilleb564aae2014-10-23 10:18:09 -07002593 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 final Phone phone = getPhone(subId);
2599 if (phone != null) {
2600 phone.setRadioPower(turnOn);
2601 return true;
2602 } else {
2603 return false;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
Wink Saville36469e72014-06-11 15:17:00 -07002610 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 public boolean enableDataConnectivity() {
2613 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 int subId = mSubscriptionController.getDefaultDataSubId();
2618 final Phone phone = getPhone(subId);
2619 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002620 phone.getDataEnabledSettings().setDataEnabled(
2621 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 return true;
2623 } else {
2624 return false;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Wink Saville36469e72014-06-11 15:17:00 -07002631 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 public boolean disableDataConnectivity() {
2634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 int subId = mSubscriptionController.getDefaultDataSubId();
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002641 phone.getDataEnabledSettings().setDataEnabled(
2642 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 return true;
2644 } else {
2645 return false;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002653 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002658 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 } else {
2660 return false;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
2667 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002668 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002669 }
2670
pkanwarae03a6b2016-11-06 20:37:09 -08002671 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 enforceCallPermission();
2673
2674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2677 return;
2678 }
2679 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2680 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
pkanwar32d516d2016-10-14 19:37:38 -07002684 };
2685
Wink Savilleb564aae2014-10-23 10:18:09 -07002686 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2692 return false;
2693 }
2694 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002701 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002702 }
2703
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002704 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 Phone phone = PhoneFactory.getPhone(slotIndex);
2708 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2709 PhoneConstantConversions.convertCallState(phone.getState());
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 }
2714
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002716 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002717 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2718 }
2719
2720 @Override
2721 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002724 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 if (phone != null) {
2726 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2727 } else {
2728 return PhoneConstantConversions.convertDataState(
2729 PhoneConstants.DataState.DISCONNECTED);
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
2735
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002737 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002738 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2739 }
2740
2741 @Override
2742 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 final long identity = Binder.clearCallingIdentity();
2744 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 if (phone != null) {
2747 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2748 } else {
2749 return TelephonyManager.DATA_ACTIVITY_NONE;
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
2755
2756 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002757 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002759 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002760
2761 LocationAccessPolicy.LocationPermissionResult locationResult =
2762 LocationAccessPolicy.checkLocationPermission(mApp,
2763 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2764 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002765 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002766 .setCallingPid(Binder.getCallingPid())
2767 .setCallingUid(Binder.getCallingUid())
2768 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002769 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002770 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2771 .build());
2772 switch (locationResult) {
2773 case DENIED_HARD:
2774 throw new SecurityException("Not allowed to access cell location");
2775 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002776 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2777 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002784 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002785 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Svetoslav64fad262015-04-14 14:35:21 -07002789 }
2790
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 @Override
Jack Yu01425032020-02-22 19:38:58 -08002792 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002793 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2794 // registered cell info, so return a NULL country instead.
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002797 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2798 // Get default phone in this case.
2799 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2800 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002801 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002803 if (phone == null) return "";
2804 ServiceStateTracker sst = phone.getServiceStateTracker();
2805 if (sst == null) return "";
2806 LocaleTracker lt = sst.getLocaleTracker();
2807 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002808 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002812 }
2813
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002814 /**
2815 * This method was removed due to potential issues caused by performing partial
2816 * updates of service state, and lack of a credible use case.
2817 *
2818 * This has the ability to break the telephony implementation by disabling notification of
2819 * changes in device connectivity. DO NOT USE THIS!
2820 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 public void enableLocationUpdates() {
2823 mApp.enforceCallingOrSelfPermission(
2824 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 }
2826
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002827 /**
2828 * This method was removed due to potential issues caused by performing partial
2829 * updates of service state, and lack of a credible use case.
2830 *
2831 * This has the ability to break the telephony implementation by disabling notification of
2832 * changes in device connectivity. DO NOT USE THIS!
2833 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 @Override
2835 public void disableLocationUpdates() {
2836 mApp.enforceCallingOrSelfPermission(
2837 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
2840 @Override
2841 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002842 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2843 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002844 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002845 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2846 throw new SecurityException(
2847 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2848 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002849
Jordan Liu1617b712019-07-10 15:06:26 -07002850 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2852 return null;
2853 }
Svetoslav64fad262015-04-14 14:35:21 -07002854
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002855 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002857 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002858 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859
Nathan Haroldf180aac2018-06-01 18:43:55 -07002860 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2861 for (CellInfo ci : info) {
2862 if (ci instanceof CellInfoGsm) {
2863 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2864 } else if (ci instanceof CellInfoWcdma) {
2865 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002868 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002871 private List<CellInfo> getCachedCellInfo() {
2872 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2873 for (Phone phone : PhoneFactory.getPhones()) {
2874 List<CellInfo> info = phone.getAllCellInfo();
2875 if (info != null) cellInfos.addAll(info);
2876 }
2877 return cellInfos;
2878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879
2880 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002881 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002883 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002884
2885 LocationAccessPolicy.LocationPermissionResult locationResult =
2886 LocationAccessPolicy.checkLocationPermission(mApp,
2887 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2888 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002889 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002890 .setCallingPid(Binder.getCallingPid())
2891 .setCallingUid(Binder.getCallingUid())
2892 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002893 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002894 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2895 .build());
2896 switch (locationResult) {
2897 case DENIED_HARD:
2898 throw new SecurityException("Not allowed to access cell info");
2899 case DENIED_SOFT:
2900 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
Nathan Haroldf096d982020-11-18 17:18:06 -08002903 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002904 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2905 return getCachedCellInfo();
2906 }
2907
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002908 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002909 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2913 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002914 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002915 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 if (info != null) cellInfos.addAll(info);
2917 }
2918 return cellInfos;
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
2922 }
2923
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002924 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2926 String callingFeatureId) {
2927 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2928 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 }
2930
2931 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002932 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2933 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002934 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002935 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002936 }
2937
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002938 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2939 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002940 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002941 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002942
2943 LocationAccessPolicy.LocationPermissionResult locationResult =
2944 LocationAccessPolicy.checkLocationPermission(mApp,
2945 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2946 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002948 .setCallingPid(Binder.getCallingPid())
2949 .setCallingUid(Binder.getCallingUid())
2950 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002951 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2952 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002953 .build());
2954 switch (locationResult) {
2955 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002956 if (TelephonyPermissions
2957 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002958 // Safetynet logging for b/154934934
2959 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2960 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 throw new SecurityException("Not allowed to access cell info");
2962 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002963 if (TelephonyPermissions
2964 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002965 // Safetynet logging for b/154934934
2966 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2967 }
Nathan Harold5320c422019-05-09 10:26:08 -07002968 try {
2969 cb.onCellInfo(new ArrayList<CellInfo>());
2970 } catch (RemoteException re) {
2971 // Drop without consequences
2972 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002973 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002974 }
2975
Nathan Harolda939a962019-05-09 10:13:47 -07002976
2977 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002978 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2979
2980 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2981 }
2982
2983 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002985 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002994 }
2995
Shishir Agrawala9f32182016-04-12 12:00:16 -07002996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002998 Phone phone = PhoneFactory.getPhone(slotIndex);
2999 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003000 return null;
3001 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003002 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003003 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003004 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003005 return null;
3006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 return phone.getImei();
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003014 }
3015
3016 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003017 public String getTypeAllocationCodeForSlot(int slotIndex) {
3018 Phone phone = PhoneFactory.getPhone(slotIndex);
3019 String tac = null;
3020 if (phone != null) {
3021 String imei = phone.getImei();
3022 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3023 }
3024 return tac;
3025 }
3026
3027 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003028 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003029 Phone phone = PhoneFactory.getPhone(slotIndex);
3030 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003031 return null;
3032 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033
Jeff Davidson913390f2018-02-23 17:11:49 -08003034 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003035 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003036 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003037 return null;
3038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 return phone.getMeid();
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Jack Yu2af8d712017-03-15 17:14:14 -07003046 }
3047
3048 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003049 public String getManufacturerCodeForSlot(int slotIndex) {
3050 Phone phone = PhoneFactory.getPhone(slotIndex);
3051 String manufacturerCode = null;
3052 if (phone != null) {
3053 String meid = phone.getMeid();
3054 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3055 }
3056 return manufacturerCode;
3057 }
3058
3059 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003060 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3061 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003062 Phone phone = PhoneFactory.getPhone(slotIndex);
3063 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 return null;
3065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003066 int subId = phone.getSubId();
3067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003068 mApp, subId, callingPackage, callingFeatureId,
3069 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003070 return null;
3071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 return phone.getDeviceSvn();
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003079 }
3080
fionaxu43304da2017-11-27 22:51:16 -08003081 @Override
3082 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 final Phone phone = getPhone(subId);
3086 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
fionaxu43304da2017-11-27 22:51:16 -08003090 }
3091
3092 @Override
3093 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 return phone == null ? null : phone.getCarrierName();
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
fionaxu43304da2017-11-27 22:51:16 -08003101 }
3102
calvinpanffe225e2018-11-01 19:43:06 +08003103 @Override
chen xu0026ca62019-03-06 15:28:50 -08003104 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003109 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
3113 }
3114
3115 @Override
chen xu0026ca62019-03-06 15:28:50 -08003116 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003120 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
chen xu651eec72018-11-11 19:03:44 -08003126 @Override
chen xu864e11c2018-12-06 22:10:03 -08003127 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3128 if (!isSubscriptionMccMnc) {
3129 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3130 }
chen xu651eec72018-11-11 19:03:44 -08003131 final Phone phone = PhoneFactory.getPhone(slotIndex);
3132 if (phone == null) {
3133 return TelephonyManager.UNKNOWN_CARRIER_ID;
3134 }
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
3141 }
3142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 //
3144 // Internal helper methods.
3145 //
3146
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003147 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3149 *
3150 * @throws SecurityException if the caller does not have the required permission
3151 */
3152 private void enforceModifyPermission() {
3153 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3154 }
3155
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003156 /**
3157 * Make sure the caller is system.
3158 *
3159 * @throws SecurityException if the caller is not system.
3160 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003161 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003162 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3163 throw new SecurityException("Caller must be system");
3164 }
3165 }
3166
Shuo Qianf2b2df42019-11-13 17:43:31 -08003167 private void enforceActiveEmergencySessionPermission() {
3168 mApp.enforceCallingOrSelfPermission(
3169 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3170 }
3171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 /**
3173 * Make sure the caller has the CALL_PHONE permission.
3174 *
3175 * @throws SecurityException if the caller does not have the required permission
3176 */
3177 private void enforceCallPermission() {
3178 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3179 }
3180
paulhu423b5f22019-08-23 19:17:33 +08003181 private void enforceSettingsPermission() {
3182 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003183 }
3184
Michele Berionned9fbae52020-11-13 02:36:59 +00003185 private void enforceRebootPermission() {
3186 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3187 }
3188
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 private String createTelUrl(String number) {
3190 if (TextUtils.isEmpty(number)) {
3191 return null;
3192 }
3193
Jake Hambye994d462014-02-03 13:10:13 -08003194 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Ihab Awadf9e92732013-12-05 18:02:52 -08003197 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3199 }
3200
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003201 private static void logv(String msg) {
3202 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3203 }
3204
Ihab Awadf9e92732013-12-05 18:02:52 -08003205 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3207 }
3208
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003209 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003211 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003212 }
3213
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003215 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 final Phone phone = PhoneFactory.getPhone(slotIndex);
3219 if (phone == null) {
3220 return PhoneConstants.PHONE_TYPE_NONE;
3221 } else {
3222 return phone.getPhoneType();
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003227 }
3228
3229 /**
3230 * Returns the CDMA ERI icon index to display
3231 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003232 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003233 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3234 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3235 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003239 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3240 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003242 mApp, subId, callingPackage, callingFeatureId,
3243 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003244 return -1;
3245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 final Phone phone = getPhone(subId);
3250 if (phone != null) {
3251 return phone.getCdmaEriIconIndex();
3252 } else {
3253 return -1;
3254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 }
3259
3260 /**
3261 * Returns the CDMA ERI icon mode,
3262 * 0 - ON
3263 * 1 - FLASHING
3264 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003265 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003266 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3267 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3268 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003269 }
3270
Sanket Padawe356d7632015-06-22 14:03:32 -07003271 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003272 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3273 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003275 mApp, subId, callingPackage, callingFeatureId,
3276 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003277 return -1;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 final Phone phone = getPhone(subId);
3283 if (phone != null) {
3284 return phone.getCdmaEriIconMode();
3285 } else {
3286 return -1;
3287 }
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291 }
3292
3293 /**
3294 * Returns the CDMA ERI text,
3295 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003296 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003297 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3298 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3299 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003300 }
3301
Sanket Padawe356d7632015-06-22 14:03:32 -07003302 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003303 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3304 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003306 mApp, subId, callingPackage, callingFeatureId,
3307 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003308 return null;
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 final Phone phone = getPhone(subId);
3314 if (phone != null) {
3315 return phone.getCdmaEriText();
3316 } else {
3317 return null;
3318 }
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003322 }
3323
3324 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003325 * Returns the CDMA MDN.
3326 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003327 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003328 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 return phone.getLine1Number();
3337 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003338 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 return null;
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003343 }
3344 }
3345
3346 /**
3347 * Returns the CDMA MIN.
3348 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003350 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 final Phone phone = getPhone(subId);
3357 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3358 return phone.getCdmaMin();
3359 } else {
3360 return null;
3361 }
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003364 }
3365 }
3366
Hall Liud892bec2018-11-30 14:51:45 -08003367 @Override
3368 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3369 INumberVerificationCallback callback, String callingPackage) {
3370 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3371 != PERMISSION_GRANTED) {
3372 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3373 }
3374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3375
3376 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3377 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003378 throw new SecurityException("Calling package must be configured in the device config: "
3379 + "calling package: " + callingPackage
3380 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003381 }
3382
3383 if (range == null) {
3384 throw new NullPointerException("Range must be non-null");
3385 }
3386
3387 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003388 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003389
3390 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3391 }
3392
Junda Liuca05d5d2014-08-14 22:36:34 -07003393 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 * Returns true if CDMA provisioning needs to run.
3395 */
3396 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
3404
3405 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003406 * Sets the voice mail number of a given subId.
3407 */
3408 @Override
3409 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003410 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3411 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3416 new Pair<String, String>(alphaTag, number), new Integer(subId));
3417 return success;
3418 } finally {
3419 Binder.restoreCallingIdentity(identity);
3420 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003421 }
3422
Ta-wei Yen87c49842016-05-13 21:19:52 -07003423 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003424 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3425 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003426 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3427 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003428 if (!TextUtils.equals(callingPackage, systemDialer)) {
3429 throw new SecurityException("caller must be system dialer");
3430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003431
3432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3435 if (phoneAccountHandle == null) {
3436 return null;
3437 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003441 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003442 }
3443
3444 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003445 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3446 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003449 mApp, subId, callingPackage, callingFeatureId,
3450 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003451 return null;
3452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003454 final long identity = Binder.clearCallingIdentity();
3455 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003456 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003457 } finally {
3458 Binder.restoreCallingIdentity(identity);
3459 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003460 }
3461
3462 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003463 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3464 VisualVoicemailSmsFilterSettings settings) {
3465 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003470 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471 } finally {
3472 Binder.restoreCallingIdentity(identity);
3473 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003474 }
3475
3476 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003477 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003483 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003487 }
3488
3489 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003490 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3491 String callingPackage, int subId) {
3492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003497 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498 } finally {
3499 Binder.restoreCallingIdentity(identity);
3500 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003501 }
3502
3503 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003504 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003510 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003514 }
3515
3516 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003517 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3518 String callingAttributionTag, int subId, String number, int port, String text,
3519 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003521 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003522 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003523 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003524 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3525 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003526 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003527
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003528 /**
fionaxu0152e512016-11-14 13:36:14 -08003529 * Sets the voice activation state of a given subId.
3530 */
3531 @Override
3532 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3534 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 final Phone phone = getPhone(subId);
3539 if (phone != null) {
3540 phone.setVoiceActivationState(activationState);
3541 } else {
3542 loge("setVoiceActivationState fails with invalid subId: " + subId);
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003546 }
3547 }
3548
3549 /**
3550 * Sets the data activation state of a given subId.
3551 */
3552 @Override
3553 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3555 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = getPhone(subId);
3560 if (phone != null) {
3561 phone.setDataActivationState(activationState);
3562 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003563 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003567 }
3568 }
3569
3570 /**
3571 * Returns the voice activation state of a given subId.
3572 */
3573 @Override
3574 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
fionaxu0152e512016-11-14 13:36:14 -08003577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 if (phone != null) {
3581 return phone.getVoiceActivationState();
3582 } else {
3583 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003587 }
3588 }
3589
3590 /**
3591 * Returns the data activation state of a given subId.
3592 */
3593 @Override
3594 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
fionaxu0152e512016-11-14 13:36:14 -08003597 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 if (phone != null) {
3601 return phone.getDataActivationState();
3602 } else {
3603 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3604 }
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003607 }
3608 }
3609
3610 /**
Wink Saville36469e72014-06-11 15:17:00 -07003611 * Returns the unread count of voicemails for a subId
3612 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003613 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003614 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3615 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003617 mApp, subId, callingPackage, callingFeatureId,
3618 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003619 return 0;
3620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 final Phone phone = getPhone(subId);
3624 if (phone != null) {
3625 return phone.getVoiceMessageCount();
3626 } else {
3627 return 0;
3628 }
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 }
3633
3634 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003635 * returns true, if the device is in a state where both voice and data
3636 * are supported simultaneously. This can change based on location or network condition.
3637 */
3638 @Override
3639 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 final Phone phone = getPhone(subId);
3643 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003647 }
3648
3649 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003650 * Send the dialer code if called from the current default dialer or the caller has
3651 * carrier privilege.
3652 * @param inputCode The dialer code to send
3653 */
3654 @Override
3655 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003658 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3659 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003660 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003661 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
fionaxu235cc5e2017-03-06 22:25:57 -08003671 }
3672
Pengquan Menga1bb6272018-09-06 09:59:22 -07003673 @Override
3674 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003675 TelephonyPermissions
3676 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3677 mApp, subId, "getNetworkSelectionMode");
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 if (!isActiveSubscription(subId)) {
3681 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3682 }
3683 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003687 }
3688
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003690 public boolean isInEmergencySmsMode() {
3691 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 for (Phone phone : PhoneFactory.getPhones()) {
3695 if (phone.isInEmergencySmsMode()) {
3696 return true;
3697 }
3698 }
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 return false;
3703 }
3704
shilu366312e2019-12-17 09:28:10 -08003705 /**
3706 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3707 * @param subId The subscription to use to check the configuration.
3708 * @param c The callback that will be used to send the result.
3709 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003710 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003711 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3712 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003713 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3714 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003715
Brad Ebinger77b832e2019-10-17 17:03:22 -07003716 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3718 "IMS not available on device.");
3719 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 final long token = Binder.clearCallingIdentity();
3721 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(token);
3729 }
3730 }
3731
shilu366312e2019-12-17 09:28:10 -08003732 /**
3733 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3734 * @param subId The subscription to use to check the configuration.
3735 * @param c The callback that will be used to send the result.
3736 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003738 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003739 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3740 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3742 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3743 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003744 final long token = Binder.clearCallingIdentity();
3745 try {
3746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3747 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3748 .removeRegistrationCallbackForSubscription(c, subId);
3749 } catch (ImsException e) {
3750 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3751 + "is inactive, ignoring unregister.");
3752 // If the subscription is no longer active, just return, since the callback
3753 // will already have been removed internally.
3754 } finally {
3755 Binder.restoreCallingIdentity(token);
3756 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 }
3758
Brad Ebinger774ba362019-10-22 17:36:18 -07003759 /**
3760 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3761 */
3762 @Override
3763 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3764 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3765 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3766 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3767 "IMS not available on device.");
3768 }
3769 final long token = Binder.clearCallingIdentity();
3770 try {
3771 Phone phone = getPhone(subId);
3772 if (phone == null) {
3773 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3774 + subId + "'");
3775 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3776 }
3777 phone.getImsRegistrationState(regState -> {
3778 try {
3779 consumer.accept((regState == null)
3780 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3781 } catch (RemoteException e) {
3782 // Ignore if the remote process is no longer available to call back.
3783 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3784 }
3785 });
3786 } finally {
3787 Binder.restoreCallingIdentity(token);
3788 }
3789 }
3790
3791 /**
3792 * Get the transport type for the IMS service registration state.
3793 */
3794 @Override
3795 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003796 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3797 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003798 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3799 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3800 "IMS not available on device.");
3801 }
3802 final long token = Binder.clearCallingIdentity();
3803 try {
3804 Phone phone = getPhone(subId);
3805 if (phone == null) {
3806 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3807 + subId + "'");
3808 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3809 }
3810 phone.getImsRegistrationTech(regTech -> {
3811 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3812 int regTechConverted = (regTech == null)
3813 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3814 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3815 regTechConverted);
3816 try {
3817 consumer.accept(regTechConverted);
3818 } catch (RemoteException e) {
3819 // Ignore if the remote process is no longer available to call back.
3820 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3821 }
3822 });
3823 } finally {
3824 Binder.restoreCallingIdentity(token);
3825 }
3826 }
3827
shilu366312e2019-12-17 09:28:10 -08003828 /**
3829 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3830 * @param subId The subscription to use to check the configuration.
3831 * @param c The callback that will be used to send the result.
3832 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003834 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3835 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003836 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3837 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003838 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3839 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3840 "IMS not available on device.");
3841 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3843 final long token = Binder.clearCallingIdentity();
3844 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003845 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003847 } catch (ImsException e) {
3848 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 } finally {
3850 Binder.restoreCallingIdentity(token);
3851 }
3852 }
3853
shilu366312e2019-12-17 09:28:10 -08003854 /**
3855 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3856 * @param subId The subscription to use to check the configuration.
3857 * @param c The callback that will be used to send the result.
3858 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003860 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003861 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3862 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3864 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3865 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003866
3867 final long token = Binder.clearCallingIdentity();
3868 try {
3869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003871 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003872 } catch (ImsException e) {
3873 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3874 + "is inactive, ignoring unregister.");
3875 // If the subscription is no longer active, just return, since the callback
3876 // will already have been removed internally.
3877 } finally {
3878 Binder.restoreCallingIdentity(token);
3879 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 }
3881
3882 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003883 public boolean isCapable(int subId, int capability, int regTech) {
3884 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3886 final long token = Binder.clearCallingIdentity();
3887 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003890 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3892 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003893 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003894 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3895 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 } finally {
3897 Binder.restoreCallingIdentity(token);
3898 }
3899 }
3900
3901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003902 public boolean isAvailable(int subId, int capability, int regTech) {
3903 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 final long token = Binder.clearCallingIdentity();
3905 try {
3906 Phone phone = getPhone(subId);
3907 if (phone == null) return false;
3908 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003909 } catch (com.android.ims.ImsException e) {
3910 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3911 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 } finally {
3913 Binder.restoreCallingIdentity(token);
3914 }
3915 }
3916
Brad Ebinger77b832e2019-10-17 17:03:22 -07003917 /**
3918 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3919 * subscription.
3920 * @param subId The subscription to use to check the configuration.
3921 * @param callback The callback that will be used to send the result.
3922 * @param capability The MmTelFeature capability that will be used to send the result.
3923 * @param transportType The transport type of the MmTelFeature capability.
3924 */
3925 @Override
3926 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3927 int transportType) {
3928 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3929 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3931 "IMS not available on device.");
3932 }
3933 final long token = Binder.clearCallingIdentity();
3934 try {
3935 int slotId = getSlotIndex(subId);
3936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3937 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3938 + subId + "'");
3939 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3940 }
3941 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3942 transportType, aBoolean -> {
3943 try {
3944 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3945 } catch (RemoteException e) {
3946 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3947 + "running. Ignore");
3948 }
3949 });
3950 } finally {
3951 Binder.restoreCallingIdentity(token);
3952 }
3953 }
3954
shilu366312e2019-12-17 09:28:10 -08003955 /**
3956 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3957 * @param subId The subscription to use to check the configuration.
3958 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 @Override
3960 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003961 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3962 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003963
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3965 final long token = Binder.clearCallingIdentity();
3966 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003969 } catch (ImsException e) {
3970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 } finally {
3972 Binder.restoreCallingIdentity(token);
3973 }
3974 }
3975
3976 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003977 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003979 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003985 } catch (ImsException e) {
3986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
3990 }
3991
shilu366312e2019-12-17 09:28:10 -08003992 /**
3993 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3994 * @param subId The subscription to use to check the configuration.
3995 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003997 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003998 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3999 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004003 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4004 } catch (ImsException e) {
4005 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
4009 }
4010
4011 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004012 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004014 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004019 } catch (ImsException e) {
4020 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
4024 }
4025
shilu366312e2019-12-17 09:28:10 -08004026 /**
4027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4028 * @param subId The subscription to use to check the configuration.
4029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 @Override
4031 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004032 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4033 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004037 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
4044 }
4045
4046 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004047 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004049 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004053 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004054 } catch (ImsException e) {
4055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
4059 }
4060
shilu366312e2019-12-17 09:28:10 -08004061 /**
4062 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4063 * @param subId The subscription to use to check the configuration.
4064 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 @Override
4066 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004067 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4068 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004074 } catch (ImsException e) {
4075 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
4079 }
4080
4081 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004082 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004084 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004088 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004090 } catch (ImsException e) {
4091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
4095 }
4096
4097 @Override
4098 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4100 "setVoWiFiNonPersistent");
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004105 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004106 } catch (ImsException e) {
4107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112
shilu366312e2019-12-17 09:28:10 -08004113 /**
4114 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4115 * @param subId The subscription to use to check the configuration.
4116 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 @Override
4118 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004119 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4120 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004124 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 } catch (ImsException e) {
4127 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
4131 }
4132
4133 @Override
4134 public void setVoWiFiModeSetting(int subId, int mode) {
4135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4136 "setVoWiFiModeSetting");
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
4150 public int getVoWiFiRoamingModeSetting(int subId) {
4151 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004155 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004157 } catch (ImsException e) {
4158 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 }
4163
4164 @Override
4165 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4167 "setVoWiFiRoamingModeSetting");
4168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004171 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004172 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004173 } catch (ImsException e) {
4174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
4178 }
4179
4180 @Override
4181 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4183 "setRttCapabilityEnabled");
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4188 } catch (ImsException e) {
4189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
4193 }
4194
shilu366312e2019-12-17 09:28:10 -08004195 /**
4196 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4197 * @param subId The subscription to use to check the configuration.
4198 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 @Override
4200 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004201 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4202 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004206 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (ImsException e) {
4209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
4213 }
4214
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004215 @Override
4216 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4217 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004220 if (!isImsAvailableOnDevice()) {
4221 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4222 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004223 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004226 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
4232 }
4233
4234 @Override
4235 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4236 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4237 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004238 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4239 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4240 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004241 try {
4242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004243 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004244 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004245 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004246 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4247 + "is inactive, ignoring unregister.");
4248 // If the subscription is no longer active, just return, since the callback will already
4249 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
allenwtsu99c623b2020-01-03 18:24:23 +08004255
4256 private void checkModifyPhoneStatePermission(int subId, String message) {
4257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4258 message);
4259 }
4260
4261 private boolean isImsProvisioningRequired(int subId, int capability,
4262 boolean isMmtelCapability) {
4263 Phone phone = getPhone(subId);
4264 if (phone == null) {
4265 loge("phone instance null for subid " + subId);
4266 return false;
4267 }
4268 if (isMmtelCapability) {
4269 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4270 return false;
4271 }
4272 } else {
4273 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4274 return false;
4275 }
4276 }
4277 return true;
4278 }
4279
4280 @Override
4281 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4282 boolean isProvisioned) {
4283 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4284
4285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4288 if (!isImsProvisioningRequired(subId, capability, false)) {
4289 return;
4290 }
4291
4292 // this capability requires provisioning, route to the correct API.
4293 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4294 switch (capability) {
4295 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4296 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4297 ims.setEabProvisioned(isProvisioned);
4298 break;
4299 default: {
4300 throw new IllegalArgumentException("Tried to set provisioning for "
4301 + "rcs capability '" + capability + "', which does not require "
4302 + "provisioning.");
4303 }
4304 }
4305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308
4309 }
4310
4311
4312 @Override
4313 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4314 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4318 if (!isImsProvisioningRequired(subId, capability, false)) {
4319 return true;
4320 }
4321
4322 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4323 switch (capability) {
4324 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4325 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4326 return ims.isEabProvisionedOnDevice();
4327
4328 default: {
4329 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4330 + "capability '" + capability + "', which does not require "
4331 + "provisioning.");
4332 }
4333 }
4334
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
4338 }
4339
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004340 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4342 boolean isProvisioned) {
4343 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4344 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4345 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4346 }
allenwtsu99c623b2020-01-03 18:24:23 +08004347 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004351 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004352 return;
4353 }
4354
4355 // this capability requires provisioning, route to the correct API.
4356 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4357 switch (capability) {
4358 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4359 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4360 ims.setVolteProvisioned(isProvisioned);
4361 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4362 ims.setWfcProvisioned(isProvisioned);
4363 }
4364 break;
4365 }
4366 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4367 // There is currently no difference in VT provisioning type.
4368 ims.setVtProvisioned(isProvisioned);
4369 break;
4370 }
4371 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4372 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4373 // change the capability of the feature instead if needed.
4374 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4375 == isProvisioned) {
4376 // No change in provisioning.
4377 return;
4378 }
4379 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4380 try {
4381 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004382 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004383 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4384 + ", Exception" + e.getMessage());
4385 }
4386 break;
4387 }
4388 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004389 throw new IllegalArgumentException("Tried to set provisioning for "
4390 + "MmTel capability '" + capability + "', which does not require "
4391 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004392 }
4393 }
4394
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
4398 }
4399
4400 @Override
4401 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4402 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4403 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4404 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4405 }
4406 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004410 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004411 return true;
4412 }
4413
4414 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4415 switch (capability) {
4416 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4417 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4418 return ims.isVolteProvisionedOnDevice();
4419 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4420 return ims.isWfcProvisionedOnDevice();
4421 }
4422 // This should never happen, since we are checking tech above to make sure it
4423 // is either LTE or IWLAN.
4424 throw new IllegalArgumentException("Invalid radio technology for voice "
4425 + "capability.");
4426 }
4427 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4428 // There is currently no difference in VT provisioning type.
4429 return ims.isVtProvisionedOnDevice();
4430 }
4431 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4432 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4433 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4434 }
4435 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004436 throw new IllegalArgumentException(
4437 "Tried to get provisioning for MmTel capability '" + capability
4438 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004439 }
4440 }
4441
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
4445 }
4446
4447 @Override
4448 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4449 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4450 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4451 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4452 }
4453 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4454 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4455 return (provisionedBits & capability) > 0;
4456 }
4457
4458 @Override
4459 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4460 boolean isProvisioned) {
4461 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4462 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4463 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4464 }
4465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4466 "setProvisioningStatusForCapability");
4467 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4468 // If the current provisioning status for capability already matches isProvisioned,
4469 // do nothing.
4470 if (((provisionedBits & capability) > 0) == isProvisioned) {
4471 return;
4472 }
4473 if (isProvisioned) {
4474 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4475 } else {
4476 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4477 }
4478 }
4479
4480 /**
4481 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4482 * technology. The bitfield should mirror the bitfield defined by
4483 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4484 */
4485 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4486 String key = getMmTelProvisioningKey(subId, tech);
4487 // Default is no capabilities are provisioned.
4488 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4489 }
4490
4491 /**
4492 * Sets the MmTel capability provisioning bitfield (defined by
4493 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4494 * technology specified.
4495 *
4496 * Note: This is a synchronous command and should not be called on UI thread.
4497 */
4498 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4499 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4500 String key = getMmTelProvisioningKey(subId, tech);
4501 editor.putInt(key, newField);
4502 editor.commit();
4503 }
4504
4505 private static String getMmTelProvisioningKey(int subId, int tech) {
4506 // resulting key is provision_ims_mmtel_{subId}_{tech}
4507 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4508 }
4509
4510 /**
4511 * Query CarrierConfig to see if the specified capability requires provisioning for the
4512 * carrier associated with the subscription id.
4513 */
4514 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4515 int capability) {
4516 CarrierConfigManager configManager = new CarrierConfigManager(context);
4517 PersistableBundle c = configManager.getConfigForSubId(subId);
4518 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004519 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4521 false);
4522 boolean requireVoiceVtProvisioning = c.getBoolean(
4523 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4524
4525 // First check to make sure that the capability requires provisioning.
4526 switch (capability) {
4527 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4528 // intentional fallthrough
4529 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4530 if (requireVoiceVtProvisioning) {
4531 // Voice and Video requires provisioning
4532 return true;
4533 }
4534 break;
4535 }
4536 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4537 if (requireUtProvisioning) {
4538 // UT requires provisioning
4539 return true;
4540 }
4541 break;
4542 }
4543 }
4544 return false;
4545 }
4546
allenwtsu99c623b2020-01-03 18:24:23 +08004547 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4548 int capability) {
4549 CarrierConfigManager configManager = new CarrierConfigManager(context);
4550 PersistableBundle c = configManager.getConfigForSubId(subId);
4551
4552 boolean requireRcsProvisioning = c.getBoolean(
4553 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4554
4555 // First check to make sure that the capability requires provisioning.
4556 switch (capability) {
4557 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4558 // intentional fallthrough
4559 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4560 if (requireRcsProvisioning) {
4561 // OPTION or PRESENCE requires provisioning
4562 return true;
4563 }
4564 break;
4565 }
4566 }
4567 return false;
4568 }
4569
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004570 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004571 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4573 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4574 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004575 enforceReadPrivilegedPermission("getImsProvisioningInt");
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004579 int slotId = getSlotIndex(subId);
4580 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4581 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4582 + subId + "' for key:" + key);
4583 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4584 }
4585 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004586 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4588 + subId + "' for key:" + key);
4589 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
4593 }
4594
4595 @Override
4596 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4598 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4599 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 enforceReadPrivilegedPermission("getImsProvisioningString");
4601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004604 int slotId = getSlotIndex(subId);
4605 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4606 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4607 + subId + "' for key:" + key);
4608 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4609 }
4610 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004611 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004612 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4613 + subId + "' for key:" + key);
4614 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
4618 }
4619
4620 @Override
4621 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004622 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4623 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4624 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4626 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004627 final long identity = Binder.clearCallingIdentity();
4628 try {
4629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004630 int slotId = getSlotIndex(subId);
4631 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4632 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4633 + subId + "' for key:" + key);
4634 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4635 }
4636 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004637 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4639 + "' for key:" + key);
4640 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644 }
4645
4646 @Override
4647 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4649 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4650 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4652 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 int slotId = getSlotIndex(subId);
4657 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4658 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4659 + subId + "' for key:" + key);
4660 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4661 }
4662 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004663 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4665 + "' for key:" + key);
4666 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
4670 }
4671
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004672 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 int slotId = SubscriptionManager.getSlotIndex(subId);
4674 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004675 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4676 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004677 }
4678 return slotId;
4679 }
4680
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004681 private int getSlotIndex(int subId) {
4682 int slotId = SubscriptionManager.getSlotIndex(subId);
4683 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4684 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4685 }
4686 return slotId;
4687 }
4688
Wink Saville36469e72014-06-11 15:17:00 -07004689 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004690 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004691 */
4692 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004693 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4694 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004695 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004696 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004697 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004698 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004699 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004700 mApp, subId, callingPackage, callingFeatureId,
4701 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4703 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 final Phone phone = getPhone(subId);
4708 if (phone != null) {
4709 return phone.getServiceState().getDataNetworkType();
4710 } else {
4711 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004716 }
4717
4718 /**
4719 * Returns the data network type
4720 */
4721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004722 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4723 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4724 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004725 }
4726
4727 /**
4728 * Returns the data network type for a subId
4729 */
4730 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004731 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4732 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004734 mApp, subId, callingPackage, callingFeatureId,
4735 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004736 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4737 }
4738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 final Phone phone = getPhone(subId);
4742 if (phone != null) {
4743 return phone.getServiceState().getDataNetworkType();
4744 } else {
4745 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4746 }
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004750 }
4751
4752 /**
Wink Saville36469e72014-06-11 15:17:00 -07004753 * Returns the Voice network type for a subId
4754 */
4755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004756 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4757 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004759 mApp, subId, callingPackage, callingFeatureId,
4760 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004761 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4762 }
4763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 final Phone phone = getPhone(subId);
4767 if (phone != null) {
4768 return phone.getServiceState().getVoiceNetworkType();
4769 } else {
4770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4771 }
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004775 }
4776
4777 /**
4778 * @return true if a ICC card is present
4779 */
4780 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004781 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004782 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4783 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004784 }
4785
4786 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004787 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004788 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004789 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004790 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 final Phone phone = PhoneFactory.getPhone(slotIndex);
4794 if (phone != null) {
4795 return phone.getIccCard().hasIccCard();
4796 } else {
4797 return false;
4798 }
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004802 }
4803
4804 /**
4805 * Return if the current radio is LTE on CDMA. This
4806 * is a tri-state return value as for a period of time
4807 * the mode may be unknown.
4808 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004809 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004810 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004811 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004812 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004813 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004814 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4815 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4816 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004817 }
4818
Sanket Padawe356d7632015-06-22 14:03:32 -07004819 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004820 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4821 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004822 try {
4823 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4824 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004825 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4826 }
4827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 final Phone phone = getPhone(subId);
4831 if (phone == null) {
4832 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4833 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004834 return TelephonyProperties.lte_on_cdma_device()
4835 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 }
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004839 }
Wink Saville36469e72014-06-11 15:17:00 -07004840 }
4841
Wink Saville36469e72014-06-11 15:17:00 -07004842 /**
4843 * {@hide}
4844 * Returns Default subId, 0 in the case of single standby.
4845 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004846 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004847 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004848 }
4849
Shishir Agrawala9f32182016-04-12 12:00:16 -07004850 private int getSlotForDefaultSubscription() {
4851 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4852 }
4853
Wink Savilleb564aae2014-10-23 10:18:09 -07004854 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004855 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004856 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004857
Pengquan Menge92a50d2018-09-21 15:54:48 -07004858 private boolean isActiveSubscription(int subId) {
4859 return mSubscriptionController.isActiveSubId(subId);
4860 }
4861
Ihab Awadf2177b72013-11-25 13:33:23 -08004862 /**
4863 * @see android.telephony.TelephonyManager.WifiCallingChoices
4864 */
4865 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 final long identity = Binder.clearCallingIdentity();
4867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004868 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4870 getWhenToMakeWifiCallsDefaultPreference());
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004874 }
4875
4876 /**
4877 * @see android.telephony.TelephonyManager.WifiCallingChoices
4878 */
4879 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004888 }
4889
Sailesh Nepald1e68152013-12-12 19:08:02 -08004890 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004891 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004892 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004893 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004894
Jordan Liu4c733742019-02-28 12:03:40 -08004895 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4896 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4897 if (phoneId == -1) {
4898 throw new IllegalArgumentException("Given slot index: " + slotIndex
4899 + " does not correspond to an active phone");
4900 }
4901 return PhoneFactory.getPhone(phoneId);
4902 }
4903
Shishir Agrawal566b7612013-10-28 14:41:00 -07004904 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004905 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4906 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4908 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004910 if (DBG) {
4911 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4912 }
4913 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4914 p2);
4915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004916
Jordan Liu4c733742019-02-28 12:03:40 -08004917
4918 @Override
4919 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4920 int slotIndex, String callingPackage, String aid, int p2) {
4921 enforceModifyPermission();
4922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4923 if (DBG) {
4924 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4925 }
4926 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4927 callingPackage, aid, p2);
4928 }
4929
4930 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4931 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 if (TextUtils.equals(ISDR_AID, aid)) {
4935 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4937 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 if (bestComponent == null
4939 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4940 loge("The calling package is not allowed to access ISD-R.");
4941 throw new SecurityException(
4942 "The calling package is not allowed to access ISD-R.");
4943 }
Derek Tan740e1672017-06-27 14:56:27 -07004944 }
Derek Tan740e1672017-06-27 14:56:27 -07004945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004947 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4948 null /* workSource */);
4949 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 return response;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004954 }
4955
4956 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004957 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4959 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004960 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4961 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4962 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004963
Jordan Liu4c733742019-02-28 12:03:40 -08004964 @Override
4965 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4966 enforceModifyPermission();
4967 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4968 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4969 channel);
4970 }
4971
4972 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 final long identity = Binder.clearCallingIdentity();
4974 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 if (channel < 0) {
4976 return false;
4977 }
Jordan Liu4c733742019-02-28 12:03:40 -08004978 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4979 null /* workSource */);
4980 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981 return success;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985 }
4986
4987 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004988 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004989 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4991 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004992 if (DBG) {
4993 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4994 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4995 + p3 + " data=" + data);
4996 }
4997 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4998 command, p1, p2, p3, data);
4999 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005000
Jordan Liu4c733742019-02-28 12:03:40 -08005001 @Override
5002 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5003 int command, int p1, int p2, int p3, String data) {
5004 enforceModifyPermission();
5005 if (DBG) {
5006 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5007 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5008 + p3 + " data=" + data);
5009 }
5010 return iccTransmitApduLogicalChannelWithPermission(
5011 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5012 data);
5013 }
5014
5015 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5016 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 final long identity = Binder.clearCallingIdentity();
5018 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005019 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 return "";
5021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005024 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5025 null /* workSource */);
5026 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 // Append the returned status code to the end of the response payload.
5029 String s = Integer.toHexString(
5030 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5031 if (response.payload != null) {
5032 s = IccUtils.bytesToHexString(response.payload) + s;
5033 }
5034 return s;
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005038 }
Jake Hambye994d462014-02-03 13:10:13 -08005039
Evan Charltonc66da362014-05-16 14:06:40 -07005040 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005041 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5042 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5044 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005046 if (DBG) {
5047 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5048 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5049 }
5050 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5051 cla, command, p1, p2, p3, data);
5052 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005053
Jordan Liu4c733742019-02-28 12:03:40 -08005054 @Override
5055 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5056 int command, int p1, int p2, int p3, String data) {
5057 enforceModifyPermission();
5058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5059 if (DBG) {
5060 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5061 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5062 + " data=" + data);
5063 }
5064
5065 return iccTransmitApduBasicChannelWithPermission(
5066 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5067 p2, p3, data);
5068 }
5069
5070 // open APDU basic channel assuming the caller has sufficient permissions
5071 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5072 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5076 && TextUtils.equals(ISDR_AID, data)) {
5077 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005078 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5079 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 if (bestComponent == null
5081 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5082 loge("The calling package is not allowed to select ISD-R.");
5083 throw new SecurityException(
5084 "The calling package is not allowed to select ISD-R.");
5085 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005086 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005089 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5090 null /* workSource */);
5091 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 // Append the returned status code to the end of the response payload.
5094 String s = Integer.toHexString(
5095 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5096 if (response.payload != null) {
5097 s = IccUtils.bytesToHexString(response.payload) + s;
5098 }
5099 return s;
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005102 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005103 }
5104
5105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005106 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005107 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5109 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 if (DBG) {
5114 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5115 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5116 }
5117
5118 IccIoResult response =
5119 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5120 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5121 subId);
5122
5123 if (DBG) {
5124 log("Exchange SIM_IO [R]" + response);
5125 }
5126
5127 byte[] result = null;
5128 int length = 2;
5129 if (response.payload != null) {
5130 length = 2 + response.payload.length;
5131 result = new byte[length];
5132 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5133 } else {
5134 result = new byte[length];
5135 }
5136
5137 result[length - 1] = (byte) response.sw2;
5138 result[length - 2] = (byte) response.sw1;
5139 return result;
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005142 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005143 }
5144
Nathan Haroldb3014052017-01-25 15:57:32 -08005145 /**
5146 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5147 * on a particular subscription
5148 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005149 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5150 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005152 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005153 return null;
5154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155
5156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 if (appType != TelephonyManager.APPTYPE_USIM
5159 && appType != TelephonyManager.APPTYPE_SIM) {
5160 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5161 return null;
5162 }
5163 Object response = sendRequest(
5164 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5165 if (response instanceof String[]) {
5166 return (String[]) response;
5167 }
yincheng zhaod698b842019-09-06 17:06:54 -07005168 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005170 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005173 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005174 }
5175
yincheng zhaod698b842019-09-06 17:06:54 -07005176 /**
5177 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5178 * subscription.
5179 *
5180 * @param subId the id of the subscription.
5181 * @param appType the uicc app type, must be USIM or SIM.
5182 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5183 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005184 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005185 * @return number of fplmns that is successfully written to the SIM.
5186 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005187 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5188 String callingFeatureId) {
5189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5190 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005191 if (DBG) logv("no permissions for setForbiddenplmns");
5192 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5193 }
5194 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5195 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5196 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5197 }
5198 if (fplmns == null) {
5199 throw new IllegalArgumentException("Fplmn List provided is null");
5200 }
5201 for (String fplmn : fplmns) {
5202 if (!CellIdentity.isValidPlmn(fplmn)) {
5203 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5204 }
5205 }
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
5208 Object response = sendRequest(
5209 CMD_SET_FORBIDDEN_PLMNS,
5210 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5211 subId);
5212 return (int) response;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005219 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5221 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5226 if (response.payload == null) {
5227 return "";
5228 }
Evan Charltonc66da362014-05-16 14:06:40 -07005229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 // Append the returned status code to the end of the response payload.
5231 String s = Integer.toHexString(
5232 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5233 s = IccUtils.bytesToHexString(response.payload) + s;
5234 return s;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Evan Charltonc66da362014-05-16 14:06:40 -07005238 }
5239
Jake Hambye994d462014-02-03 13:10:13 -08005240 /**
5241 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5242 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5243 *
5244 * @param itemID the ID of the item to read
5245 * @return the NV item as a String, or null on error.
5246 */
5247 @Override
5248 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005256 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5258 return value;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Jake Hambye994d462014-02-03 13:10:13 -08005262 }
5263
5264 /**
5265 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5266 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5267 *
5268 * @param itemID the ID of the item to read
5269 * @param itemValue the value to write, as a String
5270 * @return true on success; false on any failure
5271 */
5272 @Override
5273 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5281 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005282 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5284 return success;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Jake Hambye994d462014-02-03 13:10:13 -08005288 }
5289
5290 /**
5291 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5292 * Used for device configuration by some CDMA operators.
5293 *
5294 * @param preferredRoamingList byte array containing the new PRL
5295 * @return true on success; false on any failure
5296 */
5297 @Override
5298 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5305 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5306 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5307 return success;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
Jake Hambye994d462014-02-03 13:10:13 -08005311 }
5312
5313 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005314 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005315 * Used for device configuration by some CDMA operators.
5316 *
chen xu6dac5ab2018-10-26 17:39:23 -07005317 * @param slotIndex - device slot.
5318 *
Jake Hambye994d462014-02-03 13:10:13 -08005319 * @return true on success; false on any failure
5320 */
5321 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005322 public boolean resetModemConfig(int slotIndex) {
5323 Phone phone = PhoneFactory.getPhone(slotIndex);
5324 if (phone != null) {
5325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5326 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327
chen xu6dac5ab2018-10-26 17:39:23 -07005328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5331 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5332 return success;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 }
chen xu6dac5ab2018-10-26 17:39:23 -07005337 return false;
5338 }
5339
5340 /**
5341 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5342 *
5343 * @param slotIndex - device slot.
5344 *
5345 * @return true on success; false on any failure
5346 */
5347 @Override
5348 public boolean rebootModem(int slotIndex) {
5349 Phone phone = PhoneFactory.getPhone(slotIndex);
5350 if (phone != null) {
5351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5352 mApp, phone.getSubId(), "rebootModem");
5353
5354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5357 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5358 return success;
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
5362 }
5363 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005364 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005365
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005366 public String[] getPcscfAddress(String apnType, String callingPackage,
5367 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005368 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5370 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005371 return new String[0];
5372 }
5373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005376 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
Wink Saville36469e72014-06-11 15:17:00 -07005380 }
5381
Brad Ebinger51f743a2017-01-23 13:50:20 -08005382 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005383 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5384 * {@link #disableIms(int)}.
5385 * @param slotIndex device slot.
5386 */
5387 public void resetIms(int slotIndex) {
5388 enforceModifyPermission();
5389
5390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 if (mImsResolver == null) {
5393 // may happen if the does not support IMS.
5394 return;
5395 }
5396 mImsResolver.disableIms(slotIndex);
5397 mImsResolver.enableIms(slotIndex);
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
5401 }
5402
5403 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005404 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5405 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005406 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005407 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005408 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409
5410 final long identity = Binder.clearCallingIdentity();
5411 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005412 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005413 // may happen if the device does not support IMS.
5414 return;
5415 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005416 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005420 }
5421
5422 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005423 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5424 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005425 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005426 public void disableIms(int slotId) {
5427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005431 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005432 // may happen if the device does not support IMS.
5433 return;
5434 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005435 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005439 }
5440
5441 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005442 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5443 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005444 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005445 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005446 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005447 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448
5449 final long identity = Binder.clearCallingIdentity();
5450 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005451 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005452 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5453 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005454 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005455 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005459 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005460 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005461 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5462 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005463 @Override
5464 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005465 enforceModifyPermission();
5466
5467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005470 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
5474 }
5475
5476 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005477 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005478 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005479 */
5480 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005485 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005486 // may happen if the device does not support IMS.
5487 return null;
5488 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005489 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 } finally {
5491 Binder.restoreCallingIdentity(identity);
5492 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005493 }
5494
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005495 /**
5496 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005497 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005498 */
5499 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005504 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005505 // may happen if the device does not support IMS.
5506 return null;
5507 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005508 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005512 }
5513
Brad Ebinger884c07b2018-02-15 16:17:40 -08005514 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005515 * Sets the ImsService Package Name that Telephony will bind to.
5516 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005517 * @param slotIndex the slot ID that the ImsService should bind for.
5518 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005519 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005520 * @param featureTypes An integer array of feature types associated with a packageName.
5521 * @param packageName The name of the package that the current configuration will be replaced
5522 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005523 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005524 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5526 int[] featureTypes, String packageName) {
5527 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5528 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5530 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005531 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 final long identity = Binder.clearCallingIdentity();
5534 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005535 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005536 // may happen if the device does not support IMS.
5537 return false;
5538 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005539 Map<Integer, String> featureConfig = new HashMap<>();
5540 for (int featureType : featureTypes) {
5541 featureConfig.put(featureType, packageName);
5542 }
5543 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5544 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005548 }
5549
5550 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005551 * Clears any carrier ImsService overrides for the slot index specified that were previously
5552 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5553 *
5554 * This should only be used for testing.
5555 *
5556 * @param slotIndex the slot ID that the ImsService should bind for.
5557 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5558 */
5559 @Override
5560 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5561 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5562 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5563 "clearCarrierImsServiceOverride");
5564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5565 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5566 "clearCarrierImsServiceOverride");
5567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 if (mImsResolver == null) {
5571 // may happen if the device does not support IMS.
5572 return false;
5573 }
5574 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
5578 }
5579
5580 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005581 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005582 *
5583 * @param slotId The slot that the ImsService is associated with.
5584 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5585 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005586 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005587 * @return the package name of the ImsService configuration.
5588 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005589 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5590 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005591 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005592 TelephonyPermissions
5593 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5594 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5595 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 final long identity = Binder.clearCallingIdentity();
5598 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005600 // may happen if the device does not support IMS.
5601 return "";
5602 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005603 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005604 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5605 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005609 }
5610
Brad Ebinger77b832e2019-10-17 17:03:22 -07005611 /**
5612 * Get the MmTelFeature state associated with the requested subscription id.
5613 * @param subId The subscription that the MmTelFeature is associated with.
5614 * @param callback A callback with an integer containing the
5615 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5616 */
5617 @Override
5618 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5619 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5620 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5621 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5622 "IMS not available on device.");
5623 }
5624 final long token = Binder.clearCallingIdentity();
5625 try {
5626 int slotId = getSlotIndex(subId);
5627 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5628 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5629 + subId + "'");
5630 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5631 }
5632 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5633 try {
5634 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5635 } catch (RemoteException e) {
5636 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5637 + "Ignore");
5638 }
5639 });
5640 } finally {
5641 Binder.restoreCallingIdentity(token);
5642 }
5643 }
5644
Daniel Brightbb5840b2021-01-12 15:48:18 -08005645 /**
5646 * Sets the ims registration state on all valid {@link Phone}s.
5647 */
5648 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005653 // NOTE: Before S, this method only set the default phone.
5654 for (final Phone phone : PhoneFactory.getPhones()) {
5655 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5656 phone.setImsRegistrationState(registered);
5657 }
5658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Wink Saville36469e72014-06-11 15:17:00 -07005662 }
5663
5664 /**
Stuart Scott54788802015-03-30 13:18:01 -07005665 * Set the network selection mode to automatic.
5666 *
5667 */
5668 @Override
5669 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5671 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
shilufc958392020-01-20 11:36:01 -08005675 if (!isActiveSubscription(subId)) {
5676 return;
5677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005679 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5680 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Stuart Scott54788802015-03-30 13:18:01 -07005684 }
5685
Jack Yud10cdd42020-09-28 20:28:01 -07005686 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005687 * Ask the radio to connect to the input network and change selection mode to manual.
5688 *
5689 * @param subId the id of the subscription.
5690 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5691 * the operator to attach to.
5692 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5693 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5694 * normal network selection next time.
5695 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005696 */
5697 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005698 public boolean setNetworkSelectionModeManual(
5699 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5701 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005702
5703 if (!isActiveSubscription(subId)) {
5704 return false;
5705 }
5706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 final long identity = Binder.clearCallingIdentity();
5708 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005709 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005711 if (DBG) {
5712 log("setNetworkSelectionModeManual: subId: " + subId
5713 + " operator: " + operatorInfo);
5714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005719 }
shilu84f6e8b2019-12-19 13:58:01 -08005720 /**
5721 * Get the manual network selection
5722 *
5723 * @param subId the id of the subscription.
5724 *
5725 * @return the previously saved user selected PLMN
5726 */
5727 @Override
5728 public String getManualNetworkSelectionPlmn(int subId) {
5729 TelephonyPermissions
5730 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5731 mApp, subId, "getManualNetworkSelectionPlmn");
5732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 if (!isActiveSubscription(subId)) {
5736 return "";
5737 }
5738
5739 final Phone phone = getPhone(subId);
5740 if (phone == null) {
5741 return "";
5742 }
5743 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5744 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5745 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005750
5751 /**
5752 * Scans for available networks.
5753 */
5754 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005755 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5758 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005759 LocationAccessPolicy.LocationPermissionResult locationResult =
5760 LocationAccessPolicy.checkLocationPermission(mApp,
5761 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5762 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005763 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005764 .setCallingPid(Binder.getCallingPid())
5765 .setCallingUid(Binder.getCallingUid())
5766 .setMethod("getCellNetworkScanResults")
5767 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5768 .build());
5769 switch (locationResult) {
5770 case DENIED_HARD:
5771 throw new SecurityException("Not allowed to access scan results -- location");
5772 case DENIED_SOFT:
5773 return null;
5774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775
Pengquan Menga1bb6272018-09-06 09:59:22 -07005776 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 try {
5778 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005779 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005784 }
5785
5786 /**
sqian80370722020-01-29 15:02:51 -08005787 * Get the call forwarding info, given the call forwarding reason.
5788 */
5789 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005790 public void getCallForwarding(int subId, int callForwardingReason,
5791 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005792 enforceReadPrivilegedPermission("getCallForwarding");
5793 long identity = Binder.clearCallingIdentity();
5794 try {
5795 if (DBG) {
5796 log("getCallForwarding: subId " + subId
5797 + " callForwardingReason" + callForwardingReason);
5798 }
Hall Liua1acea22020-09-18 19:04:59 -07005799
5800 Phone phone = getPhone(subId);
5801 if (phone == null) {
5802 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005803 callback.onError(
5804 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005805 } catch (RemoteException e) {
5806 // ignore
5807 }
5808 return;
5809 }
5810
5811 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5812 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5813 @Override
5814 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5815 try {
5816 callback.onCallForwardingInfoAvailable(info);
5817 } catch (RemoteException e) {
5818 // ignore
5819 }
5820 }
5821
5822 @Override
5823 public void onError(int error) {
5824 try {
5825 callback.onError(error);
5826 } catch (RemoteException e) {
5827 // ignore
5828 }
5829 }
5830 });
5831 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
5835 }
5836
5837 /**
5838 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5839 * reason, the number to forward, and the timeout before the forwarding is attempted.
5840 */
5841 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005842 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5843 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005844 enforceModifyPermission();
5845 long identity = Binder.clearCallingIdentity();
5846 try {
5847 if (DBG) {
5848 log("setCallForwarding: subId " + subId
5849 + " callForwardingInfo" + callForwardingInfo);
5850 }
Hall Liua1acea22020-09-18 19:04:59 -07005851
5852 Phone phone = getPhone(subId);
5853 if (phone == null) {
5854 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005855 callback.accept(
5856 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005857 } catch (RemoteException e) {
5858 // ignore
5859 }
5860 return;
5861 }
5862
5863 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5864 FunctionalUtils.ignoreRemoteException(callback::accept));
5865
5866 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
5870 }
5871
5872 /**
Hall Liua1acea22020-09-18 19:04:59 -07005873 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005874 */
5875 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005876 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005877 enforceReadPrivilegedPermission("getCallForwarding");
5878 long identity = Binder.clearCallingIdentity();
5879 try {
Hall Liua1acea22020-09-18 19:04:59 -07005880
5881 Phone phone = getPhone(subId);
5882 if (phone == null) {
5883 try {
5884 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5885 } catch (RemoteException e) {
5886 // ignore
5887 }
5888 return;
5889 }
5890
5891 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5892
sqian80370722020-01-29 15:02:51 -08005893 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005894 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
5898 }
5899
5900 /**
Hall Liua1acea22020-09-18 19:04:59 -07005901 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005902 */
5903 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005904 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005905 enforceModifyPermission();
5906 long identity = Binder.clearCallingIdentity();
5907 try {
Hall Liua1acea22020-09-18 19:04:59 -07005908 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5909
5910 Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 try {
5913 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5914 } catch (RemoteException e) {
5915 // ignore
5916 }
5917 return;
5918 }
5919
5920 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5921 FunctionalUtils.ignoreRemoteException(callback::accept));
5922
5923 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 /**
yinxub1bed742017-04-17 11:45:04 -07005930 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005931 *
yinxub1bed742017-04-17 11:45:04 -07005932 * @param subId id of the subscription
5933 * @param request contains the radio access networks with bands/channels to scan
5934 * @param messenger callback messenger for scan results or errors
5935 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005936 * @return the id of the requested scan which can be used to stop the scan.
5937 */
5938 @Override
5939 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005940 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5942 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005943 LocationAccessPolicy.LocationPermissionResult locationResult =
5944 LocationAccessPolicy.checkLocationPermission(mApp,
5945 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5946 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005947 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005948 .setCallingPid(Binder.getCallingPid())
5949 .setCallingUid(Binder.getCallingUid())
5950 .setMethod("requestNetworkScan")
5951 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5952 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005953 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005954 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5955 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005956 if (e != null) {
5957 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5958 throw e;
5959 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005960 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005961 return TelephonyScanManager.INVALID_SCAN_ID;
5962 }
5963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 }
Hall Liu912dfd32019-04-25 14:02:26 -07005965 int callingUid = Binder.getCallingUid();
5966 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005967 final long identity = Binder.clearCallingIdentity();
5968 try {
5969 return mNetworkScanRequestTracker.startNetworkScan(
5970 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005971 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
yinxu504e1392017-04-12 16:03:22 -07005975 }
5976
Hall Liub2ac8ef2019-02-28 15:56:23 -08005977 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005978 NetworkScanRequest request, int subId, String callingPackage) {
5979 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005980 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5981 boolean hasNetworkScanPermission =
5982 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5983 == PERMISSION_GRANTED;
5984
5985 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5986 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5987 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005988 }
5989
5990 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5991 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005992 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5993 return new SecurityException("Specific channels must not be"
5994 + " scanned without location access.");
5995 }
5996 }
5997 }
5998
Hall Liub2ac8ef2019-02-28 15:56:23 -08005999 return null;
6000 }
6001
yinxu504e1392017-04-12 16:03:22 -07006002 /**
6003 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006004 *
6005 * @param subId id of the subscription
6006 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006007 */
6008 @Override
6009 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6011 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
Hall Liu912dfd32019-04-25 14:02:26 -07006013 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final long identity = Binder.clearCallingIdentity();
6015 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006016 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
yinxu504e1392017-04-12 16:03:22 -07006020 }
6021
6022 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006023 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006024 *
SongFerngWang9e060372020-12-21 16:41:52 +08006025 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006026 */
6027 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006028 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006029 TelephonyPermissions
6030 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006031 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032
6033 final long identity = Binder.clearCallingIdentity();
6034 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006035 if (DBG) log("getAllowedNetworkTypesBitmask");
6036 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6037 int networkTypesBitmask = (result != null ? result[0] : -1);
6038 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6039 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006043 }
6044
6045 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006046 * Get the allowed network types for certain reason.
6047 *
6048 * @param subId the id of the subscription.
6049 * @param reason the reason the allowed network type change is taking place
6050 * @return the allowed network types.
6051 */
6052 @Override
6053 public long getAllowedNetworkTypesForReason(int subId,
6054 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6055 TelephonyPermissions
6056 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6057 mApp, subId, "getAllowedNetworkTypesForReason");
6058 final long identity = Binder.clearCallingIdentity();
6059 try {
6060 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
6064 }
6065
6066 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006067 * Enable/Disable E-UTRA-NR Dual Connectivity
6068 * @param subId subscription id of the sim card
6069 * @param nrDualConnectivityState expected NR dual connectivity state
6070 * This can be passed following states
6071 * <ol>
6072 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6073 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6074 * <li>Disable NR dual connectivity and force secondary cell to be released
6075 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6076 * </ol>
6077 * @return operation result.
6078 */
6079 @Override
6080 public int setNrDualConnectivityState(int subId,
6081 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6083 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006084 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006085 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6086 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6087 }
6088
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
6092 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6093 nrDualConnectivityState, subId,
6094 workSource);
6095 if (DBG) log("enableNRDualConnectivity result: " + result);
6096 return result;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
6100 }
6101
6102 /**
6103 * Is E-UTRA-NR Dual Connectivity enabled
6104 * @return true if dual connectivity is enabled else false
6105 */
6106 @Override
6107 public boolean isNrDualConnectivityEnabled(int subId) {
6108 TelephonyPermissions
6109 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6110 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006111 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006112 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6113 return false;
6114 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6116 final long identity = Binder.clearCallingIdentity();
6117 try {
6118 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6119 null, subId, workSource);
6120 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6121 return isEnabled;
6122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
6125 }
6126
6127 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006128 * get carrier bandwidth per primary and secondary carrier
6129 * @param subId subscription id of the sim card
6130 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6131 */
6132 @Override
6133 public CarrierBandwidth getCarrierBandwidth(int subId) {
6134 TelephonyPermissions
6135 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6136 mApp, subId, "isNRDualConnectivityEnabled");
6137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 CarrierBandwidth carrierBandwidth =
6141 getPhoneFromSubId(subId).getCarrierBandwidth();
6142 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6143 return carrierBandwidth;
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
6147 }
6148
6149 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006150 * Set the allowed network types of the device and
6151 * provide the reason triggering the allowed network change.
6152 *
6153 * @param subId the id of the subscription.
6154 * @param reason the reason the allowed network type change is taking place
6155 * @param allowedNetworkTypes the allowed network types.
6156 * @return true on success; false on any failure.
6157 */
6158 @Override
6159 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006160 @TelephonyManager.AllowedNetworkTypesReason int reason,
6161 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6163 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006164 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6165 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6166 return false;
6167 }
6168
6169 if (DBG) {
6170 log("setAllowedNetworkTypesForReason: " + reason
6171 + " value: " + allowedNetworkTypes);
6172 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006173 final long identity = Binder.clearCallingIdentity();
6174 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006175 Boolean success = (Boolean) sendRequest(
6176 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6177 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6178
6179 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6180 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006181 } finally {
6182 Binder.restoreCallingIdentity(identity);
6183 }
6184 }
6185
6186 /**
Miaoa84611c2019-03-15 09:21:10 +08006187 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006188 *
Miaoa84611c2019-03-15 09:21:10 +08006189 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006190 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006191 * @hide
6192 */
6193 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006194 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006197 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 try {
Miaoa84611c2019-03-15 09:21:10 +08006199 if (phone != null) {
6200 return phone.hasMatchedTetherApnSetting();
6201 } else {
6202 return false;
6203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006206 }
Junda Liu475951f2014-11-07 16:45:03 -08006207 }
6208
6209 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006210 * Enable or disable always reporting signal strength changes from radio.
6211 *
6212 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6213 */
6214 @Override
6215 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6216 enforceModifyPermission();
6217 enforceSystemCaller();
6218
6219 final long identity = Binder.clearCallingIdentity();
6220 final Phone phone = getPhone(subId);
6221 try {
6222 if (phone != null) {
6223 if (DBG) {
6224 log("setAlwaysReportSignalStrength: subId=" + subId
6225 + " isEnable=" + isEnable);
6226 }
6227 phone.setAlwaysReportSignalStrength(isEnable);
6228 } else {
6229 loge("setAlwaysReportSignalStrength: no phone found for subId="
6230 + subId);
6231 }
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006238 * Get the user enabled state of Mobile Data.
6239 *
6240 * TODO: remove and use isUserDataEnabled.
6241 * This can't be removed now because some vendor codes
6242 * calls through ITelephony directly while they should
6243 * use TelephonyManager.
6244 *
6245 * @return true on enabled
6246 */
6247 @Override
6248 public boolean getDataEnabled(int subId) {
6249 return isUserDataEnabled(subId);
6250 }
6251
6252 /**
6253 * Get whether mobile data is enabled per user setting.
6254 *
6255 * There are other factors deciding whether mobile data is actually enabled, but they are
6256 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006257 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006258 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006259 *
6260 * @return {@code true} if data is enabled else {@code false}
6261 */
6262 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006263 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006264 try {
6265 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6266 null);
6267 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6269 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271
6272 final long identity = Binder.clearCallingIdentity();
6273 try {
6274 int phoneId = mSubscriptionController.getPhoneId(subId);
6275 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6276 Phone phone = PhoneFactory.getPhone(phoneId);
6277 if (phone != null) {
6278 boolean retVal = phone.isUserDataEnabled();
6279 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6280 return retVal;
6281 } else {
6282 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6283 return false;
6284 }
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006287 }
6288 }
6289
6290 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006291 * Checks if the device is capable of mobile data by considering whether whether the
6292 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6293 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006294 *
Shuo Qian985d1232020-01-08 14:30:06 -08006295 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006296 */
6297 @Override
6298 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006299 try {
6300 try {
6301 mApp.enforceCallingOrSelfPermission(
6302 android.Manifest.permission.ACCESS_NETWORK_STATE,
6303 null);
6304 } catch (Exception e) {
6305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6306 "isDataEnabled");
6307 }
6308 } catch (Exception e) {
6309 enforceReadPrivilegedPermission("isDataEnabled");
6310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311
6312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 int phoneId = mSubscriptionController.getPhoneId(subId);
6315 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6316 Phone phone = PhoneFactory.getPhone(phoneId);
6317 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006318 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6320 return retVal;
6321 } else {
6322 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6323 return false;
6324 }
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006327 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006328 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006329
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006330 /**
6331 * Check if data is enabled for a specific reason
6332 * @param subId Subscription index
6333 * @param reason the reason the data enable change is taking place
6334 * @return {@code true} if the overall data is enabled; {@code false} if not.
6335 */
6336 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006337 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006338 @TelephonyManager.DataEnabledReason int reason) {
6339 try {
6340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6341 null);
6342 } catch (Exception e) {
6343 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006344 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006345 }
6346
6347
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
6350 int phoneId = mSubscriptionController.getPhoneId(subId);
6351 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006352 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006353 + " reason=" + reason);
6354 }
6355 Phone phone = PhoneFactory.getPhone(phoneId);
6356 if (phone != null) {
6357 boolean retVal;
6358 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6359 retVal = phone.isUserDataEnabled();
6360 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006361 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006362 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006363 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006364 return retVal;
6365 } else {
6366 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006367 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006368 + subId + " retVal=false");
6369 }
6370 return false;
6371 }
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
6375 }
6376
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006377 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006378 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006379 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6380 // Skip the check if it's one of these special uids
6381 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6382 }
6383
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006384 //load access rules from carrier configs, and check those as well: b/139133814
6385 SubscriptionController subController = SubscriptionController.getInstance();
6386 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6387 || subController == null) return privilegeFromSim;
6388
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006389 PackageManager pkgMgr = phone.getContext().getPackageManager();
6390 String[] packages = pkgMgr.getPackagesForUid(uid);
6391
6392 final long identity = Binder.clearCallingIdentity();
6393 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006394 int subId = phone.getSubId();
6395 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6396 // A test override is in place for the privileges for this subId, so don't try to
6397 // read the subscription privileges.
6398 return privilegeFromSim;
6399 }
6400 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006401 SubscriptionManager subManager = (SubscriptionManager)
6402 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6403 for (String pkg : packages) {
6404 if (subManager.canManageSubscription(subInfo, pkg)) {
6405 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6406 }
6407 }
6408 return privilegeFromSim;
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
6412 }
6413
6414 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6415 String pkgName) {
6416 //load access rules from carrier configs, and check those as well: b/139133814
6417 SubscriptionController subController = SubscriptionController.getInstance();
6418 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6419 || subController == null) return privilegeFromSim;
6420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006423 int subId = phone.getSubId();
6424 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6425 // A test override is in place for the privileges for this subId, so don't try to
6426 // read the subscription privileges.
6427 return privilegeFromSim;
6428 }
6429 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006430 SubscriptionManager subManager = (SubscriptionManager)
6431 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6432 return subManager.canManageSubscription(subInfo, pkgName)
6433 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
6437 }
6438
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006440 public int getCarrierPrivilegeStatus(int subId) {
6441 final Phone phone = getPhone(subId);
6442 if (phone == null) {
6443 loge("getCarrierPrivilegeStatus: Invalid subId");
6444 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6445 }
6446 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006447 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006448 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6450 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006451
6452 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6453 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006454 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006455 }
Junda Liu29340342014-07-10 15:23:27 -07006456
6457 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006459 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006460 final Phone phone = getPhone(subId);
6461 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006462 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6464 }
6465 UiccProfile profile =
6466 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6467 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006468 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6470 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006471 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006472 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006473 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006474 }
6475
6476 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006477 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6478 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006479 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006480 }
6481
6482 int phoneId = SubscriptionManager.getPhoneId(subId);
6483 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006484 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006485 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006486 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6487 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006488 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6489 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6490 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006491 }
6492
6493 @Override
6494 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006495 if (TextUtils.isEmpty(pkgName))
6496 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006497 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6498 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6499 UiccCard card = UiccController.getInstance().getUiccCard(i);
6500 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006501 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006502 continue;
6503 }
6504
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006505 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6506 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6507 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006508 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6509 break;
6510 }
6511 }
6512
6513 return result;
Junda Liu29340342014-07-10 15:23:27 -07006514 }
Derek Tan89e89d42014-07-08 17:00:10 -07006515
6516 @Override
Junda Liue64de782015-04-16 17:19:16 -07006517 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6518 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6519 loge("phoneId " + phoneId + " is not valid.");
6520 return null;
6521 }
6522 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006523 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006524 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006525 return null ;
6526 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006527 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006528 }
6529
Amith Yamasani6e118872016-02-19 12:53:51 -08006530 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006531 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006532 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006533 List<String> privilegedPackages = new ArrayList<>();
6534 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006535 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6536 // has UICC in that slot.
6537 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006538 if (card.hasCarrierPrivilegeRules()) {
6539 if (packages == null) {
6540 // Only check packages in user 0 for now
6541 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006542 PackageManager.MATCH_DISABLED_COMPONENTS
6543 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006544 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006545 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006546 }
6547 for (int p = packages.size() - 1; p >= 0; p--) {
6548 PackageInfo pkgInfo = packages.get(p);
6549 if (pkgInfo != null && pkgInfo.packageName != null
6550 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006551 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006552 privilegedPackages.add(pkgInfo.packageName);
6553 }
6554 }
6555 }
6556 }
6557 return privilegedPackages;
6558 }
6559
chen xuf7e9fe82019-05-09 19:31:02 -07006560 @Override
6561 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006562 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6563
6564 final long identity = Binder.clearCallingIdentity();
6565
chen xuf7e9fe82019-05-09 19:31:02 -07006566 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006567 try {
6568 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6569 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6570 }
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006573 }
6574 return privilegedPackages;
6575 }
6576
Wink Savilleb564aae2014-10-23 10:18:09 -07006577 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006578 final Phone phone = getPhone(subId);
6579 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006580 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006581 return null;
6582 }
6583 String iccId = card.getIccId();
6584 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006585 return null;
6586 }
6587 return iccId;
6588 }
6589
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006590 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006591 public void setCallComposerStatus(int subId, int status) {
6592 enforceModifyPermission();
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 Phone phone = getPhone(subId);
6597 if (phone != null) {
6598 Phone defaultPhone = phone.getImsPhone();
6599 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6600 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6601 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006602 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6603 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006604 }
6605 }
Shuo Qiand8782462020-12-22 19:10:14 -08006606 } catch (ImsException e) {
6607 throw new ServiceSpecificException(e.getCode());
6608 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 @Override
6614 public int getCallComposerStatus(int subId) {
6615 enforceReadPrivilegedPermission("getCallComposerStatus");
6616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 Phone phone = getPhone(subId);
6620 if (phone != null) {
6621 Phone defaultPhone = phone.getImsPhone();
6622 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6623 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6624 return imsPhone.getCallComposerStatus();
6625 }
6626 }
6627 } finally {
6628 Binder.restoreCallingIdentity(identity);
6629 }
6630 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6631 }
6632
6633 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006634 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6635 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006636 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006637 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 final String iccId = getIccId(subId);
6642 final Phone phone = getPhone(subId);
6643 if (phone == null) {
6644 return false;
6645 }
6646 final String subscriberId = phone.getSubscriberId();
6647
6648 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006649 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 + subscriberId + " to " + number);
6651 }
6652
6653 if (TextUtils.isEmpty(iccId)) {
6654 return false;
6655 }
6656
6657 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6658
6659 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6660 if (alphaTag == null) {
6661 editor.remove(alphaTagPrefKey);
6662 } else {
6663 editor.putString(alphaTagPrefKey, alphaTag);
6664 }
6665
6666 // Record both the line number and IMSI for this ICCID, since we need to
6667 // track all merged IMSIs based on line number
6668 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6669 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6670 if (number == null) {
6671 editor.remove(numberPrefKey);
6672 editor.remove(subscriberPrefKey);
6673 } else {
6674 editor.putString(numberPrefKey, number);
6675 editor.putString(subscriberPrefKey, subscriberId);
6676 }
6677
6678 editor.commit();
6679 return true;
6680 } finally {
6681 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006682 }
Derek Tan7226c842014-07-02 17:42:23 -07006683 }
6684
6685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006686 public String getLine1NumberForDisplay(int subId, String callingPackage,
6687 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006688 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006690 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006691 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006692 return null;
6693 }
Derek Tan97ebb422014-09-05 16:55:38 -07006694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 final long identity = Binder.clearCallingIdentity();
6696 try {
6697 String iccId = getIccId(subId);
6698 if (iccId != null) {
6699 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6700 if (DBG_MERGE) {
6701 log("getLine1NumberForDisplay returning "
6702 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6703 }
6704 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
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 }
6712
6713 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006714 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006717 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006718 return null;
6719 }
Derek Tan97ebb422014-09-05 16:55:38 -07006720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 final long identity = Binder.clearCallingIdentity();
6722 try {
6723 String iccId = getIccId(subId);
6724 if (iccId != null) {
6725 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6726 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6727 }
6728 return null;
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006731 }
Derek Tan7226c842014-07-02 17:42:23 -07006732 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006733
6734 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006735 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6736 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006737 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6738 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006740 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006741 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006742 return null;
6743 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006744
Jordan Liub49b04b2019-05-06 14:45:15 -07006745 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6746 // the process, where TelephonyManager was instantiated.
6747 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006748 final long identity = Binder.clearCallingIdentity();
6749 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006750 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final TelephonyManager tele = TelephonyManager.from(context);
6752 final SubscriptionManager sub = SubscriptionManager.from(context);
6753
6754 // Figure out what subscribers are currently active
6755 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756
Jordan Liub49b04b2019-05-06 14:45:15 -07006757 // Only consider subs which match the current subId
6758 // This logic can be simplified. See b/131189269 for progress.
6759 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006760 activeSubscriberIds.add(tele.getSubscriberId(subId));
6761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
6763 // First pass, find a number override for an active subscriber
6764 String mergeNumber = null;
6765 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6766 for (String key : prefs.keySet()) {
6767 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6768 final String subscriberId = (String) prefs.get(key);
6769 if (activeSubscriberIds.contains(subscriberId)) {
6770 final String iccId = key.substring(
6771 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6772 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6773 mergeNumber = (String) prefs.get(numberKey);
6774 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006775 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 + " for active subscriber " + subscriberId);
6777 }
6778 if (!TextUtils.isEmpty(mergeNumber)) {
6779 break;
6780 }
6781 }
6782 }
6783 }
6784
6785 // Shortcut when no active merged subscribers
6786 if (TextUtils.isEmpty(mergeNumber)) {
6787 return null;
6788 }
6789
6790 // Second pass, find all subscribers under that line override
6791 final ArraySet<String> result = new ArraySet<>();
6792 for (String key : prefs.keySet()) {
6793 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6794 final String number = (String) prefs.get(key);
6795 if (mergeNumber.equals(number)) {
6796 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6797 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6798 final String subscriberId = (String) prefs.get(subscriberKey);
6799 if (!TextUtils.isEmpty(subscriberId)) {
6800 result.add(subscriberId);
6801 }
6802 }
6803 }
6804 }
6805
6806 final String[] resultArray = result.toArray(new String[result.size()]);
6807 Arrays.sort(resultArray);
6808 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006809 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6811 }
6812 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006813 } finally {
6814 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006815 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006816 }
6817
6818 @Override
zoey chen38003472019-12-13 17:16:31 +08006819 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6820 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 final TelephonyManager telephonyManager = mApp.getSystemService(
6825 TelephonyManager.class);
6826 String subscriberId = telephonyManager.getSubscriberId(subId);
6827 if (subscriberId == null) {
6828 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006829 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006830 + subId);
6831 }
6832 return null;
6833 }
6834
6835 final SubscriptionInfo info = SubscriptionController.getInstance()
6836 .getSubscriptionInfo(subId);
6837 final ParcelUuid groupUuid = info.getGroupUuid();
6838 // If it doesn't belong to any group, return just subscriberId of itself.
6839 if (groupUuid == null) {
6840 return new String[]{subscriberId};
6841 }
6842
6843 // Get all subscriberIds from the group.
6844 final List<String> mergedSubscriberIds = new ArrayList<>();
6845 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006846 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006847 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006848 for (SubscriptionInfo subInfo : groupInfos) {
6849 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6850 if (subscriberId != null) {
6851 mergedSubscriberIds.add(subscriberId);
6852 }
6853 }
6854
6855 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858
6859 }
6860 }
6861
6862 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006863 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006864 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006865 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 final Phone phone = getPhone(subId);
6870 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006874 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006875
6876 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006877 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006878 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6879 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006880 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6881 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 final Phone phone = getPhone(subId);
6886 if (phone == null) {
6887 return false;
6888 }
6889 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6890 cdmaNonRoamingList);
6891 } finally {
6892 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006893 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006894 }
6895
6896 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006897 @Deprecated
6898 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6899 enforceModifyPermission();
6900
6901 int returnValue = 0;
6902 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006903 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006904 if(result.exception == null) {
6905 if (result.result != null) {
6906 byte[] responseData = (byte[])(result.result);
6907 if(responseData.length > oemResp.length) {
6908 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6909 responseData.length + "bytes. Buffer Size is " +
6910 oemResp.length + "bytes.");
6911 }
6912 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6913 returnValue = responseData.length;
6914 }
6915 } else {
6916 CommandException ex = (CommandException) result.exception;
6917 returnValue = ex.getCommandError().ordinal();
6918 if(returnValue > 0) returnValue *= -1;
6919 }
6920 } catch (RuntimeException e) {
6921 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6922 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6923 if(returnValue > 0) returnValue *= -1;
6924 }
6925
6926 return returnValue;
6927 }
6928
6929 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006930 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006931 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006932 try {
6933 TelephonyPermissions
6934 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6935 mApp, phone.getSubId(), "getRadioAccessFamily");
6936 } catch (SecurityException e) {
6937 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6938 throw e;
6939 }
chen xub97461a2018-10-26 14:17:57 -07006940 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006941 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006942 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 final long identity = Binder.clearCallingIdentity();
6945 try {
chen xub97461a2018-10-26 14:17:57 -07006946 TelephonyPermissions
6947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6948 mApp, phone.getSubId(), "getRadioAccessFamily");
6949 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 } finally {
6951 Binder.restoreCallingIdentity(identity);
6952 }
chen xub97461a2018-10-26 14:17:57 -07006953 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006954 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006955
6956 @Override
6957 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006958 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960
6961 final long identity = Binder.clearCallingIdentity();
6962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006963 ImsManager.getInstance(defaultPhone.getContext(),
6964 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006968 }
6969
6970 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006971 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006972 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6974 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006975 return false;
6976 }
Svet Ganovb320e182015-04-16 12:30:10 -07006977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 // Check the user preference and the system-level IMS setting. Even if the user has
6981 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6982 // In the long run, we may instead need to check if there exists a connection service
6983 // which can support video calling.
6984 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006985 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 return imsManager.isVtEnabledByPlatform()
6987 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6988 && imsManager.isVtEnabledByUser();
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006992 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006993
Andrew Leea1239f22015-03-02 17:44:07 -08006994 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006995 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6996 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006998 mApp, subId, callingPackage, callingFeatureId,
6999 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 return false;
7001 }
7002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 CarrierConfigManager configManager =
7006 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007007 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
7011 }
Andrew Leea1239f22015-03-02 17:44:07 -08007012 }
7013
7014 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007015 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007017 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 return false;
7019 }
7020
7021 final long identity = Binder.clearCallingIdentity();
7022 try {
7023 CarrierConfigManager configManager =
7024 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007025 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
Andrew Leea1239f22015-03-02 17:44:07 -08007030 }
7031
Andrew Lee9431b832015-03-09 18:46:45 -07007032 @Override
7033 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007034 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007035 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007036 }
7037
7038 @Override
7039 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 final long identity = Binder.clearCallingIdentity();
7041 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007042 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
Andrew Lee9431b832015-03-09 18:46:45 -07007046 }
7047
Hall Liuf6668912018-10-31 17:05:23 -07007048 /**
7049 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7050 * support for the feature and device firmware support.
7051 *
7052 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7053 */
7054 @Override
7055 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007057 final Phone phone = getPhone(subscriptionId);
7058 if (phone == null) {
7059 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7060 return false;
7061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007063 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7065 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007066 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 return isCarrierSupported && isDeviceSupported;
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
Hall Liu98187582018-01-22 19:15:32 -08007071 }
7072
Hall Liuf6668912018-10-31 17:05:23 -07007073 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007074 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7075 * RTT setting, will return true if the device and carrier both support RTT.
7076 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007077 */
7078 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 final long identity = Binder.clearCallingIdentity();
7080 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007081 boolean isRttSupported = isRttSupported(subscriptionId);
7082 boolean isUserRttSettingOn = Settings.Secure.getInt(
7083 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7084 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7085 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7086 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007090 }
7091
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 @Deprecated
7093 @Override
7094 public String getDeviceId(String callingPackage) {
7095 return getDeviceIdWithFeature(callingPackage, null);
7096 }
7097
Sanket Padawe7310cc72015-01-14 09:53:20 -08007098 /**
7099 * Returns the unique device ID of phone, for example, the IMEI for
7100 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7101 *
7102 * <p>Requires Permission:
7103 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7104 */
7105 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007106 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007107 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007108 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007109 return null;
7110 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007111 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007112 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007113 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007114 return null;
7115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
7119 return phone.getDeviceId();
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007123 }
7124
Ping Sunc67b7c22016-03-02 19:16:45 +08007125 /**
7126 * {@hide}
7127 * Returns the IMS Registration Status on a particular subid
7128 *
7129 * @param subId
7130 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007131 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007132 Phone phone = getPhone(subId);
7133 if (phone != null) {
7134 return phone.isImsRegistered();
7135 } else {
7136 return false;
7137 }
7138 }
7139
Santos Cordon7a1885b2015-02-03 11:15:19 -08007140 @Override
7141 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007148 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007149
Tyler Gunnf70ed162019-04-03 15:28:53 -07007150 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007151 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007152 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007154 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007155 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7156 }
7157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
7163 }
7164
7165 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007166 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007167 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7168 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 Phone phone = getPhone(subscriptionId);
7172 if (phone == null) {
7173 return null;
7174 }
7175 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
7179 }
7180
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007181 /**
7182 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007183 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007184 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 final long identity = Binder.clearCallingIdentity();
7186 try {
7187 Phone phone = getPhone(subId);
7188 if (phone != null) {
7189 return phone.isWifiCallingEnabled();
7190 } else {
7191 return false;
7192 }
7193 } finally {
7194 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007195 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007196 }
7197
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007198 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007199 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007200 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007201 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 Phone phone = getPhone(subId);
7205 if (phone != null) {
7206 return phone.isVideoEnabled();
7207 } else {
7208 return false;
7209 }
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007212 }
7213 }
7214
7215 /**
7216 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7217 * defined in {@link ImsRegistrationImplBase}.
7218 */
7219 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 Phone phone = getPhone(subId);
7223 if (phone != null) {
7224 return phone.getImsRegistrationTech();
7225 } else {
7226 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7227 }
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007230 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007231 }
7232
Stuart Scott8eef64f2015-04-08 15:13:54 -07007233 @Override
7234 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007235 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007236 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7237 return;
7238 }
7239
Svet Ganovcc087f82015-05-12 20:35:54 -07007240 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007241
Svet Ganovcc087f82015-05-12 20:35:54 -07007242 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007243 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7244 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007245 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007246 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007247 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007248 setAllowedNetworkTypesForReason(subId,
7249 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7250 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7251 setAllowedNetworkTypesForReason(subId,
7252 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7253 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7254 setAllowedNetworkTypesForReason(subId,
7255 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7256 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007257 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7258 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007259 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007260 // There has been issues when Sms raw table somehow stores orphan
7261 // fragments. They lead to garbled message when new fragments come
7262 // in and combined with those stale ones. In case this happens again,
7263 // user can reset all network settings which will clean up this table.
7264 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007265 // Clean up IMS settings as well here.
7266 int slotId = getSlotIndex(subId);
7267 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7268 ImsManager.getInstance(mApp, slotId).factoryReset();
7269 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007270
7271 // Erase modem config if erase modem on network setting is enabled.
7272 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7273 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7274 if (configValue != null && Boolean.parseBoolean(configValue)) {
7275 sendEraseModemConfig(getDefaultPhone());
7276 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007277 } finally {
7278 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007279 }
7280 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007281
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007282 private void cleanUpSmsRawTable(Context context) {
7283 ContentResolver resolver = context.getContentResolver();
7284 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7285 resolver.delete(uri, null, null);
7286 }
7287
Narayan Kamath1c496c22015-04-16 14:40:19 +01007288 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007289 public String getSimLocaleForSubscriber(int subId) {
7290 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7291 final Phone phone = getPhone(subId);
7292 if (phone == null) {
7293 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007294 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 final long identity = Binder.clearCallingIdentity();
7297 try {
chen xu5d3637b2019-01-21 23:31:38 -08007298 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007299 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007300 if (info == null) {
7301 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7302 return null;
7303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304 // Try and fetch the locale from the carrier properties or from the SIM language
7305 // preferences (EF-PL and EF-LI)...
7306 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007308 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7309 if (localeFromDefaultSim != null) {
7310 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7311 if (DBG) log("Using locale from subId: " + subId + " locale: "
7312 + localeFromDefaultSim);
7313 return localeFromDefaultSim.toLanguageTag();
7314 } else {
7315 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 }
7317 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 // The SIM language preferences only store a language (e.g. fr = French), not an
7320 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7321 // the SIM and carrier preferences does not include a country we add the country
7322 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007323 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007325 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 return mccLocale.toLanguageTag();
7327 }
7328
7329 if (DBG) log("No locale found - returning null");
7330 return null;
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007334 }
7335
7336 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007337 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007338 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007339 }
7340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 /**
7342 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7343 */
7344 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007345 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007346 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007347 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007348
Chenjie Yu1ba97252018-01-11 18:16:20 -08007349 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007350 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007351
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007352 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007353 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7354 * representing the state of the modem.
7355 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007356 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7357 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007358 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007359 */
7360 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007361 public void requestModemActivityInfo(ResultReceiver result) {
7362 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
sqian1a1be542020-03-05 11:37:28 -08007367 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 } finally {
7369 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007370 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007371 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007372
Siddharth Rayb8114062018-06-17 15:02:38 -07007373 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7374 // less than total activity duration.
7375 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7376 if (info == null) {
7377 return false;
7378 }
7379 int activityDurationMs =
7380 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7381 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007382 int[] txTimeMs = info.getTransmitTimeMillis();
7383 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7384 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007385 }
7386 return (info.isValid()
7387 && (info.getSleepTimeMillis() <= activityDurationMs)
7388 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007389 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007390 && (totalTxTimeMs <= activityDurationMs));
7391 }
7392
Jack Yu85bd38a2015-11-09 11:34:32 -08007393 /**
7394 * {@hide}
7395 * Returns the service state information on specified subscription.
7396 */
7397 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007398 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7399 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007401 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007402 return null;
7403 }
7404
Hall Liuf19c44f2018-11-27 14:38:17 -08007405 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7406 LocationAccessPolicy.checkLocationPermission(mApp,
7407 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7408 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007409 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007410 .setCallingPid(Binder.getCallingPid())
7411 .setCallingUid(Binder.getCallingUid())
7412 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007413 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007414 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7415 .build());
7416
7417 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7418 LocationAccessPolicy.checkLocationPermission(mApp,
7419 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7420 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007421 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007422 .setCallingPid(Binder.getCallingPid())
7423 .setCallingUid(Binder.getCallingUid())
7424 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007425 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007426 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7427 .build());
7428 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7429 boolean hasFinePermission =
7430 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7431 boolean hasCoarsePermission =
7432 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 final long identity = Binder.clearCallingIdentity();
7435 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007436 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7437 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7438 Rlog.d(LOG_TAG,
7439 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7440 return null;
7441 }
7442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final Phone phone = getPhone(subId);
7444 if (phone == null) {
7445 return null;
7446 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007447
Hall Liuf19c44f2018-11-27 14:38:17 -08007448 ServiceState ss = phone.getServiceState();
7449
7450 // Scrub out the location info in ServiceState depending on what level of access
7451 // the caller has.
7452 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007453 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7454 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007458 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007459
7460 /**
7461 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7462 *
7463 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7464 * voicemail ringtone.
7465 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7466 * PhoneAccount.
7467 */
7468 @Override
7469 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 final long identity = Binder.clearCallingIdentity();
7471 try {
7472 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7473 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007474 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007481 }
7482
7483 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007484 * Sets the per-account voicemail ringtone.
7485 *
7486 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7487 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7488 *
7489 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7490 * voicemail ringtone.
7491 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7492 * PhoneAccount.
7493 */
7494 @Override
7495 public void setVoicemailRingtoneUri(String callingPackage,
7496 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007497 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007499 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7500 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7502 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7503 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7509 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007510 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 }
7512 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007515 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007516 }
7517
7518 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007519 * Returns whether vibration is set for voicemail notification in Phone settings.
7520 *
7521 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7522 * voicemail vibration setting.
7523 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7524 */
7525 @Override
7526 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7530 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007531 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007538 }
7539
Youhan Wange64578a2016-05-02 15:32:42 -07007540 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007541 * Sets the per-account voicemail vibration.
7542 *
7543 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7544 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7545 *
7546 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7547 * voicemail vibration setting.
7548 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7549 * specific PhoneAccount.
7550 */
7551 @Override
7552 public void setVoicemailVibrationEnabled(String callingPackage,
7553 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007554 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007556 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7557 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7559 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7560 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007561 }
7562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7566 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 }
7569 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007572 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007573 }
7574
7575 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007576 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7577 *
7578 * @throws SecurityException if the caller does not have the required permission
7579 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007580 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007582 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007583 }
7584
7585 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007586 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7587 * permission.
7588 *
7589 * @throws SecurityException if the caller does not have the required permission
7590 */
7591 private void enforceSendSmsPermission() {
7592 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7593 }
7594
7595 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007596 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007597 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007598 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007599 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007600 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007604 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 if (componentName == null) {
7606 throw new SecurityException(
7607 "Caller not current active visual voicemail package[null]");
7608 }
7609 String vvmPackage = componentName.getPackageName();
7610 if (!callingPackage.equals(vvmPackage)) {
7611 throw new SecurityException("Caller not current active visual voicemail package["
7612 + vvmPackage + "]");
7613 }
7614 } finally {
7615 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007616 }
7617 }
7618
7619 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007620 * Return the application ID for the app type.
7621 *
7622 * @param subId the subscription ID that this request applies to.
7623 * @param appType the uicc app type.
7624 * @return Application ID for specificied app type, or null if no uicc.
7625 */
7626 @Override
7627 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007628 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007629 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630
7631 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007632 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633 if (phone == null) {
7634 return null;
7635 }
7636 String aid = null;
7637 try {
7638 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7639 .getApplicationByType(appType).getAid();
7640 } catch (Exception e) {
7641 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7642 }
7643 return aid;
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007646 }
Youhan Wange64578a2016-05-02 15:32:42 -07007647 }
7648
Youhan Wang4001d252016-05-11 10:29:41 -07007649 /**
7650 * Return the Electronic Serial Number.
7651 *
7652 * @param subId the subscription ID that this request applies to.
7653 * @return ESN or null if error.
7654 */
7655 @Override
7656 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007657 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007658 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659
7660 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007661 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 if (phone == null) {
7663 return null;
7664 }
7665 String esn = null;
7666 try {
7667 esn = phone.getEsn();
7668 } catch (Exception e) {
7669 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7670 }
7671 return esn;
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007674 }
Youhan Wang4001d252016-05-11 10:29:41 -07007675 }
7676
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007677 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007678 * Return the Preferred Roaming List Version.
7679 *
7680 * @param subId the subscription ID that this request applies to.
7681 * @return PRLVersion or null if error.
7682 */
7683 @Override
7684 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007685 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007686 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687
7688 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007689 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 if (phone == null) {
7691 return null;
7692 }
7693 String cdmaPrlVersion = null;
7694 try {
7695 cdmaPrlVersion = phone.getCdmaPrlVersion();
7696 } catch (Exception e) {
7697 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7698 }
7699 return cdmaPrlVersion;
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007702 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007703 }
7704
7705 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007706 * Get snapshot of Telephony histograms
7707 * @return List of Telephony histograms
7708 * @hide
7709 */
7710 @Override
7711 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7713 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714
7715 final long identity = Binder.clearCallingIdentity();
7716 try {
7717 return RIL.getTelephonyRILTimingHistograms();
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
7720 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007721 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007722
7723 /**
7724 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007725 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7726 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007727 * Require system privileges. In the future we may add this to carrier APIs.
7728 *
Michele Berionne482f8202018-11-27 18:57:59 -08007729 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007730 */
7731 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007732 @TelephonyManager.SetCarrierRestrictionResult
7733 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007734 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007735 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007736
Michele Berionne482f8202018-11-27 18:57:59 -08007737 if (carrierRestrictionRules == null) {
7738 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007739 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 final long identity = Binder.clearCallingIdentity();
7742 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007743 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007744 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 } finally {
7746 Binder.restoreCallingIdentity(identity);
7747 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007748 }
7749
7750 /**
7751 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007752 * Get the allowed carrier list and the excluded carrier list, including the priority between
7753 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007754 * Require system privileges. In the future we may add this to carrier APIs.
7755 *
Michele Berionne482f8202018-11-27 18:57:59 -08007756 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007757 */
7758 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007759 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007760 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762
7763 final long identity = Binder.clearCallingIdentity();
7764 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007765 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7766 if (response instanceof CarrierRestrictionRules) {
7767 return (CarrierRestrictionRules) response;
7768 }
7769 // Response is an Exception of some kind,
7770 // which is signalled to the user as a NULL retval
7771 return null;
7772 } catch (Exception e) {
7773 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7774 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007778 }
7779
fionaxu59545b42016-05-25 15:53:37 -07007780 /**
fionaxu59545b42016-05-25 15:53:37 -07007781 * Action set from carrier signalling broadcast receivers to enable/disable radio
7782 * @param subId the subscription ID that this action applies to.
7783 * @param enabled control enable or disable radio.
7784 * {@hide}
7785 */
7786 @Override
7787 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7788 enforceModifyPermission();
7789 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790
7791 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007792 if (phone == null) {
7793 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7794 return;
7795 }
7796 try {
7797 phone.carrierActionSetRadioEnabled(enabled);
7798 } catch (Exception e) {
7799 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 } finally {
7801 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007802 }
7803 }
7804
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007805 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007806 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7807 * network status based on which carrier apps could apply actions accordingly,
7808 * enable/disable default url handler for example.
7809 *
7810 * @param subId the subscription ID that this action applies to.
7811 * @param report control start/stop reporting the default network status.
7812 * {@hide}
7813 */
7814 @Override
7815 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7816 enforceModifyPermission();
7817 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818
7819 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007820 if (phone == null) {
7821 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7822 return;
7823 }
7824 try {
7825 phone.carrierActionReportDefaultNetworkStatus(report);
7826 } catch (Exception e) {
7827 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 } finally {
7829 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007830 }
7831 }
7832
7833 /**
fionaxud9622282017-07-17 17:51:30 -07007834 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7835 * @param subId the subscription ID that this action applies to.
7836 * {@hide}
7837 */
7838 @Override
7839 public void carrierActionResetAll(int subId) {
7840 enforceModifyPermission();
7841 final Phone phone = getPhone(subId);
7842 if (phone == null) {
7843 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7844 return;
7845 }
7846 try {
7847 phone.carrierActionResetAll();
7848 } catch (Exception e) {
7849 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7850 }
7851 }
7852
7853 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007854 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7855 * bug report is being generated.
7856 */
7857 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007858 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007859 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7860 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007861 writer.println("Permission Denial: can't dump Phone from pid="
7862 + Binder.getCallingPid()
7863 + ", uid=" + Binder.getCallingUid()
7864 + "without permission "
7865 + android.Manifest.permission.DUMP);
7866 return;
7867 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007868 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007869 }
Jack Yueb89b242016-06-22 13:27:47 -07007870
Brad Ebingerdac2f002018-04-03 15:17:52 -07007871 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007872 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7873 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7874 @NonNull String[] args) {
7875 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7876 this, in.getFileDescriptor(), out.getFileDescriptor(),
7877 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007878 }
7879
Jack Yueb89b242016-06-22 13:27:47 -07007880 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007881 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007882 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007883 * @param reason the reason the data enable change is taking place
7884 * @param enabled True if enabling the data, otherwise disabling.
7885 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007886 */
7887 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007888 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007889 boolean enabled) {
7890 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7891 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7892 try {
7893 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007894 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007895 } catch (SecurityException se) {
7896 enforceModifyPermission();
7897 }
7898 } else {
7899 enforceModifyPermission();
7900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901
7902 final long identity = Binder.clearCallingIdentity();
7903 try {
7904 Phone phone = getPhone(subId);
7905 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007906 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7907 phone.carrierActionSetMeteredApnsEnabled(enabled);
7908 } else {
7909 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 }
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007914 }
7915 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007916
7917 /**
7918 * Get Client request stats
7919 * @return List of Client Request Stats
7920 * @hide
7921 */
7922 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007923 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7924 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007926 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007927 return null;
7928 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007929 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 if (phone != null) {
7934 return phone.getClientRequestStats();
7935 }
7936
7937 return null;
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007941 }
7942
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007943 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007944 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007945 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007946 }
Jack Yueb4124c2017-02-16 15:32:43 -08007947
7948 /**
Grace Chen70990072017-03-24 17:21:30 -07007949 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007950 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007951 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007952 * @param state State of SIM (power down, power up, pass through)
7953 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7954 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7955 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007956 *
7957 **/
7958 @Override
Grace Chen70990072017-03-24 17:21:30 -07007959 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007960 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007961 Phone phone = PhoneFactory.getPhone(slotIndex);
7962
vagdeviaf9a5b92018-08-15 16:01:53 -07007963 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 final long identity = Binder.clearCallingIdentity();
7966 try {
7967 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007968 phone.setSimPowerState(state, null, workSource);
7969 }
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
7972 }
7973 }
7974
7975 /**
7976 * Set SIM card power state.
7977 *
7978 * @param slotIndex SIM slot id.
7979 * @param state State of SIM (power down, power up, pass through)
7980 * @param callback callback to trigger after success or failure
7981 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7982 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7983 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7984 *
7985 **/
7986 @Override
7987 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7988 IIntegerConsumer callback) {
7989 enforceModifyPermission();
7990 Phone phone = PhoneFactory.getPhone(slotIndex);
7991
7992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7993
7994 final long identity = Binder.clearCallingIdentity();
7995 try {
7996 if (phone != null) {
7997 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7998 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 }
8000 } finally {
8001 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008002 }
8003 }
Shuo Qiandd210312017-04-12 22:11:33 +00008004
Tyler Gunn65d45c22017-06-05 11:22:26 -07008005 private boolean isUssdApiAllowed(int subId) {
8006 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008007 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008008 if (configManager == null) {
8009 return false;
8010 }
8011 PersistableBundle pb = configManager.getConfigForSubId(subId);
8012 if (pb == null) {
8013 return false;
8014 }
8015 return pb.getBoolean(
8016 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8017 }
8018
Shuo Qiandd210312017-04-12 22:11:33 +00008019 /**
8020 * Check if phone is in emergency callback mode
8021 * @return true if phone is in emergency callback mode
8022 * @param subId sub id
8023 */
goneil9c5f4872017-12-05 14:07:56 -08008024 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008025 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008026 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 if (phone != null) {
8032 return phone.isInEcm();
8033 } else {
8034 return false;
8035 }
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008038 }
8039 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008040
8041 /**
8042 * Get the current signal strength information for the given subscription.
8043 * Because this information is not updated when the device is in a low power state
8044 * it should not be relied-upon to be current.
8045 * @param subId Subscription index
8046 * @return the most recent cached signal strength info from the modem
8047 */
8048 @Override
8049 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 Phone p = getPhone(subId);
8053 if (p == null) {
8054 return null;
8055 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 return p.getSignalStrength();
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008061 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008062
Pengquan Meng77b7f132018-08-22 14:49:57 -07008063 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008064 * Get the current modem radio state for the given slot.
8065 * @param slotIndex slot index.
8066 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008067 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008068 * @return the current radio power state from the modem
8069 */
8070 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008071 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008072 Phone phone = PhoneFactory.getPhone(slotIndex);
8073 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8075 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008076 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8077 }
8078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 return phone.getRadioPowerState();
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
8084 }
8085 }
8086 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8087 }
8088
8089 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008090 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8091 *
8092 * <p>Requires one of the following permissions:
8093 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8094 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8095 * privileges.
8096 *
8097 * @param subId subscription id
8098 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8099 * {@code false}.
8100 */
8101 @Override
8102 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008103 try {
8104 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8105 null);
8106 } catch (Exception e) {
8107 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8108 mApp, subId, "isDataRoamingEnabled");
8109 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008110
Pengquan Menga1bb6272018-09-06 09:59:22 -07008111 boolean isEnabled = false;
8112 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008113 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008114 Phone phone = getPhone(subId);
8115 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008116 } finally {
8117 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008118 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008119 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008120 }
8121
8122
8123 /**
8124 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8125 *
8126 * <p> Requires permission:
8127 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8128 * privileges.
8129 *
8130 * @param subId subscription id
8131 * @param isEnabled {@code true} means enable, {@code false} means disable.
8132 */
8133 @Override
8134 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8136 mApp, subId, "setDataRoamingEnabled");
8137
Pengquan Menga1bb6272018-09-06 09:59:22 -07008138 final long identity = Binder.clearCallingIdentity();
8139 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008140 Phone phone = getPhone(subId);
8141 if (phone != null) {
8142 phone.setDataRoamingEnabled(isEnabled);
8143 }
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008146 }
8147 }
8148
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008149 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008150 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008151 TelephonyPermissions
8152 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008153 mApp, subId, "isManualNetworkSelectionAllowed");
8154
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008155 boolean isAllowed = true;
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008158 Phone phone = getPhone(subId);
8159 if (phone != null) {
8160 isAllowed = phone.isCspPlmnEnabled();
8161 }
8162 } finally {
8163 Binder.restoreCallingIdentity(identity);
8164 }
8165 return isAllowed;
8166 }
8167
8168 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008169 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008170 // Verify that tha callingPackage belongs to the calling UID
8171 mApp.getSystemService(AppOpsManager.class)
8172 .checkPackage(Binder.getCallingUid(), callingPackage);
8173
Jordan Liu1e142fc2019-04-22 15:10:43 -07008174 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008175 try {
8176 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008177 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008178 } catch (SecurityException e) {
8179 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8180 // has carrier privileges on an active UICC
8181 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8182 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008183 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008184 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008185 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008186
8187 final long identity = Binder.clearCallingIdentity();
8188 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008189 UiccController uiccController = UiccController.getInstance();
8190 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008191 if (hasReadPermission) {
8192 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008193 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008194
8195 // Remove private info if the caller doesn't have access
8196 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8197 for (UiccCardInfo cardInfo : cardInfos) {
8198 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8199 // is available
8200 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8201 if (card == null || card.getUiccProfile() == null) {
8202 // assume no access if the card or profile is unavailable
8203 filteredInfos.add(cardInfo.getUnprivileged());
8204 continue;
8205 }
8206 UiccProfile profile = card.getUiccProfile();
8207 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8208 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8209 filteredInfos.add(cardInfo);
8210 } else {
8211 filteredInfos.add(cardInfo.getUnprivileged());
8212 }
8213 }
8214 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008215 } finally {
8216 Binder.restoreCallingIdentity(identity);
8217 }
8218 }
8219
8220 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008221 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008222 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 final long identity = Binder.clearCallingIdentity();
8225 try {
8226 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8227 if (slots == null) {
8228 Rlog.i(LOG_TAG, "slots is null.");
8229 return null;
8230 }
8231
8232 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8233 for (int i = 0; i < slots.length; i++) {
8234 UiccSlot slot = slots[i];
8235 if (slot == null) {
8236 continue;
8237 }
8238
Jordan Liu7be7e652019-05-06 18:55:02 +00008239 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240 UiccCard card = slot.getUiccCard();
8241 if (card != null) {
8242 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008243 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008244 cardId = slot.getEid();
8245 if (TextUtils.isEmpty(cardId)) {
8246 cardId = slot.getIccId();
8247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 }
8249
Jordan Liu857451f2019-05-09 16:35:35 -07008250 if (cardId != null) {
8251 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8252 // if cardId is an EID, it's all digits so this is fine
8253 cardId = IccUtils.stripTrailingFs(cardId);
8254 }
8255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 int cardState = 0;
8257 switch (slot.getCardState()) {
8258 case CARDSTATE_ABSENT:
8259 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8260 break;
8261 case CARDSTATE_PRESENT:
8262 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8263 break;
8264 case CARDSTATE_ERROR:
8265 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8266 break;
8267 case CARDSTATE_RESTRICTED:
8268 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8269 break;
8270 default:
8271 break;
8272
8273 }
8274
8275 infos[i] = new UiccSlotInfo(
8276 slot.isActive(),
8277 slot.isEuicc(),
8278 cardId,
8279 cardState,
8280 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008281 slot.isExtendedApduSupported(),
8282 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 }
8284 return infos;
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008287 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008288 }
8289
8290 @Override
8291 public boolean switchSlots(int[] physicalSlots) {
8292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293
8294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008300 }
Jack Yu4c988042018-02-27 15:30:01 -08008301
8302 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008303 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 return UiccController.getInstance().getCardIdForDefaultEuicc();
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
8309 }
8310 }
8311
Pengquan Meng85728fb2018-03-12 16:31:21 -07008312 /**
goneil47ffb6e2018-04-06 15:40:58 -07008313 * A test API to reload the UICC profile.
8314 *
8315 * <p>Requires that the calling app has permission
8316 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8317 * @hide
8318 */
8319 @Override
8320 public void refreshUiccProfile(int subId) {
8321 enforceModifyPermission();
8322
8323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 Phone phone = getPhone(subId);
8326 if (phone == null) {
8327 return;
8328 }
8329 UiccCard uiccCard = phone.getUiccCard();
8330 if (uiccCard == null) {
8331 return;
8332 }
8333 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8334 if (uiccProfile == null) {
8335 return;
8336 }
8337 uiccProfile.refresh();
8338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
8341 }
8342
8343 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008344 * Returns false if the mobile data is disabled by default, otherwise return true.
8345 */
8346 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008347 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008348 }
8349
8350 /**
8351 * Returns true if the data roaming is enabled by default, i.e the system property
8352 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8353 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8354 */
8355 private boolean getDefaultDataRoamingEnabled(int subId) {
8356 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008357 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008358 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008359 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8360 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8361 return isDataRoamingEnabled;
8362 }
8363
8364 /**
8365 * Returns the default network type for the given {@code subId}, if the default network type is
8366 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8367 */
8368 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008369 List<Integer> list = TelephonyProperties.default_network();
8370 int phoneId = mSubscriptionController.getPhoneId(subId);
8371 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8372 return list.get(phoneId);
8373 }
8374 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008375 }
fionaxua13278b2018-03-21 00:08:13 -07008376
8377 @Override
8378 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008379 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008380 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 final Phone phone = getPhone(subId);
8385 if (phone == null) {
8386 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8387 return;
8388 }
chen xueaba88a2019-03-15 13:15:10 -07008389 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8390 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008391 if (carrierPrivilegeRules == null) {
8392 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8393 } else {
8394 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 } finally {
8397 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008398 }
fionaxua13278b2018-03-21 00:08:13 -07008399 }
8400
8401 @Override
8402 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008403 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008404
8405 final long identity = Binder.clearCallingIdentity();
8406 try {
8407 final Phone phone = getPhone(subId);
8408 if (phone == null) {
8409 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8410 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8411 }
8412 return phone.getCarrierIdListVersion();
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008415 }
fionaxua13278b2018-03-21 00:08:13 -07008416 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008417
8418 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008419 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8420 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008422 mApp, subId, callingPackage, callingFeatureId,
8423 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008424 return -1;
8425 }
8426
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
8432 }
8433 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008434
8435 @Override
8436 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008437 TelephonyPermissions
8438 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008439 mApp, subId, "getCdmaRoamingMode");
8440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
8447 }
8448
8449 @Override
8450 public boolean setCdmaRoamingMode(int subId, int mode) {
8451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8452 mApp, subId, "setCdmaRoamingMode");
8453
8454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
8460 }
8461
8462 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008463 public int getCdmaSubscriptionMode(int subId) {
8464 TelephonyPermissions
8465 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8466 mApp, subId, "getCdmaSubscriptionMode");
8467
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 }
8475
8476 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008477 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8479 mApp, subId, "setCdmaSubscriptionMode");
8480
8481 final long identity = Binder.clearCallingIdentity();
8482 try {
8483 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
8486 }
8487 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008488
sqianc5eccab2018-10-19 18:46:41 -07008489 @Override
sqian8c685422019-02-22 15:55:18 -08008490 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008491 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008493 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8494 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008495 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8496 }
8497 final long identity = Binder.clearCallingIdentity();
8498 try {
sqian854d44b2018-12-12 16:48:18 -08008499 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8500 for (Phone phone: PhoneFactory.getPhones()) {
8501 if (phone.getEmergencyNumberTracker() != null
8502 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8503 emergencyNumberListInternal.put(
8504 phone.getSubId(),
8505 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8506 }
sqian11b7a0e2018-12-05 18:48:28 -08008507 }
sqian854d44b2018-12-12 16:48:18 -08008508 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008509 } finally {
8510 Binder.restoreCallingIdentity(identity);
8511 }
sqianc5eccab2018-10-19 18:46:41 -07008512 }
8513
8514 @Override
sqian8c685422019-02-22 15:55:18 -08008515 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008516 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008517 if (!exactMatch) {
8518 TelephonyPermissions
8519 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008520 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008521 }
8522 final long identity = Binder.clearCallingIdentity();
8523 try {
sqian854d44b2018-12-12 16:48:18 -08008524 for (Phone phone: PhoneFactory.getPhones()) {
8525 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008526 && phone.getEmergencyNumberTracker()
8527 .isEmergencyNumber(number, exactMatch)) {
8528 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008529 }
sqian11b7a0e2018-12-05 18:48:28 -08008530 }
8531 return false;
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
8534 }
8535 }
8536
sqianf4ca7ed2019-01-15 18:32:07 -08008537 /**
8538 * Update emergency number list for test mode.
8539 */
8540 @Override
8541 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8543 "updateEmergencyNumberListTestMode");
8544
8545 final long identity = Binder.clearCallingIdentity();
8546 try {
8547 for (Phone phone: PhoneFactory.getPhones()) {
8548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8549 if (tracker != null) {
8550 tracker.executeEmergencyNumberTestModeCommand(action, num);
8551 }
8552 }
8553 } finally {
8554 Binder.restoreCallingIdentity(identity);
8555 }
8556 }
8557
8558 /**
8559 * Get the full emergency number list for test mode.
8560 */
8561 @Override
8562 public List<String> getEmergencyNumberListTestMode() {
8563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8564 "getEmergencyNumberListTestMode");
8565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 Set<String> emergencyNumbers = new HashSet<>();
8569 for (Phone phone: PhoneFactory.getPhones()) {
8570 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8571 if (tracker != null) {
8572 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8573 emergencyNumbers.add(num.getNumber());
8574 }
8575 }
8576 }
8577 return new ArrayList<>(emergencyNumbers);
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
8581 }
8582
chen xud6b45bd2018-10-30 22:27:10 -07008583 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008584 public int getEmergencyNumberDbVersion(int subId) {
8585 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8586
8587 final long identity = Binder.clearCallingIdentity();
8588 try {
8589 final Phone phone = getPhone(subId);
8590 if (phone == null) {
8591 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8592 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8593 }
8594 return phone.getEmergencyNumberDbVersion();
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
8598 }
8599
8600 @Override
8601 public void notifyOtaEmergencyNumberDbInstalled() {
8602 enforceModifyPermission();
8603
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 for (Phone phone: PhoneFactory.getPhones()) {
8607 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8608 if (tracker != null) {
8609 tracker.updateOtaEmergencyNumberDatabase();
8610 }
8611 }
8612 } finally {
8613 Binder.restoreCallingIdentity(identity);
8614 }
8615 }
8616
8617 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008618 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008619 enforceActiveEmergencySessionPermission();
8620
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
8623 for (Phone phone: PhoneFactory.getPhones()) {
8624 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8625 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008626 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8627 }
8628 }
8629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
8632 }
8633
8634 @Override
8635 public void resetOtaEmergencyNumberDbFilePath() {
8636 enforceActiveEmergencySessionPermission();
8637
8638 final long identity = Binder.clearCallingIdentity();
8639 try {
8640 for (Phone phone: PhoneFactory.getPhones()) {
8641 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8642 if (tracker != null) {
8643 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008644 }
8645 }
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650
8651 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008652 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8653 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8654 Phone phone = getPhone(subId);
8655 if (phone == null) {
8656 return null;
8657 }
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 UiccProfile profile = UiccController.getInstance()
8661 .getUiccProfileForPhone(phone.getPhoneId());
8662 if (profile != null) {
8663 return profile.getCertsFromCarrierPrivilegeAccessRules();
8664 }
8665 } finally {
8666 Binder.restoreCallingIdentity(identity);
8667 }
8668 return null;
8669 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008670
8671 /**
8672 * Enable or disable a modem stack.
8673 */
8674 @Override
8675 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8676 enforceModifyPermission();
8677
8678 final long identity = Binder.clearCallingIdentity();
8679 try {
8680 Phone phone = PhoneFactory.getPhone(slotIndex);
8681 if (phone == null) {
8682 return false;
8683 } else {
8684 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8685 }
8686 } finally {
8687 Binder.restoreCallingIdentity(identity);
8688 }
8689 }
Michelecea4cf22018-12-21 15:00:11 -08008690
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008691 /**
8692 * Whether a modem stack is enabled or not.
8693 */
8694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008695 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8696 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008697 Phone phone = PhoneFactory.getPhone(slotIndex);
8698 if (phone == null) return false;
8699
8700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008701 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8702 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008703 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8704 }
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008708 try {
8709 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8710 } catch (NoSuchElementException ex) {
8711 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8712 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 }
8717
Michelecea4cf22018-12-21 15:00:11 -08008718 @Override
Michele0ea7d782019-03-19 14:58:42 -07008719 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008720 enforceModifyPermission();
8721
8722 final long identity = Binder.clearCallingIdentity();
8723 try {
8724 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008725 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008726 .commit();
8727 } finally {
8728 Binder.restoreCallingIdentity(identity);
8729 }
8730 }
8731
8732 @Override
Michele0ea7d782019-03-19 14:58:42 -07008733 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008734 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008736 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8737 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008738 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008739 }
Michelecea4cf22018-12-21 15:00:11 -08008740
8741 final long identity = Binder.clearCallingIdentity();
8742 try {
Michele0ea7d782019-03-19 14:58:42 -07008743 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008744 } finally {
8745 Binder.restoreCallingIdentity(identity);
8746 }
8747 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008748
Michele0ea7d782019-03-19 14:58:42 -07008749 @TelephonyManager.IsMultiSimSupportedResult
8750 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008751 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8752 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8753 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008754 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8755 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008756 }
8757 // Check if the hardware supports multisim functionality. If usage of multisim is not
8758 // supported by the modem, indicate that it is restricted.
8759 PhoneCapability staticCapability =
8760 mPhoneConfigurationManager.getStaticPhoneCapability();
8761 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008762 loge("isMultiSimSupportedInternal: no static configuration available");
8763 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008764 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008765 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008766 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8767 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008768 }
8769 // Check if support of multiple SIMs is restricted by carrier
8770 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008771 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008772 }
8773
Michele0ea7d782019-03-19 14:58:42 -07008774 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008775 }
8776
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008777 /**
8778 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008779 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8780 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8781 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008782 * @param numOfSims number of active sims we want to switch to
8783 */
8784 @Override
8785 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008786 if (numOfSims == 1) {
8787 enforceModifyPermission();
8788 } else {
8789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8790 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8791 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008792 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008793
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008794 try {
Michele30b57b22019-03-01 12:01:14 -08008795 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008796 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008797 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8798 return;
8799 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008800 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
8805
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008806 @Override
8807 public boolean isApplicationOnUicc(int subId, int appType) {
8808 enforceReadPrivilegedPermission("isApplicationOnUicc");
8809 Phone phone = getPhone(subId);
8810 if (phone == null) {
8811 return false;
8812 }
8813 final long identity = Binder.clearCallingIdentity();
8814 try {
8815 UiccCard uiccCard = phone.getUiccCard();
8816 if (uiccCard == null) {
8817 return false;
8818 }
8819 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8820 if (uiccProfile == null) {
8821 return false;
8822 }
8823 if (TelephonyManager.APPTYPE_SIM <= appType
8824 && appType <= TelephonyManager.APPTYPE_ISIM) {
8825 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8826 }
8827 return false;
8828 } finally {
8829 Binder.restoreCallingIdentity(identity);
8830 }
8831 }
8832
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008833 /**
chen xub4baa772019-04-03 10:23:41 -07008834 * Get whether making changes to modem configurations will trigger reboot.
8835 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008836 */
8837 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008838 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8839 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008841 mApp, subId, callingPackage, callingFeatureId,
8842 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008843 return false;
8844 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008845 final long identity = Binder.clearCallingIdentity();
8846 try {
8847 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
8851 }
8852
Nathan Harold29f5f052019-02-15 13:41:57 -08008853 private void updateModemStateMetrics() {
8854 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8855 // TODO: check the state for each modem if the api is ready.
8856 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8857 }
8858
Pengquan Meng3889a572019-01-23 11:16:29 -08008859 @Override
8860 public int[] getSlotsMapping() {
8861 enforceReadPrivilegedPermission("getSlotsMapping");
8862
8863 final long identity = Binder.clearCallingIdentity();
8864 try {
8865 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8866 // All logical slots should have a mapping to a physical slot.
8867 int[] logicalSlotsMapping = new int[phoneCount];
8868 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8869 for (int i = 0; i < slotInfos.length; i++) {
8870 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8871 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8872 }
8873 }
8874 return logicalSlotsMapping;
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008879
8880 /**
8881 * Get the IRadio HAL Version
8882 */
8883 @Override
8884 public int getRadioHalVersion() {
8885 Phone phone = getDefaultPhone();
8886 if (phone == null) return -1;
8887 HalVersion hv = phone.getHalVersion();
8888 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8889 return hv.major * 100 + hv.minor;
8890 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008891
8892 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008893 * Get the current calling package name.
8894 * @return the current calling package name
8895 */
8896 @Override
8897 public String getCurrentPackageName() {
8898 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8899 }
8900
8901 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008902 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8903 * corresponding network requests on a subId.
8904 *
8905 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008906 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008907 * 2) APN is un-metered for this subscription, or
8908 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008909 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008910 *
8911 * @return whether data is allowed for a apn type.
8912 *
8913 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008914 */
8915 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008916 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008917 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8918 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008919
8920 // Now that all security checks passes, perform the operation as ourselves.
8921 final long identity = Binder.clearCallingIdentity();
8922 try {
8923 Phone phone = getPhone(subId);
8924 if (phone == null) return false;
8925
Jack Yu41407ee2019-05-13 16:54:09 -07008926 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008927 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
8932
8933 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008934 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008935 enforceReadPrivilegedPermission("isApnMetered");
8936
8937 // Now that all security checks passes, perform the operation as ourselves.
8938 final long identity = Binder.clearCallingIdentity();
8939 try {
8940 Phone phone = getPhone(subId);
8941 if (phone == null) return true; // By default return true.
8942
Jack Yu41407ee2019-05-13 16:54:09 -07008943 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008944 } finally {
8945 Binder.restoreCallingIdentity(identity);
8946 }
8947 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008948
8949 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008950 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8951 int subscriptionId, IBooleanConsumer resultCallback) {
8952 enforceModifyPermission();
8953 long token = Binder.clearCallingIdentity();
8954 try {
8955 Phone phone = getPhone(subscriptionId);
8956 if (phone == null) {
8957 try {
8958 if (resultCallback != null) {
8959 resultCallback.accept(false);
8960 }
8961 } catch (RemoteException e) {
8962 // ignore
8963 }
8964 return;
8965 }
8966 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8967 Pair.create(specifiers, (x) -> {
8968 try {
8969 if (resultCallback != null) {
8970 resultCallback.accept(x);
8971 }
8972 } catch (RemoteException e) {
8973 // ignore
8974 }
8975 });
8976 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8977 } finally {
8978 Binder.restoreCallingIdentity(token);
8979 }
8980 }
8981
8982 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008983 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8984 TelephonyPermissions
8985 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8986 mApp, subId, "getSystemSelectionChannels");
8987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 List<RadioAccessSpecifier> specifiers =
8991 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8992 null, subId, workSource);
8993 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8994 return specifiers;
8995 } finally {
8996 Binder.restoreCallingIdentity(identity);
8997 }
8998 }
8999
9000 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009001 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009002 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009003 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9004 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9005 if (iccRecords == null) {
9006 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9007 return false;
9008 }
9009 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9010 }
9011
9012 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009013 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9014 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009015 if (callingPackage == null) {
9016 callingPackage = getCurrentPackageName();
9017 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009018 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9019 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009020 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9021 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009022 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9023 }
9024 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9025 Intent intent = new Intent();
9026 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9027 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9028 // Bring up choose default SMS subscription dialog right now
9029 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9030 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9031 mApp.startActivity(intent);
9032 }
chen xud5ca2d52019-05-28 15:20:57 -07009033
9034 @Override
9035 public String getMmsUAProfUrl(int subId) {
9036 //TODO investigate if this API should require proper permission check in R b/133791609
9037 final long identity = Binder.clearCallingIdentity();
9038 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009039 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9040 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9041 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9042 return carrierUAProfUrl;
9043 }
chen xud5ca2d52019-05-28 15:20:57 -07009044 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9045 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9046 } finally {
9047 Binder.restoreCallingIdentity(identity);
9048 }
9049 }
9050
9051 @Override
9052 public String getMmsUserAgent(int subId) {
9053 //TODO investigate if this API should require proper permission check in R b/133791609
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009056 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9057 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9058 if (!TextUtils.isEmpty(carrierUserAgent)) {
9059 return carrierUserAgent;
9060 }
chen xud5ca2d52019-05-28 15:20:57 -07009061 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9062 .getString(com.android.internal.R.string.config_mms_user_agent);
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
9066 }
Jack Yub07d4972019-05-28 16:12:25 -07009067
9068 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009069 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9070 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9071
9072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 Phone phone = getPhone(subscriptionId);
9075 if (phone == null) return false;
9076
9077 switch (policy) {
9078 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9079 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9080 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9081 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9082 default:
9083 throw new IllegalArgumentException(policy + " is not a valid policy");
9084 }
9085 } finally {
9086 Binder.restoreCallingIdentity(identity);
9087 }
9088 }
9089
9090 @Override
9091 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9092 boolean enabled) {
9093 enforceModifyPermission();
9094
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
9097 Phone phone = getPhone(subscriptionId);
9098 if (phone == null) return;
9099
9100 switch (policy) {
9101 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9102 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9103 break;
9104 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9105 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9106 break;
9107 default:
9108 throw new IllegalArgumentException(policy + " is not a valid policy");
9109 }
9110 } finally {
9111 Binder.restoreCallingIdentity(identity);
9112 }
9113 }
9114
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009115 /**
Hall Liub48cf452020-09-25 11:13:49 -07009116 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009117 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9118 * otherwise.
9119 */
9120 @Override
9121 public void setCepEnabled(boolean isCepEnabled) {
9122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9123
9124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9127 for (Phone phone : PhoneFactory.getPhones()) {
9128 Phone defaultPhone = phone.getImsPhone();
9129 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9130 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9131 ImsPhoneCallTracker imsPhoneCallTracker =
9132 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9133 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9134 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9135 + imsPhone.getMsisdn());
9136 }
9137 }
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
9140 }
9141 }
allenwtsu46dcc572020-01-08 18:24:03 +08009142
9143 /**
9144 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9145 *
9146 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9147 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9148 * before being read.
9149 */
9150 @Override
9151 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9152 isCompressed) {
9153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9154 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009155 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9156 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9157 }
9158 if (!isImsAvailableOnDevice()) {
9159 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9160 "IMS not available on device.");
9161 }
9162
9163 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009164 try {
Hui Wang068ab862020-10-31 05:12:53 +00009165 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009168 }
9169 }
zoey chenf95ca592019-12-30 16:11:23 +08009170
9171 @Override
9172 public boolean isIccLockEnabled(int subId) {
9173 enforceReadPrivilegedPermission("isIccLockEnabled");
9174
9175 // Now that all security checks passes, perform the operation as ourselves.
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
9178 Phone phone = getPhone(subId);
9179 if (phone != null && phone.getIccCard() != null) {
9180 return phone.getIccCard().getIccLockEnabled();
9181 } else {
9182 return false;
9183 }
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
9189 /**
zoey chene02881a2019-12-30 16:11:23 +08009190 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009191 *
zoey chene02881a2019-12-30 16:11:23 +08009192 * @return an integer representing the status of IccLock enabled or disabled in the following
9193 * three cases:
9194 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9195 * successfully.
9196 * - Positive number and zero for remaining password attempts.
9197 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009198 *
9199 */
9200 @Override
9201 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9202 enforceModifyPermission();
9203
9204 Phone phone = getPhone(subId);
9205 if (phone == null) {
9206 return 0;
9207 }
9208 // Now that all security checks passes, perform the operation as ourselves.
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9212 new Pair<Boolean, String>(enabled, password), phone, null);
9213 return attemptsRemaining;
9214
9215 } catch (Exception e) {
9216 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9217 } finally {
9218 Binder.restoreCallingIdentity(identity);
9219 }
9220 return 0;
9221 }
9222
9223 /**
9224 * Change the ICC password used in ICC pin lock.
9225 *
zoey chene02881a2019-12-30 16:11:23 +08009226 * @return an integer representing the status of IccLock changed in the following three cases:
9227 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9228 * - Positive number and zero for remaining password attempts.
9229 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009230 *
9231 */
9232 @Override
9233 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9234 enforceModifyPermission();
9235
9236 Phone phone = getPhone(subId);
9237 if (phone == null) {
9238 return 0;
9239 }
9240 // Now that all security checks passes, perform the operation as ourselves.
9241 final long identity = Binder.clearCallingIdentity();
9242 try {
9243 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9244 new Pair<String, String>(oldPassword, newPassword), phone, null);
9245 return attemptsRemaining;
9246
9247 } catch (Exception e) {
9248 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 return 0;
9253 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009254
Peter Wangdafb9ac2020-01-15 14:13:38 -08009255 /**
9256 * Request for receiving user activity notification
9257 */
9258 @Override
9259 public void requestUserActivityNotification() {
9260 if (!mNotifyUserActivity.get()
9261 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9262 mNotifyUserActivity.set(true);
9263 }
9264 }
9265
9266 /**
9267 * Called when userActivity is signalled in the power manager.
9268 * This is safe to call from any thread, with any window manager locks held or not.
9269 */
9270 @Override
9271 public void userActivity() {
9272 // ***************************************
9273 // * Inherited from PhoneWindowManager *
9274 // ***************************************
9275 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9276 // WITH ITS LOCKS HELD.
9277 //
9278 // This code must be VERY careful about the locks
9279 // it acquires.
9280 // In fact, the current code acquires way too many,
9281 // and probably has lurking deadlocks.
9282
9283 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9284 throw new SecurityException("Only the OS may call notifyUserActivity()");
9285 }
9286
9287 if (mNotifyUserActivity.getAndSet(false)) {
9288 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9289 USER_ACTIVITY_NOTIFICATION_DELAY);
9290 }
9291 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009292
Malcolm Chen884180b2020-04-13 11:59:40 -07009293 @Override
9294 public boolean canConnectTo5GInDsdsMode() {
9295 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9296 }
Jack Yud10cdd42020-09-28 20:28:01 -07009297
9298 @Override
9299 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9300 String callingFeatureId) {
9301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9302 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9303 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9304 }
9305
9306 Phone phone = getPhone(subId);
9307 if (phone == null) {
9308 throw new RuntimeException("phone is not available");
9309 }
9310 // Now that all security checks passes, perform the operation as ourselves.
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 return phone.getEquivalentHomePlmns();
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009318
Hui Wang0866fcc2020-10-12 12:14:23 -07009319 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009320 public boolean isRadioInterfaceCapabilitySupported(
9321 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009322 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009323 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009324 if (radioInterfaceCapabilities == null) {
9325 throw new RuntimeException("radio interface capabilities are not available");
9326 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009327 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009328 }
9329 }
9330
9331 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009332 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9333 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009334 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9335 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9336 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9337 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9338 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009339 if (DBG) {
9340 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9341 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9342 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9343 }
9344
9345 if (!SubscriptionManager.isValidSubscriptionId(subId)
9346 || appType < TelephonyManager.APPTYPE_UNKNOWN
9347 || appType > TelephonyManager.APPTYPE_ISIM
9348 || nafUrl == null || securityProtocol == null || callback == null) {
9349 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9350 if (callback != null) {
9351 try {
9352 callback.onAuthenticationFailure(
9353 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9354 } catch (RemoteException exception) {
9355 log("Fail to notify onAuthenticationFailure due to " + exception);
9356 }
9357 return;
9358 }
9359 }
9360
9361 final long token = Binder.clearCallingIdentity();
9362 try {
9363 getGbaManager(subId).bootstrapAuthenticationRequest(
9364 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9365 forceBootStrapping, callback));
9366 } finally {
9367 Binder.restoreCallingIdentity(token);
9368 }
9369 }
9370
Jack Nudelman24d51a52020-11-24 12:08:04 -08009371 /**
9372 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9373 * requested radio power state will actually be set. See {@link
9374 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9375 *
9376 * @param subId the subscription ID of the phone requesting to set the radio power state.
9377 * @param enable {@code true} if trying to turn radio on.
9378 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9379 * false}.
9380 */
9381 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9382 Phone phone = getPhone(subId);
9383 if (phone != null) {
9384 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9385 return true;
9386 }
9387 return false;
9388 }
9389
9390 private int handleDataThrottlingRequest(int subId,
9391 DataThrottlingRequest dataThrottlingRequest) {
9392 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9393 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9394 if (!setRadioPowerForThermal(subId, true)) {
9395 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9396 }
9397
9398 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9399
9400 int thermalMitigationResult =
9401 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9402 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9403 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9404 }
9405 return thermalMitigationResult;
9406 }
9407
9408 /**
9409 * Thermal mitigation request to control functionalities at modem.
9410 *
9411 * @param subId the id of the subscription.
9412 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9413 *
9414 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9415 */
9416 @Override
9417 @ThermalMitigationResult
9418 public int sendThermalMitigationRequest(
9419 int subId,
9420 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9421 enforceModifyPermission();
9422
9423 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9424 final long identity = Binder.clearCallingIdentity();
9425
9426 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9427 try {
9428 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9429 switch (thermalMitigationAction) {
9430 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9431 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009432 handleDataThrottlingRequest(subId,
9433 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009434 break;
9435 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9436 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9437 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9438 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9439 }
9440
9441 // Ensure that radio is on. If not able to power on due to phone being
9442 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9443 if (!setRadioPowerForThermal(subId, true)) {
9444 thermalMitigationResult =
9445 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9446 break;
9447 }
9448
9449 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9450 false);
9451 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9452 break;
9453 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9454 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9455 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9456 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9457 }
9458
9459 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9460 if (registry != null) {
9461 TelephonyConnectionService service =
9462 registry.getTelephonyConnectionService();
9463 Phone phone = getPhone(subId);
9464 if (phone == null) {
9465 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009466 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009467 break;
9468 }
9469
9470 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009471 != TelephonyManager.CALL_STATE_IDLE
9472 || phone.isInEmergencySmsMode() || phone.isInEcm()
9473 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009474 String errorMessage = "Phone state is not valid. call state = "
9475 + PhoneConstantConversions.convertCallState(phone.getState())
9476 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9477 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9478 errorMessage += service == null
9479 ? " TelephonyConnectionService is null"
9480 : " isEmergencyCallPending = "
9481 + service.isEmergencyCallPending();
9482 Log.e(LOG_TAG, errorMessage);
9483 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009484 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009485 break;
9486 }
9487 } else {
9488 thermalMitigationResult =
9489 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9490 break;
9491 }
9492
9493 // Turn radio off. If not able to power off due to phone being unavailable,
9494 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9495 if (!setRadioPowerForThermal(subId, false)) {
9496 thermalMitigationResult =
9497 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9498 break;
9499 }
9500 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009501 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009502 break;
9503 default:
9504 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9505 + "not exist. Requested action: " + thermalMitigationAction);
9506 }
9507 } catch (IllegalArgumentException e) {
9508 throw e;
9509 } catch (Exception e) {
9510 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9511 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9512 } finally {
9513 Binder.restoreCallingIdentity(identity);
9514 }
9515
9516 if (DBG) {
9517 log("thermalMitigationRequest returning with thermalMitigationResult: "
9518 + thermalMitigationResult);
9519 }
9520
9521 return thermalMitigationResult;
9522 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009523
9524 /**
9525 * Set the GbaService Package Name that Telephony will bind to.
9526 *
9527 * @param subId The sim that the GbaService is associated with.
9528 * @param packageName The name of the package to be replaced with.
9529 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9530 */
9531 @Override
9532 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9533 enforceModifyPermission();
9534
9535 final long identity = Binder.clearCallingIdentity();
9536 try {
9537 return getGbaManager(subId).overrideServicePackage(packageName);
9538 } finally {
9539 Binder.restoreCallingIdentity(identity);
9540 }
9541 }
9542
9543 /**
9544 * Return the package name of the currently bound GbaService.
9545 *
9546 * @param subId The sim that the GbaService is associated with.
9547 * @return the package name of the GbaService configuration, null if GBA is not supported.
9548 */
9549 @Override
9550 public String getBoundGbaService(int subId) {
9551 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9552
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
9555 return getGbaManager(subId).getServicePackage();
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
9561 /**
9562 * Set the release time for telephony to unbind GbaService.
9563 *
9564 * @param subId The sim that the GbaService is associated with.
9565 * @param interval The release time to unbind GbaService by millisecond.
9566 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9567 */
9568 @Override
9569 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9570 enforceModifyPermission();
9571
9572 final long identity = Binder.clearCallingIdentity();
9573 try {
9574 return getGbaManager(subId).overrideReleaseTime(interval);
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 /**
9581 * Return the release time for telephony to unbind GbaService.
9582 *
9583 * @param subId The sim that the GbaService is associated with.
9584 * @return The release time to unbind GbaService by millisecond.
9585 */
9586 @Override
9587 public int getGbaReleaseTime(int subId) {
9588 enforceReadPrivilegedPermission("getGbaReleaseTime");
9589
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 return getGbaManager(subId).getReleaseTime();
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
9597
9598 private GbaManager getGbaManager(int subId) {
9599 GbaManager instance = GbaManager.getInstance(subId);
9600 if (instance == null) {
9601 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9602 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9603 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9604 }
9605 return instance;
9606 }
Hui Wang068ab862020-10-31 05:12:53 +00009607
9608 /**
9609 * indicate whether the device and the carrier can support
9610 * RCS VoLTE single registration.
9611 */
9612 @Override
9613 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009614 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9615 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9616 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9617 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009618
9619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9620 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9621 }
9622
9623 final long identity = Binder.clearCallingIdentity();
9624 try {
9625 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9626 if (rpm != null) {
9627 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9628 }
9629 return false;
9630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
9634
9635 /**
9636 * Register RCS provisioning callback.
9637 */
9638 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009639 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009640 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009641 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009642 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009643 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9644 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009645
9646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9647 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9648 }
9649 if (!isImsAvailableOnDevice()) {
9650 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9651 "IMS not available on device.");
9652 }
9653
9654 final long identity = Binder.clearCallingIdentity();
9655 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009656 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009657 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009658 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9659 "Service not available for the subscription.");
9660 }
Hui Wang068ab862020-10-31 05:12:53 +00009661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 /**
9667 * Unregister RCS provisioning callback.
9668 */
9669 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009670 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009671 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009672 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009673 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009674 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9675 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009676
9677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9678 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9679 }
9680 if (!isImsAvailableOnDevice()) {
9681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9682 "IMS not available on device.");
9683 }
9684
9685 final long identity = Binder.clearCallingIdentity();
9686 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009687 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009688 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
9694 /**
9695 * trigger RCS reconfiguration.
9696 */
9697 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009698 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9699 "triggerRcsReconfiguration",
9700 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009701
9702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9703 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9704 }
9705 if (!isImsAvailableOnDevice()) {
9706 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9707 "IMS not available on device.");
9708 }
9709
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
9718 /**
9719 * Provide the client configuration parameters of the RCS application.
9720 */
9721 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009722 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9723 "setRcsClientConfiguration",
9724 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009725
9726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9727 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9728 }
9729 if (!isImsAvailableOnDevice()) {
9730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9731 "IMS not available on device.");
9732 }
9733
9734 final long identity = Binder.clearCallingIdentity();
9735
9736 try {
9737 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9738 if (configBinder == null) {
9739 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9740 } else {
9741 configBinder.setRcsClientConfiguration(rcc);
9742 }
9743 } catch (RemoteException e) {
9744 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749
9750 /**
Hui Wang19a21872021-02-19 20:45:36 -08009751 * Enables or disables the test mode for RCS VoLTE single registration.
9752 */
9753 @Override
9754 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9756 "setRcsSingleRegistrationTestModeEnabled");
9757
9758 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9759 }
9760
9761 /**
9762 * Gets the test mode for RCS VoLTE single registration.
9763 */
9764 @Override
9765 public boolean getRcsSingleRegistrationTestModeEnabled() {
9766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9767 "getRcsSingleRegistrationTestModeEnabled");
9768
9769 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9770 }
9771
9772 /**
Hui Wang068ab862020-10-31 05:12:53 +00009773 * Overrides the config of RCS VoLTE single registration enabled for the device.
9774 */
9775 @Override
9776 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9778 "setDeviceSingleRegistrationEnabledOverride");
9779 enforceModifyPermission();
9780
9781 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9782 : Boolean.parseBoolean(enabledStr);
9783 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009784 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009785 }
9786
9787 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009788 * Sends a device to device communication message. Only usable via shell.
9789 * @param message message to send.
9790 * @param value message value.
9791 */
9792 @Override
9793 public void sendDeviceToDeviceMessage(int message, int value) {
9794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9795 "setCarrierSingleRegistrationEnabledOverride");
9796 enforceModifyPermission();
9797
9798 final long identity = Binder.clearCallingIdentity();
9799 try {
9800 TelephonyConnectionService service =
9801 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9802 if (service == null) {
9803 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9804 return;
9805 }
9806 service.sendTestDeviceToDeviceMessage(message, value);
9807 } finally {
9808 Binder.restoreCallingIdentity(identity);
9809 }
9810 }
9811
9812
9813 /**
Hui Wang068ab862020-10-31 05:12:53 +00009814 * Gets the config of RCS VoLTE single registration enabled for the device.
9815 */
9816 @Override
9817 public boolean getDeviceSingleRegistrationEnabled() {
9818 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9819 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9820 }
9821
9822 /**
9823 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9824 */
9825 @Override
9826 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9828 "setCarrierSingleRegistrationEnabledOverride");
9829 enforceModifyPermission();
9830
9831 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9832 : Boolean.parseBoolean(enabledStr);
9833 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9834 subId, enabled);
9835 }
9836
9837 /**
9838 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9839 */
9840 @Override
9841 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9842 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9843 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9844 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009845
9846 /**
9847 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9848 * their mobile plan.
9849 */
9850 @Override
9851 public String getMobileProvisioningUrl() {
9852 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9853 final long identity = Binder.clearCallingIdentity();
9854 try {
9855 return getDefaultPhone().getMobileProvisioningUrl();
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009860
James.cf Linbcdf8b32021-01-14 16:44:13 +08009861 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009862 * Get the EAB contact from the EAB database.
9863 */
9864 @Override
9865 public String getContactFromEab(String contact) {
9866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9867 enforceModifyPermission();
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
9870 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
9875
9876 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009877 * Remove the EAB contacts from the EAB database.
9878 */
9879 @Override
9880 public int removeContactFromEab(int subId, String contacts) {
9881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9882 enforceModifyPermission();
9883 final long identity = Binder.clearCallingIdentity();
9884 try {
9885 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9886 } finally {
9887 Binder.restoreCallingIdentity(identity);
9888 }
9889 }
9890
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009891 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009892 public boolean getDeviceUceEnabled() {
9893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 return mApp.getDeviceUceEnabled();
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
9901
9902 @Override
9903 public void setDeviceUceEnabled(boolean isEnabled) {
9904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
9907 mApp.setDeviceUceEnabled(isEnabled);
9908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 }
9912
9913 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009914 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9915 String callingPackage) {
9916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9917 mApp, subId, "setSignalStrengthUpdateRequest");
9918
9919 final int callingUid = Binder.getCallingUid();
9920 // Verify that tha callingPackage belongs to the calling UID
9921 mApp.getSystemService(AppOpsManager.class)
9922 .checkPackage(callingUid, callingPackage);
9923
9924 validateSignalStrengthUpdateRequest(request, callingUid);
9925
9926 final long identity = Binder.clearCallingIdentity();
9927 try {
9928 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9929 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9930
9931 if (result instanceof IllegalStateException) {
9932 throw (IllegalStateException) result;
9933 }
9934 } finally {
9935 Binder.restoreCallingIdentity(identity);
9936 }
9937 }
9938
9939 @Override
9940 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9941 String callingPackage) {
9942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9943 mApp, subId, "clearSignalStrengthUpdateRequest");
9944
9945 final int callingUid = Binder.getCallingUid();
9946 // Verify that tha callingPackage belongs to the calling UID
9947 mApp.getSystemService(AppOpsManager.class)
9948 .checkPackage(callingUid, callingPackage);
9949
9950 final long identity = Binder.clearCallingIdentity();
9951 try {
9952 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9953 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9954
9955 if (result instanceof IllegalStateException) {
9956 throw (IllegalStateException) result;
9957 }
9958 } finally {
9959 Binder.restoreCallingIdentity(identity);
9960 }
9961 }
9962
9963 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9964 int callingUid) {
9965 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9966 // phone/system process do not have further restriction on request
9967 return;
9968 }
9969
9970 // Applications has restrictions on how to use the request:
9971 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9972 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9973 // This is not system caller which has been checked above
9974 throw new IllegalArgumentException(
9975 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9976 }
9977
9978 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9979 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9980 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9981 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9982 || info.isEnabled()) {
9983 throw new IllegalArgumentException(
9984 "Only system can set hide fields in SignalThresholdInfo");
9985 }
9986
9987 // Thresholds length for each RAN need in range. This has been validated in
9988 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9989 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9990 final int[] thresholds = info.getThresholds();
9991 Objects.requireNonNull(thresholds);
9992 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9993 || thresholds.length
9994 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9995 throw new IllegalArgumentException(
9996 "thresholds length is out of range: " + thresholds.length);
9997 }
9998 }
9999 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010000
10001 /**
10002 * Prepare TelephonyManager for an unattended reboot. The reboot is
10003 * required to be done shortly after the API is invoked.
10004 */
10005 @Override
10006 @TelephonyManager.PrepareUnattendedRebootResult
10007 public int prepareForUnattendedReboot() {
10008 enforceRebootPermission();
10009
10010 final long identity = Binder.clearCallingIdentity();
10011 try {
10012 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010017}