blob: 023732a1e598f709050078e711bb7fe47e3c50e1 [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;
866 }
867 loge("enableNrDualConnectivity" + ": CommandException: "
868 + ar.exception);
869 } else {
870 loge("enableNrDualConnectivity" + ": Unknown exception");
871 }
872 }
873 notifyRequester(request);
874 break;
875 }
876
SongFerngWang9e060372020-12-21 16:41:52 +0800877 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800878 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800879 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
880 request);
881 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800882 break;
883
SongFerngWang9e060372020-12-21 16:41:52 +0800884 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result; // Integer
889 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530890 // request.result must be set to something non-null
891 // for the calling thread to unblock
892 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800894 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800896 loge("getAllowedNetworkTypesBitmask: CommandException: "
897 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800899 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 }
901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 break;
904
SongFerngWang9e060372020-12-21 16:41:52 +0800905 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800907 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
908 request);
909 Pair<Integer, Long> reasonWithNetworkTypes =
910 (Pair<Integer, Long>) request.argument;
911 getPhoneFromRequest(request).setAllowedNetworkTypes(
912 reasonWithNetworkTypes.first,
913 reasonWithNetworkTypes.second,
914 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 break;
916
SongFerngWang9e060372020-12-21 16:41:52 +0800917 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
918 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 break;
920
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000921 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
922 request = (MainThreadRequest)msg.obj;
923 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000925 break;
926
927 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
928 ar = (AsyncResult)msg.obj;
929 request = (MainThreadRequest)ar.userObj;
930 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700931 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000932 break;
933
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800934 case CMD_SET_VOICEMAIL_NUMBER:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
937 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800938 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
939 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800940 break;
941
942 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
943 handleNullReturnEvent(msg, "setVoicemailNumber");
944 break;
945
Stuart Scott54788802015-03-30 13:18:01 -0700946 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
949 request);
950 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
951 break;
952
953 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
954 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
955 break;
956
Shishir Agrawal302c8692015-06-19 13:49:39 -0700957 case CMD_PERFORM_NETWORK_SCAN:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
960 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
961 break;
962
Hall Liua1acea22020-09-18 19:04:59 -0700963 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700966 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
967 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
968 request.argument;
969 int callForwardingReason = args.first;
970 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800971 break;
Hall Liua1acea22020-09-18 19:04:59 -0700972 }
973 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700976 TelephonyManager.CallForwardingInfoCallback callback =
977 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
978 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800979 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700980 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800981 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
982 for (CallForwardInfo callForwardInfo : callForwardInfos) {
983 // Service Class is a bit mask per 3gpp 27.007. Search for
984 // any service for voice call.
985 if ((callForwardInfo.serviceClass
986 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700987 callForwardingInfo = new CallForwardingInfo(true,
988 callForwardInfo.reason,
989 callForwardInfo.number,
990 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800991 break;
992 }
993 }
994 // Didn't find a call forward info for voice call.
995 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700996 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
997 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800998 }
Hall Liua1acea22020-09-18 19:04:59 -0700999 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001000 } else {
1001 if (ar.result == null) {
1002 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1003 }
1004 if (ar.exception != null) {
1005 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1006 }
Hall Liuae527aa2020-09-29 17:10:18 -07001007 int errorCode = TelephonyManager
1008 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001009 if (ar.exception instanceof CommandException) {
1010 CommandException.Error error =
1011 ((CommandException) (ar.exception)).getCommandError();
1012 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001013 errorCode = TelephonyManager
1014 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001015 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001016 errorCode = TelephonyManager
1017 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001018 }
1019 }
Hall Liua1acea22020-09-18 19:04:59 -07001020 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001021 }
sqian80370722020-01-29 15:02:51 -08001022 break;
Hall Liua1acea22020-09-18 19:04:59 -07001023 }
sqian80370722020-01-29 15:02:51 -08001024
Hall Liua1acea22020-09-18 19:04:59 -07001025 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001028 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001029 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001030 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1031 request.argument).first;
1032 request.phone.setCallForwardingOption(
1033 callForwardingInfoToSet.isEnabled()
1034 ? CommandsInterface.CF_ACTION_ENABLE
1035 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001036 callForwardingInfoToSet.getReason(),
1037 callForwardingInfoToSet.getNumber(),
1038 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1039 break;
Hall Liua1acea22020-09-18 19:04:59 -07001040 }
sqian80370722020-01-29 15:02:51 -08001041
Hall Liua1acea22020-09-18 19:04:59 -07001042 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001045 Consumer<Integer> callback =
1046 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1047 request.argument).second;
1048 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001049 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001050 int errorCode = TelephonyManager.CallForwardingInfoCallback
1051 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001052 if (ar.exception instanceof CommandException) {
1053 CommandException.Error error =
1054 ((CommandException) (ar.exception)).getCommandError();
1055 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001056 errorCode = TelephonyManager.CallForwardingInfoCallback
1057 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001058 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001059 errorCode = TelephonyManager.CallForwardingInfoCallback
1060 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001061 }
1062 }
1063 callback.accept(errorCode);
1064 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001065 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001066 }
sqian80370722020-01-29 15:02:51 -08001067 break;
Hall Liua1acea22020-09-18 19:04:59 -07001068 }
sqian80370722020-01-29 15:02:51 -08001069
Hall Liua1acea22020-09-18 19:04:59 -07001070 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1073 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1074 break;
Hall Liua1acea22020-09-18 19:04:59 -07001075 }
sqian80370722020-01-29 15:02:51 -08001076
Hall Liua1acea22020-09-18 19:04:59 -07001077 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001078 ar = (AsyncResult) msg.obj;
1079 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001080 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001081 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1082 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001083 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001084 // Service Class is a bit mask per 3gpp 27.007.
1085 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001086 if (callForwardResults.length > 1
1087 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001088 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001089 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001090 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1091 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001092 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001093 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001094 }
1095 } else {
1096 if (ar.result == null) {
1097 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1098 }
1099 if (ar.exception != null) {
1100 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1101 }
1102 if (ar.exception instanceof CommandException) {
1103 CommandException.Error error =
1104 ((CommandException) (ar.exception)).getCommandError();
1105 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1106 callForwardingStatus =
1107 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1108 }
1109 }
1110 }
Hall Liua1acea22020-09-18 19:04:59 -07001111 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001112 break;
Hall Liua1acea22020-09-18 19:04:59 -07001113 }
sqian80370722020-01-29 15:02:51 -08001114
Hall Liua1acea22020-09-18 19:04:59 -07001115 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001118 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1119 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001120 break;
Hall Liua1acea22020-09-18 19:04:59 -07001121 }
sqian80370722020-01-29 15:02:51 -08001122
Hall Liua1acea22020-09-18 19:04:59 -07001123 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001126 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1127 Consumer<Integer> callback =
1128 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1129 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001130 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001131 if (ar.exception instanceof CommandException) {
1132 CommandException.Error error =
1133 ((CommandException) (ar.exception)).getCommandError();
1134 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1135 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1136 } else {
1137 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1138 }
1139 } else {
1140 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1141 }
1142 } else {
1143 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1144 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001145 }
sqian80370722020-01-29 15:02:51 -08001146 break;
Hall Liua1acea22020-09-18 19:04:59 -07001147 }
sqian80370722020-01-29 15:02:51 -08001148
Shishir Agrawal302c8692015-06-19 13:49:39 -07001149 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 CellNetworkScanResult cellScanResult;
1153 if (ar.exception == null && ar.result != null) {
1154 cellScanResult = new CellNetworkScanResult(
1155 CellNetworkScanResult.STATUS_SUCCESS,
1156 (List<OperatorInfo>) ar.result);
1157 } else {
1158 if (ar.result == null) {
1159 loge("getCellNetworkScanResults: Empty response");
1160 }
1161 if (ar.exception != null) {
1162 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1163 }
1164 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1165 if (ar.exception instanceof CommandException) {
1166 CommandException.Error error =
1167 ((CommandException) (ar.exception)).getCommandError();
1168 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1169 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1170 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1171 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1172 }
1173 }
1174 cellScanResult = new CellNetworkScanResult(errorCode, null);
1175 }
1176 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001178 break;
1179
1180 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1181 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001182 ManualNetworkSelectionArgument selArg =
1183 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001184 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1185 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001186 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1187 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001188 break;
1189
1190 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001191 ar = (AsyncResult) msg.obj;
1192 request = (MainThreadRequest) ar.userObj;
1193 if (ar.exception == null) {
1194 request.result = true;
1195 } else {
1196 request.result = false;
1197 loge("setNetworkSelectionModeManual " + ar.exception);
1198 }
1199 notifyRequester(request);
1200 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001201 break;
1202
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001203 case CMD_GET_MODEM_ACTIVITY_INFO:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001206 if (defaultPhone != null) {
1207 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001208 } else {
1209 ResultReceiver result = (ResultReceiver) request.argument;
1210 Bundle bundle = new Bundle();
1211 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1212 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1213 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001214 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001215 break;
1216
1217 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1218 ar = (AsyncResult) msg.obj;
1219 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001220 ResultReceiver result = (ResultReceiver) request.argument;
1221
1222 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001223 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001224 // Update the last modem activity info and the result of the request.
1225 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1226 if (isModemActivityInfoValid(info)) {
1227 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1228 int[] txTimeMs = info.getTransmitTimeMillis();
1229 int[] lastModemTxTimeMs = mLastModemActivityInfo
1230 .getTransmitTimeMillis();
1231 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1232 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1233 }
1234 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1235 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1236 + mLastModemActivityInfo.getSleepTimeMillis());
1237 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1238 + mLastModemActivityInfo.getIdleTimeMillis());
1239 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1240 mLastModemActivityInfo.setReceiveTimeMillis(
1241 info.getReceiveTimeMillis()
1242 + mLastModemActivityInfo.getReceiveTimeMillis());
1243 }
1244 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1245 mLastModemActivityInfo.getSleepTimeMillis(),
1246 mLastModemActivityInfo.getIdleTimeMillis(),
1247 mLastModemActivityInfo.getTransmitTimeMillis(),
1248 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001249 } else {
1250 if (ar.result == null) {
1251 loge("queryModemActivityInfo: Empty response");
1252 } else if (ar.exception instanceof CommandException) {
1253 loge("queryModemActivityInfo: CommandException: " +
1254 ar.exception);
1255 } else {
1256 loge("queryModemActivityInfo: Unknown exception");
1257 }
1258 }
sqian1a1be542020-03-05 11:37:28 -08001259 Bundle bundle = new Bundle();
1260 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1261 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001262 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001263 break;
1264
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 case CMD_SET_ALLOWED_CARRIERS:
1266 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001267 CarrierRestrictionRules argument =
1268 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001270 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001271 break;
1272
1273 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1274 ar = (AsyncResult) msg.obj;
1275 request = (MainThreadRequest) ar.userObj;
1276 if (ar.exception == null && ar.result != null) {
1277 request.result = ar.result;
1278 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001279 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1280 if (ar.exception instanceof CommandException) {
1281 loge("setAllowedCarriers: CommandException: " + ar.exception);
1282 CommandException.Error error =
1283 ((CommandException) (ar.exception)).getCommandError();
1284 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1285 request.result =
1286 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1287 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001288 } else {
1289 loge("setAllowedCarriers: Unknown exception");
1290 }
1291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001292 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 break;
1294
1295 case CMD_GET_ALLOWED_CARRIERS:
1296 request = (MainThreadRequest) msg.obj;
1297 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001298 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 break;
1300
1301 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null && ar.result != null) {
1305 request.result = ar.result;
1306 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001307 request.result = new IllegalStateException(
1308 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001309 if (ar.result == null) {
1310 loge("getAllowedCarriers: Empty response");
1311 } else if (ar.exception instanceof CommandException) {
1312 loge("getAllowedCarriers: CommandException: " +
1313 ar.exception);
1314 } else {
1315 loge("getAllowedCarriers: Unknown exception");
1316 }
1317 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001319 break;
1320
Nathan Haroldb3014052017-01-25 15:57:32 -08001321 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1322 ar = (AsyncResult) msg.obj;
1323 request = (MainThreadRequest) ar.userObj;
1324 if (ar.exception == null && ar.result != null) {
1325 request.result = ar.result;
1326 } else {
1327 request.result = new IllegalArgumentException(
1328 "Failed to retrieve Forbidden Plmns");
1329 if (ar.result == null) {
1330 loge("getForbiddenPlmns: Empty response");
1331 } else {
1332 loge("getForbiddenPlmns: Unknown exception");
1333 }
1334 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001335 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001336 break;
1337
1338 case CMD_GET_FORBIDDEN_PLMNS:
1339 request = (MainThreadRequest) msg.obj;
1340 uiccCard = getUiccCardFromRequest(request);
1341 if (uiccCard == null) {
1342 loge("getForbiddenPlmns() UiccCard is null");
1343 request.result = new IllegalArgumentException(
1344 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001345 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001346 break;
1347 }
1348 Integer appType = (Integer) request.argument;
1349 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1350 if (uiccApp == null) {
1351 loge("getForbiddenPlmns() no app with specified type -- "
1352 + appType);
1353 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001354 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001355 break;
1356 } else {
1357 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1358 + " specified type -- " + appType);
1359 }
1360 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1361 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1362 onCompleted);
1363 break;
1364
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001365 case CMD_SWITCH_SLOTS:
1366 request = (MainThreadRequest) msg.obj;
1367 int[] physicalSlots = (int[]) request.argument;
1368 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1369 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1370 break;
1371
1372 case EVENT_SWITCH_SLOTS_DONE:
1373 ar = (AsyncResult) msg.obj;
1374 request = (MainThreadRequest) ar.userObj;
1375 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001376 notifyRequester(request);
1377 break;
1378 case CMD_GET_NETWORK_SELECTION_MODE:
1379 request = (MainThreadRequest) msg.obj;
1380 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1381 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1382 break;
1383
1384 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception != null) {
1388 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1389 } else {
1390 int mode = ((int[]) ar.result)[0];
1391 if (mode == 0) {
1392 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1393 } else {
1394 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1395 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001396 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001397 notifyRequester(request);
1398 break;
1399 case CMD_GET_CDMA_ROAMING_MODE:
1400 request = (MainThreadRequest) msg.obj;
1401 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1402 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1403 break;
1404 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
1407 if (ar.exception != null) {
1408 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1409 } else {
1410 request.result = ((int[]) ar.result)[0];
1411 }
1412 notifyRequester(request);
1413 break;
1414 case CMD_SET_CDMA_ROAMING_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1417 int mode = (int) request.argument;
1418 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1419 break;
1420 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 request.result = ar.exception == null;
1424 notifyRequester(request);
1425 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001426 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1427 request = (MainThreadRequest) msg.obj;
1428 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1429 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1430 break;
1431 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1432 ar = (AsyncResult) msg.obj;
1433 request = (MainThreadRequest) ar.userObj;
1434 if (ar.exception != null) {
1435 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1436 } else {
1437 request.result = ((int[]) ar.result)[0];
1438 }
1439 notifyRequester(request);
1440 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001441 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1444 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001445 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1446 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001447 break;
1448 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 request.result = ar.exception == null;
1452 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001453 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 case CMD_GET_ALL_CELL_INFO:
1455 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001456 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001457 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 case EVENT_GET_ALL_CELL_INFO_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001462 // If a timeout occurs, the response will be null
1463 request.result = (ar.exception == null && ar.result != null)
1464 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 synchronized (request) {
1466 request.notifyAll();
1467 }
1468 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001469 case CMD_REQUEST_CELL_INFO_UPDATE:
1470 request = (MainThreadRequest) msg.obj;
1471 request.phone.requestCellInfoUpdate(request.workSource,
1472 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1473 break;
1474 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1475 ar = (AsyncResult) msg.obj;
1476 request = (MainThreadRequest) ar.userObj;
1477 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1478 try {
1479 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001481 cb.onError(
1482 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1483 ar.exception.getClass().getName(),
1484 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001485 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001486 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001487 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001488 } else {
1489 // use the result as returned
1490 cb.onCellInfo((List<CellInfo>) ar.result);
1491 }
1492 } catch (RemoteException re) {
1493 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1494 }
1495 break;
Sarah Chincc055732020-11-18 13:39:35 -08001496 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 request = (MainThreadRequest) msg.obj;
1498 WorkSource ws = (WorkSource) request.argument;
1499 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001500 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 break;
Sarah Chincc055732020-11-18 13:39:35 -08001502 }
1503 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 ar = (AsyncResult) msg.obj;
1505 request = (MainThreadRequest) ar.userObj;
1506 if (ar.exception == null) {
1507 request.result = ar.result;
1508 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001509 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001510 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001511 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001512 }
1513
1514 synchronized (request) {
1515 request.notifyAll();
1516 }
1517 break;
Sarah Chincc055732020-11-18 13:39:35 -08001518 }
chen xu6dac5ab2018-10-26 17:39:23 -07001519 case CMD_MODEM_REBOOT:
1520 request = (MainThreadRequest) msg.obj;
1521 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001522 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001523 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001524 case EVENT_CMD_MODEM_REBOOT_DONE:
1525 handleNullReturnEvent(msg, "rebootModem");
1526 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001527 case CMD_REQUEST_ENABLE_MODEM:
1528 request = (MainThreadRequest) msg.obj;
1529 boolean enable = (boolean) request.argument;
1530 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001531 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001532 PhoneConfigurationManager.getInstance()
1533 .enablePhone(request.phone, enable, onCompleted);
1534 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001535 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001536 ar = (AsyncResult) msg.obj;
1537 request = (MainThreadRequest) ar.userObj;
1538 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001539 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001540 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001541 if ((boolean) request.result) {
1542 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1543 updateModemStateMetrics();
1544 } else {
1545 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1546 + ar.exception);
1547 }
1548 notifyRequester(request);
1549 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001550 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001551 case CMD_GET_MODEM_STATUS:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1554 PhoneConfigurationManager.getInstance()
1555 .getPhoneStatusFromModem(request.phone, onCompleted);
1556 break;
1557 case EVENT_GET_MODEM_STATUS_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 int id = request.phone.getPhoneId();
1561 if (ar.exception == null && ar.result != null) {
1562 request.result = ar.result;
1563 //update the cache as modem status has changed
1564 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1565 (boolean) request.result);
1566 } else {
1567 // Return true if modem status cannot be retrieved. For most cases,
1568 // modem status is on. And for older version modems, GET_MODEM_STATUS
1569 // and disable modem are not supported. Modem is always on.
1570 // TODO: this should be fixed in R to support a third
1571 // status UNKNOWN b/131631629
1572 request.result = true;
1573 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1574 + ar.exception);
1575 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001576 notifyRequester(request);
1577 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001578 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1579 request = (MainThreadRequest) msg.obj;
1580 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1581 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1582 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1583 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1584 break;
1585 }
1586 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
1589 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1590 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1591 args.second.accept(ar.exception == null);
1592 notifyRequester(request);
1593 break;
1594 }
Sarah Chincc055732020-11-18 13:39:35 -08001595 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1596 request = (MainThreadRequest) msg.obj;
1597 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1598 Phone phone = getPhoneFromRequest(request);
1599 if (phone != null) {
1600 phone.getSystemSelectionChannels(onCompleted);
1601 } else {
1602 loge("getSystemSelectionChannels: No phone object");
1603 request.result = new ArrayList<RadioAccessSpecifier>();
1604 notifyRequester(request);
1605 }
1606 break;
1607 }
1608 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 if (ar.exception == null && ar.result != null) {
1612 request.result = ar.result;
1613 } else {
1614 request.result = new IllegalArgumentException(
1615 "Failed to retrieve system selection channels");
1616 if (ar.result == null) {
1617 loge("getSystemSelectionChannels: Empty response");
1618 } else {
1619 loge("getSystemSelectionChannels: Unknown exception");
1620 }
1621 }
1622 notifyRequester(request);
1623 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001624 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception == null && ar.result != null) {
1628 request.result = ar.result;
1629 } else {
1630 request.result = -1;
1631 loge("Failed to set Forbidden Plmns");
1632 if (ar.result == null) {
1633 loge("setForbidenPlmns: Empty response");
1634 } else if (ar.exception != null) {
1635 loge("setForbiddenPlmns: Exception: " + ar.exception);
1636 request.result = -1;
1637 } else {
1638 loge("setForbiddenPlmns: Unknown exception");
1639 }
1640 }
1641 notifyRequester(request);
1642 break;
1643 case CMD_SET_FORBIDDEN_PLMNS:
1644 request = (MainThreadRequest) msg.obj;
1645 uiccCard = getUiccCardFromRequest(request);
1646 if (uiccCard == null) {
1647 loge("setForbiddenPlmns: UiccCard is null");
1648 request.result = -1;
1649 notifyRequester(request);
1650 break;
1651 }
1652 Pair<Integer, List<String>> setFplmnsArgs =
1653 (Pair<Integer, List<String>>) request.argument;
1654 appType = setFplmnsArgs.first;
1655 List<String> fplmns = setFplmnsArgs.second;
1656 uiccApp = uiccCard.getApplicationByType(appType);
1657 if (uiccApp == null) {
1658 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1659 request.result = -1;
1660 loge("Failed to get UICC App");
1661 notifyRequester(request);
1662 } else {
1663 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1664 ((SIMRecords) uiccApp.getIccRecords())
1665 .setForbiddenPlmns(onCompleted, fplmns);
1666 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001667 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001668 case CMD_ERASE_MODEM_CONFIG:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1671 defaultPhone.eraseModemConfig(onCompleted);
1672 break;
1673 case EVENT_ERASE_MODEM_CONFIG_DONE:
1674 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001675 break;
zoey chenf95ca592019-12-30 16:11:23 +08001676
1677 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1680 Pair<String, String> changed = (Pair<String, String>) request.argument;
1681 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1682 changed.first, changed.second, onCompleted);
1683 break;
1684 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 if (ar.exception == null) {
1688 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001689 // If the operation is successful, update the PIN storage
1690 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1691 int phoneId = getPhoneFromRequest(request).getPhoneId();
1692 UiccController.getInstance().getPinStorage()
1693 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001694 } else {
1695 request.result = msg.arg1;
1696 }
1697 notifyRequester(request);
1698 break;
1699
Michele Berionned9fbae52020-11-13 02:36:59 +00001700 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1703 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1704 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1705 enabled.first, enabled.second, onCompleted);
1706 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001707 }
zoey chenf95ca592019-12-30 16:11:23 +08001708 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001713 // If the operation is successful, update the PIN storage
1714 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1715 int phoneId = getPhoneFromRequest(request).getPhoneId();
1716 if (enabled.first) {
1717 UiccController.getInstance().getPinStorage()
1718 .storePin(enabled.second, phoneId);
1719 } else {
1720 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1721 }
zoey chenf95ca592019-12-30 16:11:23 +08001722 } else {
1723 request.result = msg.arg1;
1724 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001725
1726
zoey chenf95ca592019-12-30 16:11:23 +08001727 notifyRequester(request);
1728 break;
1729
Peter Wangdafb9ac2020-01-15 14:13:38 -08001730 case MSG_NOTIFY_USER_ACTIVITY:
1731 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001732 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001733 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1734 getDefaultPhone().getContext().sendBroadcastAsUser(
1735 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1736 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001737
1738 case CMD_SET_DATA_THROTTLING: {
1739 request = (MainThreadRequest) msg.obj;
1740 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1741 DataThrottlingRequest dataThrottlingRequest =
1742 (DataThrottlingRequest) request.argument;
1743 Phone phone = getPhoneFromRequest(request);
1744 if (phone != null) {
1745 phone.setDataThrottling(onCompleted,
1746 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1747 dataThrottlingRequest.getCompletionDurationMillis());
1748 } else {
1749 loge("setDataThrottling: No phone object");
1750 request.result =
1751 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1752 notifyRequester(request);
1753 }
1754
1755 break;
1756 }
1757 case EVENT_SET_DATA_THROTTLING_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760
1761 if (ar.exception == null) {
1762 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1763 } else if (ar.exception instanceof CommandException) {
1764 loge("setDataThrottling: CommandException: " + ar.exception);
1765 CommandException.Error error =
1766 ((CommandException) (ar.exception)).getCommandError();
1767
1768 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1769 request.result = TelephonyManager
1770 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1771 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1772 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1773 } else {
1774 request.result =
1775 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1776 }
1777 } else {
1778 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1779 }
1780 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1781 notifyRequester(request);
1782 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001783
1784 case CMD_SET_SIM_POWER: {
1785 request = (MainThreadRequest) msg.obj;
1786 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1787 request = (MainThreadRequest) msg.obj;
1788 int stateToSet =
1789 ((Pair<Integer, IIntegerConsumer>)
1790 request.argument).first;
1791 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1792 break;
1793 }
1794 case EVENT_SET_SIM_POWER_DONE: {
1795 ar = (AsyncResult) msg.obj;
1796 request = (MainThreadRequest) ar.userObj;
1797 IIntegerConsumer callback =
1798 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1799 if (ar.exception != null) {
1800 loge("setSimPower exception: " + ar.exception);
1801 int errorCode = TelephonyManager.CallForwardingInfoCallback
1802 .RESULT_ERROR_UNKNOWN;
1803 if (ar.exception instanceof CommandException) {
1804 CommandException.Error error =
1805 ((CommandException) (ar.exception)).getCommandError();
1806 if (error == CommandException.Error.SIM_ERR) {
1807 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1808 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1809 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1810 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1811 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1812 } else {
1813 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1814 }
1815 }
1816 try {
1817 callback.accept(errorCode);
1818 } catch (RemoteException e) {
1819 // Ignore if the remote process is no longer available to call back.
1820 Log.w(LOG_TAG, "setSimPower: callback not available.");
1821 }
1822 } else {
1823 try {
1824 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1825 } catch (RemoteException e) {
1826 // Ignore if the remote process is no longer available to call back.
1827 Log.w(LOG_TAG, "setSimPower: callback not available.");
1828 }
1829 }
1830 break;
1831 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001832 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1833 request = (MainThreadRequest) msg.obj;
1834
1835 final Phone phone = getPhoneFromRequest(request);
1836 if (phone == null || phone.getServiceStateTracker() == null) {
1837 request.result = new IllegalStateException("Phone or SST is null");
1838 notifyRequester(request);
1839 break;
1840 }
1841
1842 Pair<Integer, SignalStrengthUpdateRequest> pair =
1843 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1844 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1845 request);
1846 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1847 request.subId, pair.first /*callingUid*/,
1848 pair.second /*request*/, onCompleted);
1849 break;
1850 }
1851 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 // request.result will be the exception of ar if present, true otherwise.
1855 // Be cautious not to leave result null which will wait() forever
1856 request.result = ar.exception != null ? ar.exception : true;
1857 notifyRequester(request);
1858 break;
1859 }
1860 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1861 request = (MainThreadRequest) msg.obj;
1862
1863 Phone phone = getPhoneFromRequest(request);
1864 if (phone == null || phone.getServiceStateTracker() == null) {
1865 request.result = new IllegalStateException("Phone or SST is null");
1866 notifyRequester(request);
1867 break;
1868 }
1869
1870 Pair<Integer, SignalStrengthUpdateRequest> pair =
1871 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1872 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1873 request);
1874 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1875 request.subId, pair.first /*callingUid*/,
1876 pair.second /*request*/, onCompleted);
1877 break;
1878 }
1879 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1880 ar = (AsyncResult) msg.obj;
1881 request = (MainThreadRequest) ar.userObj;
1882 request.result = ar.exception != null ? ar.exception : true;
1883 notifyRequester(request);
1884 break;
1885 }
Jordan Liud5366d92020-11-24 14:50:34 -08001886
Michele Berionned9fbae52020-11-13 02:36:59 +00001887 case CMD_PREPARE_UNATTENDED_REBOOT:
1888 request = (MainThreadRequest) msg.obj;
1889 request.result =
1890 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1891 notifyRequester(request);
1892 break;
1893
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 default:
1895 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1896 break;
1897 }
1898 }
Jake Hambye994d462014-02-03 13:10:13 -08001899
Pengquan Menga1bb6272018-09-06 09:59:22 -07001900 private void notifyRequester(MainThreadRequest request) {
1901 synchronized (request) {
1902 request.notifyAll();
1903 }
1904 }
1905
Jake Hambye994d462014-02-03 13:10:13 -08001906 private void handleNullReturnEvent(Message msg, String command) {
1907 AsyncResult ar = (AsyncResult) msg.obj;
1908 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1909 if (ar.exception == null) {
1910 request.result = true;
1911 } else {
1912 request.result = false;
1913 if (ar.exception instanceof CommandException) {
1914 loge(command + ": CommandException: " + ar.exception);
1915 } else {
1916 loge(command + ": Unknown exception");
1917 }
1918 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001919 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
1923 /**
1924 * Posts the specified command to be executed on the main thread,
1925 * waits for the request to complete, and returns the result.
1926 * @see #sendRequestAsync
1927 */
1928 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001929 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1930 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001931 }
1932
1933 /**
1934 * Posts the specified command to be executed on the main thread,
1935 * waits for the request to complete, and returns the result.
1936 * @see #sendRequestAsync
1937 */
1938 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1939 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001940 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
1943 /**
1944 * Posts the specified command to be executed on the main thread,
1945 * waits for the request to complete, and returns the result.
1946 * @see #sendRequestAsync
1947 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001948 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001949 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1950 }
1951
1952 /**
1953 * Posts the specified command to be executed on the main thread,
1954 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1955 * if not timeout or null otherwise.
1956 * @see #sendRequestAsync
1957 */
1958 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1959 long timeoutInMs) {
1960 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001961 }
1962
1963 /**
1964 * Posts the specified command to be executed on the main thread,
1965 * waits for the request to complete, and returns the result.
1966 * @see #sendRequestAsync
1967 */
Nathan Harold92bed182018-10-12 18:16:49 -07001968 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001969 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001970 }
1971
1972 /**
1973 * Posts the specified command to be executed on the main thread,
1974 * waits for the request to complete, and returns the result.
1975 * @see #sendRequestAsync
1976 */
1977 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001978 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1979 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001980 }
1981
1982 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001983 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1984 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1985 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001986 * @see #sendRequestAsync
1987 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001988 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1989 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1991 throw new RuntimeException("This method will deadlock if called from the main thread.");
1992 }
1993
Nathan Harold92bed182018-10-12 18:16:49 -07001994 MainThreadRequest request = null;
1995 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1996 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1997 } else if (phone != null) {
1998 request = new MainThreadRequest(argument, phone, workSource);
1999 } else {
2000 request = new MainThreadRequest(argument, subId, workSource);
2001 }
2002
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 Message msg = mMainThreadHandler.obtainMessage(command, request);
2004 msg.sendToTarget();
2005
Rambo Wang0f050d82021-02-12 11:43:36 -08002006
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002008 if (timeoutInMs >= 0) {
2009 // Wait for at least timeoutInMs before returning null request result
2010 long now = SystemClock.elapsedRealtime();
2011 long deadline = now + timeoutInMs;
2012 while (request == null && now < deadline) {
2013 try {
2014 request.wait(deadline - now);
2015 } catch (InterruptedException e) {
2016 // Do nothing, go back and check if request is completed or timeout
2017 } finally {
2018 now = SystemClock.elapsedRealtime();
2019 }
2020 }
2021 } else {
2022 // Wait for the request to complete
2023 while (request.result == null) {
2024 try {
2025 request.wait();
2026 } catch (InterruptedException e) {
2027 // Do nothing, go back and wait until the request is complete
2028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 }
2030 }
2031 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002032 if (request.result == null) {
2033 Log.wtf(LOG_TAG,
2034 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 return request.result;
2037 }
2038
2039 /**
2040 * Asynchronous ("fire and forget") version of sendRequest():
2041 * Posts the specified command to be executed on the main thread, and
2042 * returns immediately.
2043 * @see #sendRequest
2044 */
2045 private void sendRequestAsync(int command) {
2046 mMainThreadHandler.sendEmptyMessage(command);
2047 }
2048
2049 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002050 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002051 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002052 */
2053 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002054 sendRequestAsync(command, argument, null, null);
2055 }
2056
2057 /**
2058 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2059 * @see {@link #sendRequest(int,Object)}
2060 */
2061 private void sendRequestAsync(
2062 int command, Object argument, Phone phone, WorkSource workSource) {
2063 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002064 Message msg = mMainThreadHandler.obtainMessage(command, request);
2065 msg.sendToTarget();
2066 }
2067
2068 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 * Initialize the singleton PhoneInterfaceManager instance.
2070 * This is only done once, at startup, from PhoneApp.onCreate().
2071 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002072 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 synchronized (PhoneInterfaceManager.class) {
2074 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002075 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 } else {
2077 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2078 }
2079 return sInstance;
2080 }
2081 }
2082
2083 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002084 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002087 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002088 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2090 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002091 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002092 mTelephonySharedPreferences =
2093 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002094 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002095 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002096 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002097 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002098
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 publish();
2100 }
2101
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002102 private Phone getDefaultPhone() {
2103 Phone thePhone = getPhone(getDefaultSubscription());
2104 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2105 }
2106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 private void publish() {
2108 if (DBG) log("publish: " + this);
2109
Peter Wangc035ce42020-01-08 21:00:22 -08002110 TelephonyFrameworkInitializer
2111 .getTelephonyServiceManager()
2112 .getTelephonyServiceRegisterer()
2113 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
Stuart Scott584921c2015-01-15 17:10:34 -08002116 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002117 if (request.phone != null) {
2118 return request.phone;
2119 } else {
2120 return getPhoneFromSubId(request.subId);
2121 }
2122 }
2123
2124 private Phone getPhoneFromSubId(int subId) {
2125 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2126 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002127 }
2128
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002129 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2130 Phone phone = getPhoneFromRequest(request);
2131 return phone == null ? null :
2132 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2133 }
2134
Wink Saville36469e72014-06-11 15:17:00 -07002135 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002136 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002137 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002140 private void sendEraseModemConfig(Phone phone) {
2141 if (phone != null) {
2142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2143 mApp, phone.getSubId(), "eraseModemConfig");
2144 final long identity = Binder.clearCallingIdentity();
2145 try {
2146 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2147 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2148 } finally {
2149 Binder.restoreCallingIdentity(identity);
2150 }
2151 }
2152 }
2153
Peter Wang050bb052020-01-13 23:33:09 -08002154 private boolean isImsAvailableOnDevice() {
2155 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2156 if (pm == null) {
2157 // For some reason package manger is not available.. This will fail internally anyway,
2158 // so do not throw error and allow.
2159 return true;
2160 }
2161 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2162 }
2163
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002165 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
Wink Savilleb564aae2014-10-23 10:18:09 -07002168 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 if (DBG) log("dial: " + number);
2170 // No permission check needed here: This is just a wrapper around the
2171 // ACTION_DIAL intent, which is available to any app since it puts up
2172 // the UI before it does anything.
2173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 String url = createTelUrl(number);
2177 if (url == null) {
2178 return;
2179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181 // PENDING: should we just silently fail if phone is offhook or ringing?
2182 PhoneConstants.State state = mCM.getState(subId);
2183 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2184 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2185 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2186 mApp.startActivity(intent);
2187 }
2188 } finally {
2189 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191 }
2192
2193 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002194 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002195 }
2196
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 if (DBG) log("call: " + number);
2199
2200 // This is just a wrapper around the ACTION_CALL intent, but we still
2201 // need to do a permission check since we're calling startActivity()
2202 // from the context of the phone app.
2203 enforceCallPermission();
2204
Jordan Liu1617b712019-07-10 15:06:26 -07002205 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 != AppOpsManager.MODE_ALLOWED) {
2207 return;
2208 }
2209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 String url = createTelUrl(number);
2213 if (url == null) {
2214 return;
2215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002217 boolean isValid = false;
2218 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2219 if (slist != null) {
2220 for (SubscriptionInfo subInfoRecord : slist) {
2221 if (subInfoRecord.getSubscriptionId() == subId) {
2222 isValid = true;
2223 break;
2224 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002225 }
Wink Saville08874612014-08-31 19:19:58 -07002226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 if (!isValid) {
2228 return;
2229 }
Wink Saville08874612014-08-31 19:19:58 -07002230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2232 intent.putExtra(SUBSCRIPTION_KEY, subId);
2233 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2234 mApp.startActivity(intent);
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
2237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
Wink Savilleb564aae2014-10-23 10:18:09 -07002240 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002241 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002242 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2243 }
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002246 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002247 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2248 }
2249
Wink Savilleb564aae2014-10-23 10:18:09 -07002250 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252
2253 final long identity = Binder.clearCallingIdentity();
2254 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002255 Phone phone = getPhone(subId);
2256 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 checkSimPin.start();
2258 return checkSimPin.unlockSim(null, pin);
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
2261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
Wink Savilleb564aae2014-10-23 10:18:09 -07002264 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002269 Phone phone = getPhone(subId);
2270 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 checkSimPuk.start();
2272 return checkSimPuk.unlockSim(puk, pin);
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
2278 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002279 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 * a synchronous one.
2281 */
2282 private static class UnlockSim extends Thread {
2283
2284 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002285 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286
2287 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002288 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2289 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290
2291 // For replies from SimCard interface
2292 private Handler mHandler;
2293
2294 // For async handler to identify request type
2295 private static final int SUPPLY_PIN_COMPLETE = 100;
2296
Michele Berionned9fbae52020-11-13 02:36:59 +00002297 UnlockSim(int phoneId, IccCard simCard) {
2298 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 mSimCard = simCard;
2300 }
2301
2302 @Override
2303 public void run() {
2304 Looper.prepare();
2305 synchronized (UnlockSim.this) {
2306 mHandler = new Handler() {
2307 @Override
2308 public void handleMessage(Message msg) {
2309 AsyncResult ar = (AsyncResult) msg.obj;
2310 switch (msg.what) {
2311 case SUPPLY_PIN_COMPLETE:
2312 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2313 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002314 mRetryCount = msg.arg1;
2315 if (ar.exception != null) {
2316 if (ar.exception instanceof CommandException &&
2317 ((CommandException)(ar.exception)).getCommandError()
2318 == CommandException.Error.PASSWORD_INCORRECT) {
2319 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002320 } //When UiccCardApp dispose,handle message and return exception
2321 else if (ar.exception instanceof CommandException &&
2322 ((CommandException) (ar.exception)).getCommandError()
2323 == CommandException.Error.ABORTED) {
2324 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002325 } else {
2326 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2327 }
2328 } else {
2329 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 mDone = true;
2332 UnlockSim.this.notifyAll();
2333 }
2334 break;
2335 }
2336 }
2337 };
2338 UnlockSim.this.notifyAll();
2339 }
2340 Looper.loop();
2341 }
2342
2343 /*
2344 * Use PIN or PUK to unlock SIM card
2345 *
2346 * If PUK is null, unlock SIM card with PIN
2347 *
2348 * If PUK is not null, unlock SIM card with PUK and set PIN code
2349 */
Wink Saville9de0f752013-10-22 19:04:03 -07002350 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351
2352 while (mHandler == null) {
2353 try {
2354 wait();
2355 } catch (InterruptedException e) {
2356 Thread.currentThread().interrupt();
2357 }
2358 }
2359 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2360
2361 if (puk == null) {
2362 mSimCard.supplyPin(pin, callback);
2363 } else {
2364 mSimCard.supplyPuk(puk, pin, callback);
2365 }
2366
2367 while (!mDone) {
2368 try {
2369 Log.d(LOG_TAG, "wait for done");
2370 wait();
2371 } catch (InterruptedException e) {
2372 // Restore the interrupted status
2373 Thread.currentThread().interrupt();
2374 }
2375 }
2376 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002377 int[] resultArray = new int[2];
2378 resultArray[0] = mResult;
2379 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002380
2381 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2382 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2383 }
2384
Wink Saville9de0f752013-10-22 19:04:03 -07002385 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 }
2387 }
2388
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002389 /**
2390 * This method has been removed due to privacy and stability concerns.
2391 */
2392 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002394 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2395 return;
Wink Saville36469e72014-06-11 15:17:00 -07002396 }
2397
Nathan Harold1f889d82020-06-04 17:05:26 -07002398 @Override
2399 public void updateServiceLocationWithPackageName(String callingPackage) {
2400 mApp.getSystemService(AppOpsManager.class)
2401 .checkPackage(Binder.getCallingUid(), callingPackage);
2402
Nathan Haroldf096d982020-11-18 17:18:06 -08002403 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002404 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2405 // Callers targeting S have no business invoking this method.
2406 return;
2407 }
2408
2409 LocationAccessPolicy.LocationPermissionResult locationResult =
2410 LocationAccessPolicy.checkLocationPermission(mApp,
2411 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2412 .setCallingPackage(callingPackage)
2413 .setCallingFeatureId(null)
2414 .setCallingPid(Binder.getCallingPid())
2415 .setCallingUid(Binder.getCallingUid())
2416 .setMethod("updateServiceLocation")
2417 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2419 .build());
2420 // Apps that lack location permission have no business calling this method;
2421 // however, because no permission was declared in the public API, denials must
2422 // all be "soft".
2423 switch (locationResult) {
2424 case DENIED_HARD: /* fall through */
2425 case DENIED_SOFT:
2426 return;
2427 }
2428
2429 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 final long identity = Binder.clearCallingIdentity();
2431 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002432 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002434 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002442 @Override
2443 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002444 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002447
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002448 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2450 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2451 callingFeatureId);
2452 }
2453
2454 @Deprecated
2455 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002457 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2458 }
2459
2460 @Override
2461 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2462 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002464 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 return false;
2466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 return isRadioOnForSubscriber(subId);
2471 } finally {
2472 Binder.restoreCallingIdentity(identity);
2473 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002474 }
2475
2476 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
2480 if (phone != null) {
2481 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2482 } else {
2483 return false;
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
2490 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002491 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
Wink Saville36469e72014-06-11 15:17:00 -07002493
Wink Savilleb564aae2014-10-23 10:18:09 -07002494 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
2500 if (phone != null) {
2501 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2502 }
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002505 }
Wink Saville36469e72014-06-11 15:17:00 -07002506 }
2507
2508 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002509 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002510 }
2511
Wink Savilleb564aae2014-10-23 10:18:09 -07002512 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 final Phone phone = getPhone(subId);
2518 if (phone == null) {
2519 return false;
2520 }
2521 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2522 toggleRadioOnOffForSubscriber(subId);
2523 }
2524 return true;
2525 } finally {
2526 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 }
Wink Saville36469e72014-06-11 15:17:00 -07002529
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002530 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002531 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002532 /*
2533 * If any of the Radios are available, it will need to be
2534 * shutdown. So return true if any Radio is available.
2535 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2539 Phone phone = PhoneFactory.getPhone(i);
2540 if (phone != null && phone.isRadioAvailable()) return true;
2541 }
2542 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2543 return false;
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002546 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002547 }
2548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002550 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 enforceModifyPermission();
2552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2556 logv("Shutting down Phone " + i);
2557 shutdownRadioUsingPhoneId(i);
2558 }
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002561 }
2562 }
2563
2564 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002565 Phone phone = PhoneFactory.getPhone(phoneId);
2566 if (phone != null && phone.isRadioAvailable()) {
2567 phone.shutdownRadio();
2568 }
2569 }
2570
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2577 if (defaultPhone != null) {
2578 defaultPhone.setRadioPower(turnOn);
2579 return true;
2580 } else {
2581 loge("There's no default phone.");
2582 return false;
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002586 }
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
2595 if (phone != null) {
2596 phone.setRadioPower(turnOn);
2597 return true;
2598 } else {
2599 return false;
2600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
2605
Wink Saville36469e72014-06-11 15:17:00 -07002606 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 public boolean enableDataConnectivity() {
2609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610
2611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 int subId = mSubscriptionController.getDefaultDataSubId();
2614 final Phone phone = getPhone(subId);
2615 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002616 phone.getDataEnabledSettings().setDataEnabled(
2617 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 return true;
2619 } else {
2620 return false;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Wink Saville36469e72014-06-11 15:17:00 -07002627 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 public boolean disableDataConnectivity() {
2630 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631
2632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 int subId = mSubscriptionController.getDefaultDataSubId();
2635 final Phone phone = getPhone(subId);
2636 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002637 phone.getDataEnabledSettings().setDataEnabled(
2638 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 return true;
2640 } else {
2641 return false;
2642 }
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002649 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 final Phone phone = getPhone(subId);
2653 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002654 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 } else {
2656 return false;
2657 }
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
2663 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002664 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002665 }
2666
pkanwarae03a6b2016-11-06 20:37:09 -08002667 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 enforceCallPermission();
2669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2673 return;
2674 }
2675 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2676 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
2679 }
pkanwar32d516d2016-10-14 19:37:38 -07002680 };
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2688 return false;
2689 }
2690 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002697 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002700 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 Phone phone = PhoneFactory.getPhone(slotIndex);
2704 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2705 PhoneConstantConversions.convertCallState(phone.getState());
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 }
2710
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002712 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002713 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2714 }
2715
2716 @Override
2717 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002720 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 if (phone != null) {
2722 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2723 } else {
2724 return PhoneConstantConversions.convertDataState(
2725 PhoneConstants.DataState.DISCONNECTED);
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002733 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002734 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2735 }
2736
2737 @Override
2738 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002741 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 if (phone != null) {
2743 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2744 } else {
2745 return TelephonyManager.DATA_ACTIVITY_NONE;
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 }
2751
2752 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002753 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002755 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002756
2757 LocationAccessPolicy.LocationPermissionResult locationResult =
2758 LocationAccessPolicy.checkLocationPermission(mApp,
2759 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2760 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002761 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002762 .setCallingPid(Binder.getCallingPid())
2763 .setCallingUid(Binder.getCallingUid())
2764 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002765 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002766 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2767 .build());
2768 switch (locationResult) {
2769 case DENIED_HARD:
2770 throw new SecurityException("Not allowed to access cell location");
2771 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002772 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2773 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002776 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002780 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002781 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
Svetoslav64fad262015-04-14 14:35:21 -07002785 }
2786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 @Override
Jack Yu01425032020-02-22 19:38:58 -08002788 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002789 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2790 // registered cell info, so return a NULL country instead.
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002793 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2794 // Get default phone in this case.
2795 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2796 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002797 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002799 if (phone == null) return "";
2800 ServiceStateTracker sst = phone.getServiceStateTracker();
2801 if (sst == null) return "";
2802 LocaleTracker lt = sst.getLocaleTracker();
2803 if (lt == null) return "";
2804 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2805 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2806 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002807 } finally {
2808 Binder.restoreCallingIdentity(identity);
2809 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 }
2811
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002812 /**
2813 * This method was removed due to potential issues caused by performing partial
2814 * updates of service state, and lack of a credible use case.
2815 *
2816 * This has the ability to break the telephony implementation by disabling notification of
2817 * changes in device connectivity. DO NOT USE THIS!
2818 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 public void enableLocationUpdates() {
2821 mApp.enforceCallingOrSelfPermission(
2822 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 }
2824
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002825 /**
2826 * This method was removed due to potential issues caused by performing partial
2827 * updates of service state, and lack of a credible use case.
2828 *
2829 * This has the ability to break the telephony implementation by disabling notification of
2830 * changes in device connectivity. DO NOT USE THIS!
2831 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 @Override
2833 public void disableLocationUpdates() {
2834 mApp.enforceCallingOrSelfPermission(
2835 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
2837
2838 @Override
2839 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002840 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2841 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002842 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002843 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2844 throw new SecurityException(
2845 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2846 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002847
Jordan Liu1617b712019-07-10 15:06:26 -07002848 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2850 return null;
2851 }
Svetoslav64fad262015-04-14 14:35:21 -07002852
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002853 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002855 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002856 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857
Nathan Haroldf180aac2018-06-01 18:43:55 -07002858 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2859 for (CellInfo ci : info) {
2860 if (ci instanceof CellInfoGsm) {
2861 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2862 } else if (ci instanceof CellInfoWcdma) {
2863 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002866 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
2868
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002869 private List<CellInfo> getCachedCellInfo() {
2870 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2871 for (Phone phone : PhoneFactory.getPhones()) {
2872 List<CellInfo> info = phone.getAllCellInfo();
2873 if (info != null) cellInfos.addAll(info);
2874 }
2875 return cellInfos;
2876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877
2878 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002879 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002880 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002881 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002882
2883 LocationAccessPolicy.LocationPermissionResult locationResult =
2884 LocationAccessPolicy.checkLocationPermission(mApp,
2885 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2886 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002887 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002888 .setCallingPid(Binder.getCallingPid())
2889 .setCallingUid(Binder.getCallingUid())
2890 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002891 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002892 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2893 .build());
2894 switch (locationResult) {
2895 case DENIED_HARD:
2896 throw new SecurityException("Not allowed to access cell info");
2897 case DENIED_SOFT:
2898 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 }
2900
Nathan Haroldf096d982020-11-18 17:18:06 -08002901 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002902 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2903 return getCachedCellInfo();
2904 }
2905
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002906 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002907 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2911 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002912 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002913 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 if (info != null) cellInfos.addAll(info);
2915 }
2916 return cellInfos;
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
2920 }
2921
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002922 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002923 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2924 String callingFeatureId) {
2925 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2926 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002927 }
2928
2929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002930 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2931 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002932 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002933 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002934 }
2935
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002936 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2937 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002938 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002939 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002940
2941 LocationAccessPolicy.LocationPermissionResult locationResult =
2942 LocationAccessPolicy.checkLocationPermission(mApp,
2943 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2944 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002945 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002946 .setCallingPid(Binder.getCallingPid())
2947 .setCallingUid(Binder.getCallingUid())
2948 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002949 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2950 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002951 .build());
2952 switch (locationResult) {
2953 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002954 if (TelephonyPermissions
2955 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002956 // Safetynet logging for b/154934934
2957 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2958 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002959 throw new SecurityException("Not allowed to access cell info");
2960 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002961 if (TelephonyPermissions
2962 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002963 // Safetynet logging for b/154934934
2964 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2965 }
Nathan Harold5320c422019-05-09 10:26:08 -07002966 try {
2967 cb.onCellInfo(new ArrayList<CellInfo>());
2968 } catch (RemoteException re) {
2969 // Drop without consequences
2970 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002971 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002972 }
2973
Nathan Harolda939a962019-05-09 10:13:47 -07002974
2975 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002976 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2977
2978 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2979 }
2980
2981 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002982 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002983 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002988 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Shishir Agrawala9f32182016-04-12 12:00:16 -07002994 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002995 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002996 Phone phone = PhoneFactory.getPhone(slotIndex);
2997 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002998 return null;
2999 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003000 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003001 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003002 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003003 return null;
3004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 return phone.getImei();
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003012 }
3013
3014 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003015 public String getTypeAllocationCodeForSlot(int slotIndex) {
3016 Phone phone = PhoneFactory.getPhone(slotIndex);
3017 String tac = null;
3018 if (phone != null) {
3019 String imei = phone.getImei();
3020 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3021 }
3022 return tac;
3023 }
3024
3025 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003026 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 Phone phone = PhoneFactory.getPhone(slotIndex);
3028 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003029 return null;
3030 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031
Jeff Davidson913390f2018-02-23 17:11:49 -08003032 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003033 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003034 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003035 return null;
3036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 return phone.getMeid();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
Jack Yu2af8d712017-03-15 17:14:14 -07003044 }
3045
3046 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003047 public String getManufacturerCodeForSlot(int slotIndex) {
3048 Phone phone = PhoneFactory.getPhone(slotIndex);
3049 String manufacturerCode = null;
3050 if (phone != null) {
3051 String meid = phone.getMeid();
3052 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3053 }
3054 return manufacturerCode;
3055 }
3056
3057 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003058 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3059 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003060 Phone phone = PhoneFactory.getPhone(slotIndex);
3061 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003062 return null;
3063 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003064 int subId = phone.getSubId();
3065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003066 mApp, subId, callingPackage, callingFeatureId,
3067 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003068 return null;
3069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 return phone.getDeviceSvn();
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003077 }
3078
fionaxu43304da2017-11-27 22:51:16 -08003079 @Override
3080 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 final Phone phone = getPhone(subId);
3084 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
fionaxu43304da2017-11-27 22:51:16 -08003088 }
3089
3090 @Override
3091 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 final Phone phone = getPhone(subId);
3095 return phone == null ? null : phone.getCarrierName();
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
fionaxu43304da2017-11-27 22:51:16 -08003099 }
3100
calvinpanffe225e2018-11-01 19:43:06 +08003101 @Override
chen xu0026ca62019-03-06 15:28:50 -08003102 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 final Phone phone = getPhone(subId);
3106 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003107 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003108 } finally {
3109 Binder.restoreCallingIdentity(identity);
3110 }
3111 }
3112
3113 @Override
chen xu0026ca62019-03-06 15:28:50 -08003114 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003118 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
chen xu651eec72018-11-11 19:03:44 -08003124 @Override
chen xu864e11c2018-12-06 22:10:03 -08003125 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3126 if (!isSubscriptionMccMnc) {
3127 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3128 }
chen xu651eec72018-11-11 19:03:44 -08003129 final Phone phone = PhoneFactory.getPhone(slotIndex);
3130 if (phone == null) {
3131 return TelephonyManager.UNKNOWN_CARRIER_ID;
3132 }
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 //
3142 // Internal helper methods.
3143 //
3144
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003145 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3147 *
3148 * @throws SecurityException if the caller does not have the required permission
3149 */
3150 private void enforceModifyPermission() {
3151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3152 }
3153
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003154 /**
3155 * Make sure the caller is system.
3156 *
3157 * @throws SecurityException if the caller is not system.
3158 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003159 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003160 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3161 throw new SecurityException("Caller must be system");
3162 }
3163 }
3164
Shuo Qianf2b2df42019-11-13 17:43:31 -08003165 private void enforceActiveEmergencySessionPermission() {
3166 mApp.enforceCallingOrSelfPermission(
3167 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3168 }
3169
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 /**
3171 * Make sure the caller has the CALL_PHONE permission.
3172 *
3173 * @throws SecurityException if the caller does not have the required permission
3174 */
3175 private void enforceCallPermission() {
3176 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3177 }
3178
paulhu423b5f22019-08-23 19:17:33 +08003179 private void enforceSettingsPermission() {
3180 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003181 }
3182
Michele Berionned9fbae52020-11-13 02:36:59 +00003183 private void enforceRebootPermission() {
3184 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3185 }
3186
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 private String createTelUrl(String number) {
3188 if (TextUtils.isEmpty(number)) {
3189 return null;
3190 }
3191
Jake Hambye994d462014-02-03 13:10:13 -08003192 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194
Ihab Awadf9e92732013-12-05 18:02:52 -08003195 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3197 }
3198
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003199 private static void logv(String msg) {
3200 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3201 }
3202
Ihab Awadf9e92732013-12-05 18:02:52 -08003203 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3205 }
3206
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003209 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003213 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 final Phone phone = PhoneFactory.getPhone(slotIndex);
3217 if (phone == null) {
3218 return PhoneConstants.PHONE_TYPE_NONE;
3219 } else {
3220 return phone.getPhoneType();
3221 }
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 }
3226
3227 /**
3228 * Returns the CDMA ERI icon index to display
3229 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003230 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003231 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3232 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3233 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003234 }
3235
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003237 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3238 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003240 mApp, subId, callingPackage, callingFeatureId,
3241 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003242 return -1;
3243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244
3245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 final Phone phone = getPhone(subId);
3248 if (phone != null) {
3249 return phone.getCdmaEriIconIndex();
3250 } else {
3251 return -1;
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
3258 /**
3259 * Returns the CDMA ERI icon mode,
3260 * 0 - ON
3261 * 1 - FLASHING
3262 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003263 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003264 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3265 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3266 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003267 }
3268
Sanket Padawe356d7632015-06-22 14:03:32 -07003269 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003270 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3271 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003273 mApp, subId, callingPackage, callingFeatureId,
3274 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003275 return -1;
3276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 final Phone phone = getPhone(subId);
3281 if (phone != null) {
3282 return phone.getCdmaEriIconMode();
3283 } else {
3284 return -1;
3285 }
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003289 }
3290
3291 /**
3292 * Returns the CDMA ERI text,
3293 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003294 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003295 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3296 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3297 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003298 }
3299
Sanket Padawe356d7632015-06-22 14:03:32 -07003300 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003301 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3302 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003304 mApp, subId, callingPackage, callingFeatureId,
3305 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003306 return null;
3307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 final Phone phone = getPhone(subId);
3312 if (phone != null) {
3313 return phone.getCdmaEriText();
3314 } else {
3315 return null;
3316 }
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320 }
3321
3322 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003323 * Returns the CDMA MDN.
3324 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003325 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003326 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3328 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 return phone.getLine1Number();
3335 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 return null;
3338 }
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003341 }
3342 }
3343
3344 /**
3345 * Returns the CDMA MIN.
3346 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003347 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003348 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3350 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 final Phone phone = getPhone(subId);
3355 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3356 return phone.getCdmaMin();
3357 } else {
3358 return null;
3359 }
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003362 }
3363 }
3364
Hall Liud892bec2018-11-30 14:51:45 -08003365 @Override
3366 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3367 INumberVerificationCallback callback, String callingPackage) {
3368 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3369 != PERMISSION_GRANTED) {
3370 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3371 }
3372 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3373
3374 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3375 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003376 throw new SecurityException("Calling package must be configured in the device config: "
3377 + "calling package: " + callingPackage
3378 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003379 }
3380
3381 if (range == null) {
3382 throw new NullPointerException("Range must be non-null");
3383 }
3384
3385 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003386 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003387
3388 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3389 }
3390
Junda Liuca05d5d2014-08-14 22:36:34 -07003391 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 * Returns true if CDMA provisioning needs to run.
3393 */
3394 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 final long identity = Binder.clearCallingIdentity();
3396 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003397 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
3402
3403 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003404 * Sets the voice mail number of a given subId.
3405 */
3406 @Override
3407 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003408 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3409 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3414 new Pair<String, String>(alphaTag, number), new Integer(subId));
3415 return success;
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003419 }
3420
Ta-wei Yen87c49842016-05-13 21:19:52 -07003421 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003422 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3423 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003424 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3425 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003426 if (!TextUtils.equals(callingPackage, systemDialer)) {
3427 throw new SecurityException("caller must be system dialer");
3428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429
3430 final long identity = Binder.clearCallingIdentity();
3431 try {
3432 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3433 if (phoneAccountHandle == null) {
3434 return null;
3435 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003436 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003439 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003440 }
3441
3442 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003443 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3444 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003447 mApp, subId, callingPackage, callingFeatureId,
3448 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003449 return null;
3450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003452 final long identity = Binder.clearCallingIdentity();
3453 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003454 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003458 }
3459
3460 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003461 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3462 VisualVoicemailSmsFilterSettings settings) {
3463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003468 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469 } finally {
3470 Binder.restoreCallingIdentity(identity);
3471 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003472 }
3473
3474 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003475 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003481 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003485 }
3486
3487 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003488 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3489 String callingPackage, int subId) {
3490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003495 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496 } finally {
3497 Binder.restoreCallingIdentity(identity);
3498 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003499 }
3500
3501 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003502 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003508 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003512 }
3513
3514 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003515 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3516 String callingAttributionTag, int subId, String number, int port, String text,
3517 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003519 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003520 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003521 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003522 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3523 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003524 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003525
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003526 /**
fionaxu0152e512016-11-14 13:36:14 -08003527 * Sets the voice activation state of a given subId.
3528 */
3529 @Override
3530 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3532 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 final Phone phone = getPhone(subId);
3537 if (phone != null) {
3538 phone.setVoiceActivationState(activationState);
3539 } else {
3540 loge("setVoiceActivationState fails with invalid subId: " + subId);
3541 }
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003544 }
3545 }
3546
3547 /**
3548 * Sets the data activation state of a given subId.
3549 */
3550 @Override
3551 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3553 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 if (phone != null) {
3559 phone.setDataActivationState(activationState);
3560 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003561 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562 }
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003565 }
3566 }
3567
3568 /**
3569 * Returns the voice activation state of a given subId.
3570 */
3571 @Override
3572 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574
fionaxu0152e512016-11-14 13:36:14 -08003575 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 if (phone != null) {
3579 return phone.getVoiceActivationState();
3580 } else {
3581 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003585 }
3586 }
3587
3588 /**
3589 * Returns the data activation state of a given subId.
3590 */
3591 @Override
3592 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594
fionaxu0152e512016-11-14 13:36:14 -08003595 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 if (phone != null) {
3599 return phone.getDataActivationState();
3600 } else {
3601 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003605 }
3606 }
3607
3608 /**
Wink Saville36469e72014-06-11 15:17:00 -07003609 * Returns the unread count of voicemails for a subId
3610 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003611 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003612 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3613 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003615 mApp, subId, callingPackage, callingFeatureId,
3616 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003617 return 0;
3618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 final Phone phone = getPhone(subId);
3622 if (phone != null) {
3623 return phone.getVoiceMessageCount();
3624 } else {
3625 return 0;
3626 }
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003630 }
3631
3632 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003633 * returns true, if the device is in a state where both voice and data
3634 * are supported simultaneously. This can change based on location or network condition.
3635 */
3636 @Override
3637 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 final Phone phone = getPhone(subId);
3641 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003645 }
3646
3647 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003648 * Send the dialer code if called from the current default dialer or the caller has
3649 * carrier privilege.
3650 * @param inputCode The dialer code to send
3651 */
3652 @Override
3653 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003655 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003656 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3657 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003658 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003659 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
fionaxu235cc5e2017-03-06 22:25:57 -08003669 }
3670
Pengquan Menga1bb6272018-09-06 09:59:22 -07003671 @Override
3672 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003673 TelephonyPermissions
3674 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3675 mApp, subId, "getNetworkSelectionMode");
3676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 if (!isActiveSubscription(subId)) {
3679 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3680 }
3681 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003685 }
3686
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003688 public boolean isInEmergencySmsMode() {
3689 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 for (Phone phone : PhoneFactory.getPhones()) {
3693 if (phone.isInEmergencySmsMode()) {
3694 return true;
3695 }
3696 }
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
3700 return false;
3701 }
3702
shilu366312e2019-12-17 09:28:10 -08003703 /**
3704 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3705 * @param subId The subscription to use to check the configuration.
3706 * @param c The callback that will be used to send the result.
3707 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003708 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003709 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3710 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003711 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3712 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003713
Brad Ebinger77b832e2019-10-17 17:03:22 -07003714 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3715 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3716 "IMS not available on device.");
3717 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 final long token = Binder.clearCallingIdentity();
3719 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003721 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (ImsException e) {
3724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 } finally {
3726 Binder.restoreCallingIdentity(token);
3727 }
3728 }
3729
shilu366312e2019-12-17 09:28:10 -08003730 /**
3731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3732 * @param subId The subscription to use to check the configuration.
3733 * @param c The callback that will be used to send the result.
3734 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003736 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003737 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3738 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003739 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3740 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3741 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003742 final long token = Binder.clearCallingIdentity();
3743 try {
3744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3745 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3746 .removeRegistrationCallbackForSubscription(c, subId);
3747 } catch (ImsException e) {
3748 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3749 + "is inactive, ignoring unregister.");
3750 // If the subscription is no longer active, just return, since the callback
3751 // will already have been removed internally.
3752 } finally {
3753 Binder.restoreCallingIdentity(token);
3754 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 }
3756
Brad Ebinger774ba362019-10-22 17:36:18 -07003757 /**
3758 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3759 */
3760 @Override
3761 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3762 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3763 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3765 "IMS not available on device.");
3766 }
3767 final long token = Binder.clearCallingIdentity();
3768 try {
3769 Phone phone = getPhone(subId);
3770 if (phone == null) {
3771 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3772 + subId + "'");
3773 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3774 }
3775 phone.getImsRegistrationState(regState -> {
3776 try {
3777 consumer.accept((regState == null)
3778 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3779 } catch (RemoteException e) {
3780 // Ignore if the remote process is no longer available to call back.
3781 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3782 }
3783 });
3784 } finally {
3785 Binder.restoreCallingIdentity(token);
3786 }
3787 }
3788
3789 /**
3790 * Get the transport type for the IMS service registration state.
3791 */
3792 @Override
3793 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003794 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3795 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003796 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3797 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3798 "IMS not available on device.");
3799 }
3800 final long token = Binder.clearCallingIdentity();
3801 try {
3802 Phone phone = getPhone(subId);
3803 if (phone == null) {
3804 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3805 + subId + "'");
3806 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3807 }
3808 phone.getImsRegistrationTech(regTech -> {
3809 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3810 int regTechConverted = (regTech == null)
3811 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3812 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3813 regTechConverted);
3814 try {
3815 consumer.accept(regTechConverted);
3816 } catch (RemoteException e) {
3817 // Ignore if the remote process is no longer available to call back.
3818 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3819 }
3820 });
3821 } finally {
3822 Binder.restoreCallingIdentity(token);
3823 }
3824 }
3825
shilu366312e2019-12-17 09:28:10 -08003826 /**
3827 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3828 * @param subId The subscription to use to check the configuration.
3829 * @param c The callback that will be used to send the result.
3830 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003832 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3833 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003834 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3835 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003836 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3837 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3838 "IMS not available on device.");
3839 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3841 final long token = Binder.clearCallingIdentity();
3842 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003843 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003845 } catch (ImsException e) {
3846 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 } finally {
3848 Binder.restoreCallingIdentity(token);
3849 }
3850 }
3851
shilu366312e2019-12-17 09:28:10 -08003852 /**
3853 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3854 * @param subId The subscription to use to check the configuration.
3855 * @param c The callback that will be used to send the result.
3856 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003858 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003859 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3860 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3862 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3863 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003864
3865 final long token = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3868 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003869 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003870 } catch (ImsException e) {
3871 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3872 + "is inactive, ignoring unregister.");
3873 // If the subscription is no longer active, just return, since the callback
3874 // will already have been removed internally.
3875 } finally {
3876 Binder.restoreCallingIdentity(token);
3877 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 }
3879
3880 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003881 public boolean isCapable(int subId, int capability, int regTech) {
3882 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3884 final long token = Binder.clearCallingIdentity();
3885 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003886 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003888 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3890 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003892 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3893 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 } finally {
3895 Binder.restoreCallingIdentity(token);
3896 }
3897 }
3898
3899 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003900 public boolean isAvailable(int subId, int capability, int regTech) {
3901 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 final long token = Binder.clearCallingIdentity();
3903 try {
3904 Phone phone = getPhone(subId);
3905 if (phone == null) return false;
3906 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003907 } catch (com.android.ims.ImsException e) {
3908 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3909 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 } finally {
3911 Binder.restoreCallingIdentity(token);
3912 }
3913 }
3914
Brad Ebinger77b832e2019-10-17 17:03:22 -07003915 /**
3916 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3917 * subscription.
3918 * @param subId The subscription to use to check the configuration.
3919 * @param callback The callback that will be used to send the result.
3920 * @param capability The MmTelFeature capability that will be used to send the result.
3921 * @param transportType The transport type of the MmTelFeature capability.
3922 */
3923 @Override
3924 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3925 int transportType) {
3926 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3927 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3928 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3929 "IMS not available on device.");
3930 }
3931 final long token = Binder.clearCallingIdentity();
3932 try {
3933 int slotId = getSlotIndex(subId);
3934 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3935 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3936 + subId + "'");
3937 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3938 }
3939 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3940 transportType, aBoolean -> {
3941 try {
3942 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3943 } catch (RemoteException e) {
3944 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3945 + "running. Ignore");
3946 }
3947 });
3948 } finally {
3949 Binder.restoreCallingIdentity(token);
3950 }
3951 }
3952
shilu366312e2019-12-17 09:28:10 -08003953 /**
3954 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3955 * @param subId The subscription to use to check the configuration.
3956 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 @Override
3958 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003959 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3960 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003961
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3963 final long token = Binder.clearCallingIdentity();
3964 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003965 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003967 } catch (ImsException e) {
3968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 } finally {
3970 Binder.restoreCallingIdentity(token);
3971 }
3972 }
3973
3974 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003975 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003977 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003981 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003983 } catch (ImsException e) {
3984 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
3988 }
3989
shilu366312e2019-12-17 09:28:10 -08003990 /**
3991 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3992 * @param subId The subscription to use to check the configuration.
3993 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003995 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003996 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3997 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004001 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4002 } catch (ImsException e) {
4003 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 } finally {
4005 Binder.restoreCallingIdentity(identity);
4006 }
4007 }
4008
4009 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004010 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004012 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004016 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004017 } catch (ImsException e) {
4018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
4022 }
4023
shilu366312e2019-12-17 09:28:10 -08004024 /**
4025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 @Override
4029 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004030 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4031 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004035 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004037 } catch (ImsException e) {
4038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
4042 }
4043
4044 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004045 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004047 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004051 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004052 } catch (ImsException e) {
4053 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
4057 }
4058
shilu366312e2019-12-17 09:28:10 -08004059 /**
4060 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4061 * @param subId The subscription to use to check the configuration.
4062 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 @Override
4064 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004065 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4066 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004070 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004072 } catch (ImsException e) {
4073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
4077 }
4078
4079 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004080 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004082 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004086 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004088 } catch (ImsException e) {
4089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
4093 }
4094
4095 @Override
4096 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4098 "setVoWiFiNonPersistent");
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004102 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004103 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004104 } catch (ImsException e) {
4105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
4109 }
4110
shilu366312e2019-12-17 09:28:10 -08004111 /**
4112 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4113 * @param subId The subscription to use to check the configuration.
4114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 @Override
4116 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004117 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4118 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004122 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (ImsException e) {
4125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
4131 @Override
4132 public void setVoWiFiModeSetting(int subId, int mode) {
4133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4134 "setVoWiFiModeSetting");
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (ImsException e) {
4141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
4145 }
4146
4147 @Override
4148 public int getVoWiFiRoamingModeSetting(int subId) {
4149 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004153 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004155 } catch (ImsException e) {
4156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
4160 }
4161
4162 @Override
4163 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4165 "setVoWiFiRoamingModeSetting");
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004169 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004171 } catch (ImsException e) {
4172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
4176 }
4177
4178 @Override
4179 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4181 "setRttCapabilityEnabled");
4182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
shilu366312e2019-12-17 09:28:10 -08004193 /**
4194 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4195 * @param subId The subscription to use to check the configuration.
4196 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 @Override
4198 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004199 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4200 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004204 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
4211 }
4212
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004213 @Override
4214 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4215 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4216 final long identity = Binder.clearCallingIdentity();
4217 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004218 if (!isImsAvailableOnDevice()) {
4219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4220 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004221 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004224 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
4230 }
4231
4232 @Override
4233 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4234 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4235 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004236 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4237 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4238 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004239 try {
4240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004241 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004242 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004244 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4245 + "is inactive, ignoring unregister.");
4246 // If the subscription is no longer active, just return, since the callback will already
4247 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
4251 }
4252
allenwtsu99c623b2020-01-03 18:24:23 +08004253
4254 private void checkModifyPhoneStatePermission(int subId, String message) {
4255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4256 message);
4257 }
4258
4259 private boolean isImsProvisioningRequired(int subId, int capability,
4260 boolean isMmtelCapability) {
4261 Phone phone = getPhone(subId);
4262 if (phone == null) {
4263 loge("phone instance null for subid " + subId);
4264 return false;
4265 }
4266 if (isMmtelCapability) {
4267 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4268 return false;
4269 }
4270 } else {
4271 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4272 return false;
4273 }
4274 }
4275 return true;
4276 }
4277
4278 @Override
4279 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4280 boolean isProvisioned) {
4281 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4286 if (!isImsProvisioningRequired(subId, capability, false)) {
4287 return;
4288 }
4289
4290 // this capability requires provisioning, route to the correct API.
4291 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4292 switch (capability) {
4293 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4294 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4295 ims.setEabProvisioned(isProvisioned);
4296 break;
4297 default: {
4298 throw new IllegalArgumentException("Tried to set provisioning for "
4299 + "rcs capability '" + capability + "', which does not require "
4300 + "provisioning.");
4301 }
4302 }
4303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306
4307 }
4308
4309
4310 @Override
4311 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4312 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4316 if (!isImsProvisioningRequired(subId, capability, false)) {
4317 return true;
4318 }
4319
4320 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4321 switch (capability) {
4322 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4323 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4324 return ims.isEabProvisionedOnDevice();
4325
4326 default: {
4327 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4328 + "capability '" + capability + "', which does not require "
4329 + "provisioning.");
4330 }
4331 }
4332
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004338 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004339 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4340 boolean isProvisioned) {
4341 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4342 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4343 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4344 }
allenwtsu99c623b2020-01-03 18:24:23 +08004345 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
4348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004349 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004350 return;
4351 }
4352
4353 // this capability requires provisioning, route to the correct API.
4354 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4355 switch (capability) {
4356 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4357 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4358 ims.setVolteProvisioned(isProvisioned);
4359 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4360 ims.setWfcProvisioned(isProvisioned);
4361 }
4362 break;
4363 }
4364 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4365 // There is currently no difference in VT provisioning type.
4366 ims.setVtProvisioned(isProvisioned);
4367 break;
4368 }
4369 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4370 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4371 // change the capability of the feature instead if needed.
4372 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4373 == isProvisioned) {
4374 // No change in provisioning.
4375 return;
4376 }
4377 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4378 try {
4379 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004381 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4382 + ", Exception" + e.getMessage());
4383 }
4384 break;
4385 }
4386 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004387 throw new IllegalArgumentException("Tried to set provisioning for "
4388 + "MmTel capability '" + capability + "', which does not require "
4389 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004390 }
4391 }
4392
4393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
4396 }
4397
4398 @Override
4399 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4400 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4401 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4402 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4403 }
4404 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
4407 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004408 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004409 return true;
4410 }
4411
4412 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4413 switch (capability) {
4414 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4415 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4416 return ims.isVolteProvisionedOnDevice();
4417 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4418 return ims.isWfcProvisionedOnDevice();
4419 }
4420 // This should never happen, since we are checking tech above to make sure it
4421 // is either LTE or IWLAN.
4422 throw new IllegalArgumentException("Invalid radio technology for voice "
4423 + "capability.");
4424 }
4425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4426 // There is currently no difference in VT provisioning type.
4427 return ims.isVtProvisionedOnDevice();
4428 }
4429 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4430 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4431 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4432 }
4433 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004434 throw new IllegalArgumentException(
4435 "Tried to get provisioning for MmTel capability '" + capability
4436 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437 }
4438 }
4439
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
4443 }
4444
4445 @Override
4446 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4447 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4448 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4449 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4450 }
4451 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4452 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4453 return (provisionedBits & capability) > 0;
4454 }
4455
4456 @Override
4457 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4458 boolean isProvisioned) {
4459 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4460 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4461 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4462 }
4463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4464 "setProvisioningStatusForCapability");
4465 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4466 // If the current provisioning status for capability already matches isProvisioned,
4467 // do nothing.
4468 if (((provisionedBits & capability) > 0) == isProvisioned) {
4469 return;
4470 }
4471 if (isProvisioned) {
4472 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4473 } else {
4474 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4475 }
4476 }
4477
4478 /**
4479 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4480 * technology. The bitfield should mirror the bitfield defined by
4481 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4482 */
4483 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4484 String key = getMmTelProvisioningKey(subId, tech);
4485 // Default is no capabilities are provisioned.
4486 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4487 }
4488
4489 /**
4490 * Sets the MmTel capability provisioning bitfield (defined by
4491 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4492 * technology specified.
4493 *
4494 * Note: This is a synchronous command and should not be called on UI thread.
4495 */
4496 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4497 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4498 String key = getMmTelProvisioningKey(subId, tech);
4499 editor.putInt(key, newField);
4500 editor.commit();
4501 }
4502
4503 private static String getMmTelProvisioningKey(int subId, int tech) {
4504 // resulting key is provision_ims_mmtel_{subId}_{tech}
4505 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4506 }
4507
4508 /**
4509 * Query CarrierConfig to see if the specified capability requires provisioning for the
4510 * carrier associated with the subscription id.
4511 */
4512 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4513 int capability) {
4514 CarrierConfigManager configManager = new CarrierConfigManager(context);
4515 PersistableBundle c = configManager.getConfigForSubId(subId);
4516 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004517 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4519 false);
4520 boolean requireVoiceVtProvisioning = c.getBoolean(
4521 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4522
4523 // First check to make sure that the capability requires provisioning.
4524 switch (capability) {
4525 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4526 // intentional fallthrough
4527 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4528 if (requireVoiceVtProvisioning) {
4529 // Voice and Video requires provisioning
4530 return true;
4531 }
4532 break;
4533 }
4534 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4535 if (requireUtProvisioning) {
4536 // UT requires provisioning
4537 return true;
4538 }
4539 break;
4540 }
4541 }
4542 return false;
4543 }
4544
allenwtsu99c623b2020-01-03 18:24:23 +08004545 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4546 int capability) {
4547 CarrierConfigManager configManager = new CarrierConfigManager(context);
4548 PersistableBundle c = configManager.getConfigForSubId(subId);
4549
4550 boolean requireRcsProvisioning = c.getBoolean(
4551 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4552
4553 // First check to make sure that the capability requires provisioning.
4554 switch (capability) {
4555 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4556 // intentional fallthrough
4557 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4558 if (requireRcsProvisioning) {
4559 // OPTION or PRESENCE requires provisioning
4560 return true;
4561 }
4562 break;
4563 }
4564 }
4565 return false;
4566 }
4567
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004568 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004569 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004570 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4571 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4572 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004573 enforceReadPrivilegedPermission("getImsProvisioningInt");
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
4576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004577 int slotId = getSlotIndex(subId);
4578 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4579 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4580 + subId + "' for key:" + key);
4581 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4582 }
4583 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004585 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4586 + subId + "' for key:" + key);
4587 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004588 } finally {
4589 Binder.restoreCallingIdentity(identity);
4590 }
4591 }
4592
4593 @Override
4594 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004595 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4596 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4597 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004598 enforceReadPrivilegedPermission("getImsProvisioningString");
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004602 int slotId = getSlotIndex(subId);
4603 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4604 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4605 + subId + "' for key:" + key);
4606 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4607 }
4608 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004609 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004610 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4611 + subId + "' for key:" + key);
4612 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
4616 }
4617
4618 @Override
4619 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004620 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4621 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4622 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4624 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 int slotId = getSlotIndex(subId);
4629 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4630 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4631 + subId + "' for key:" + key);
4632 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4633 }
4634 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004636 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4637 + "' for key:" + key);
4638 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
4644 @Override
4645 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4647 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4648 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4650 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 int slotId = getSlotIndex(subId);
4655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4656 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4657 + subId + "' for key:" + key);
4658 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4659 }
4660 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4663 + "' for key:" + key);
4664 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004670 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004671 int slotId = SubscriptionManager.getSlotIndex(subId);
4672 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4674 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004675 }
4676 return slotId;
4677 }
4678
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004679 private int getSlotIndex(int subId) {
4680 int slotId = SubscriptionManager.getSlotIndex(subId);
4681 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4682 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4683 }
4684 return slotId;
4685 }
4686
Wink Saville36469e72014-06-11 15:17:00 -07004687 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004688 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004689 */
4690 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004691 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4692 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004693 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004694 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004695 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004696 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004697 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004698 mApp, subId, callingPackage, callingFeatureId,
4699 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004700 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4701 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 final Phone phone = getPhone(subId);
4706 if (phone != null) {
4707 return phone.getServiceState().getDataNetworkType();
4708 } else {
4709 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4710 }
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004714 }
4715
4716 /**
4717 * Returns the data network type
4718 */
4719 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004720 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4721 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4722 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004723 }
4724
4725 /**
4726 * Returns the data network type for a subId
4727 */
4728 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004729 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4730 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004732 mApp, subId, callingPackage, callingFeatureId,
4733 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004734 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4735 }
4736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 final Phone phone = getPhone(subId);
4740 if (phone != null) {
4741 return phone.getServiceState().getDataNetworkType();
4742 } else {
4743 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4744 }
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004748 }
4749
4750 /**
Wink Saville36469e72014-06-11 15:17:00 -07004751 * Returns the Voice network type for a subId
4752 */
4753 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004754 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004757 mApp, subId, callingPackage, callingFeatureId,
4758 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4760 }
4761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 final Phone phone = getPhone(subId);
4765 if (phone != null) {
4766 return phone.getServiceState().getVoiceNetworkType();
4767 } else {
4768 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4769 }
4770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004773 }
4774
4775 /**
4776 * @return true if a ICC card is present
4777 */
4778 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004779 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004780 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4781 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004782 }
4783
4784 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004785 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004786 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004787 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004788 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 final Phone phone = PhoneFactory.getPhone(slotIndex);
4792 if (phone != null) {
4793 return phone.getIccCard().hasIccCard();
4794 } else {
4795 return false;
4796 }
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004800 }
4801
4802 /**
4803 * Return if the current radio is LTE on CDMA. This
4804 * is a tri-state return value as for a period of time
4805 * the mode may be unknown.
4806 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004807 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004808 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004809 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004810 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004811 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004812 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4813 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4814 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004815 }
4816
Sanket Padawe356d7632015-06-22 14:03:32 -07004817 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004818 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4819 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004820 try {
4821 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4822 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004823 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4824 }
4825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 final long identity = Binder.clearCallingIdentity();
4827 try {
4828 final Phone phone = getPhone(subId);
4829 if (phone == null) {
4830 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4831 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004832 return TelephonyProperties.lte_on_cdma_device()
4833 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 }
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004837 }
Wink Saville36469e72014-06-11 15:17:00 -07004838 }
4839
Wink Saville36469e72014-06-11 15:17:00 -07004840 /**
4841 * {@hide}
4842 * Returns Default subId, 0 in the case of single standby.
4843 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004844 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004845 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004846 }
4847
Shishir Agrawala9f32182016-04-12 12:00:16 -07004848 private int getSlotForDefaultSubscription() {
4849 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4850 }
4851
Wink Savilleb564aae2014-10-23 10:18:09 -07004852 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004853 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004854 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004855
Pengquan Menge92a50d2018-09-21 15:54:48 -07004856 private boolean isActiveSubscription(int subId) {
4857 return mSubscriptionController.isActiveSubId(subId);
4858 }
4859
Ihab Awadf2177b72013-11-25 13:33:23 -08004860 /**
4861 * @see android.telephony.TelephonyManager.WifiCallingChoices
4862 */
4863 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 final long identity = Binder.clearCallingIdentity();
4865 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004866 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4868 getWhenToMakeWifiCallsDefaultPreference());
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004872 }
4873
4874 /**
4875 * @see android.telephony.TelephonyManager.WifiCallingChoices
4876 */
4877 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 final long identity = Binder.clearCallingIdentity();
4879 try {
4880 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004881 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004886 }
4887
Sailesh Nepald1e68152013-12-12 19:08:02 -08004888 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004889 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004890 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004891 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004892
Jordan Liu4c733742019-02-28 12:03:40 -08004893 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4894 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4895 if (phoneId == -1) {
4896 throw new IllegalArgumentException("Given slot index: " + slotIndex
4897 + " does not correspond to an active phone");
4898 }
4899 return PhoneFactory.getPhone(phoneId);
4900 }
4901
Shishir Agrawal566b7612013-10-28 14:41:00 -07004902 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004903 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4904 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4906 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004908 if (DBG) {
4909 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4910 }
4911 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4912 p2);
4913 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004914
Jordan Liu4c733742019-02-28 12:03:40 -08004915
4916 @Override
4917 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4918 int slotIndex, String callingPackage, String aid, int p2) {
4919 enforceModifyPermission();
4920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4921 if (DBG) {
4922 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4923 }
4924 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4925 callingPackage, aid, p2);
4926 }
4927
4928 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4929 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 if (TextUtils.equals(ISDR_AID, aid)) {
4933 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4935 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 if (bestComponent == null
4937 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4938 loge("The calling package is not allowed to access ISD-R.");
4939 throw new SecurityException(
4940 "The calling package is not allowed to access ISD-R.");
4941 }
Derek Tan740e1672017-06-27 14:56:27 -07004942 }
Derek Tan740e1672017-06-27 14:56:27 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004945 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4946 null /* workSource */);
4947 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 return response;
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004952 }
4953
4954 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004955 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4957 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004958 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4959 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4960 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004961
Jordan Liu4c733742019-02-28 12:03:40 -08004962 @Override
4963 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4964 enforceModifyPermission();
4965 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4966 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4967 channel);
4968 }
4969
4970 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 final long identity = Binder.clearCallingIdentity();
4972 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 if (channel < 0) {
4974 return false;
4975 }
Jordan Liu4c733742019-02-28 12:03:40 -08004976 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4977 null /* workSource */);
4978 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 return success;
4980 } finally {
4981 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004982 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004983 }
4984
4985 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004986 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004987 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4989 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004990 if (DBG) {
4991 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4992 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4993 + p3 + " data=" + data);
4994 }
4995 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4996 command, p1, p2, p3, data);
4997 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004998
Jordan Liu4c733742019-02-28 12:03:40 -08004999 @Override
5000 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5001 int command, int p1, int p2, int p3, String data) {
5002 enforceModifyPermission();
5003 if (DBG) {
5004 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5005 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5006 + p3 + " data=" + data);
5007 }
5008 return iccTransmitApduLogicalChannelWithPermission(
5009 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5010 data);
5011 }
5012
5013 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5014 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 final long identity = Binder.clearCallingIdentity();
5016 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005017 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 return "";
5019 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005022 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5023 null /* workSource */);
5024 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 // Append the returned status code to the end of the response payload.
5027 String s = Integer.toHexString(
5028 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5029 if (response.payload != null) {
5030 s = IccUtils.bytesToHexString(response.payload) + s;
5031 }
5032 return s;
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005036 }
Jake Hambye994d462014-02-03 13:10:13 -08005037
Evan Charltonc66da362014-05-16 14:06:40 -07005038 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005039 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5040 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5042 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005044 if (DBG) {
5045 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5046 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5047 }
5048 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5049 cla, command, p1, p2, p3, data);
5050 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005051
Jordan Liu4c733742019-02-28 12:03:40 -08005052 @Override
5053 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5054 int command, int p1, int p2, int p3, String data) {
5055 enforceModifyPermission();
5056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5057 if (DBG) {
5058 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5059 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5060 + " data=" + data);
5061 }
5062
5063 return iccTransmitApduBasicChannelWithPermission(
5064 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5065 p2, p3, data);
5066 }
5067
5068 // open APDU basic channel assuming the caller has sufficient permissions
5069 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5070 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5074 && TextUtils.equals(ISDR_AID, data)) {
5075 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005076 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5077 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 if (bestComponent == null
5079 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5080 loge("The calling package is not allowed to select ISD-R.");
5081 throw new SecurityException(
5082 "The calling package is not allowed to select ISD-R.");
5083 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005084 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005087 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5088 null /* workSource */);
5089 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 // Append the returned status code to the end of the response payload.
5092 String s = Integer.toHexString(
5093 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5094 if (response.payload != null) {
5095 s = IccUtils.bytesToHexString(response.payload) + s;
5096 }
5097 return s;
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005100 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005101 }
5102
5103 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005104 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005105 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5107 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 if (DBG) {
5112 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5113 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5114 }
5115
5116 IccIoResult response =
5117 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5118 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5119 subId);
5120
5121 if (DBG) {
5122 log("Exchange SIM_IO [R]" + response);
5123 }
5124
5125 byte[] result = null;
5126 int length = 2;
5127 if (response.payload != null) {
5128 length = 2 + response.payload.length;
5129 result = new byte[length];
5130 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5131 } else {
5132 result = new byte[length];
5133 }
5134
5135 result[length - 1] = (byte) response.sw2;
5136 result[length - 2] = (byte) response.sw1;
5137 return result;
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005140 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005141 }
5142
Nathan Haroldb3014052017-01-25 15:57:32 -08005143 /**
5144 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5145 * on a particular subscription
5146 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005147 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5148 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005150 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005151 return null;
5152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 if (appType != TelephonyManager.APPTYPE_USIM
5157 && appType != TelephonyManager.APPTYPE_SIM) {
5158 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5159 return null;
5160 }
5161 Object response = sendRequest(
5162 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5163 if (response instanceof String[]) {
5164 return (String[]) response;
5165 }
yincheng zhaod698b842019-09-06 17:06:54 -07005166 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005168 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 } finally {
5170 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005171 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005172 }
5173
yincheng zhaod698b842019-09-06 17:06:54 -07005174 /**
5175 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5176 * subscription.
5177 *
5178 * @param subId the id of the subscription.
5179 * @param appType the uicc app type, must be USIM or SIM.
5180 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5181 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005182 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005183 * @return number of fplmns that is successfully written to the SIM.
5184 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005185 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5186 String callingFeatureId) {
5187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5188 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005189 if (DBG) logv("no permissions for setForbiddenplmns");
5190 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5191 }
5192 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5193 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5194 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5195 }
5196 if (fplmns == null) {
5197 throw new IllegalArgumentException("Fplmn List provided is null");
5198 }
5199 for (String fplmn : fplmns) {
5200 if (!CellIdentity.isValidPlmn(fplmn)) {
5201 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5202 }
5203 }
5204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 Object response = sendRequest(
5207 CMD_SET_FORBIDDEN_PLMNS,
5208 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5209 subId);
5210 return (int) response;
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
5214 }
5215
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005216 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005217 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5224 if (response.payload == null) {
5225 return "";
5226 }
Evan Charltonc66da362014-05-16 14:06:40 -07005227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 // Append the returned status code to the end of the response payload.
5229 String s = Integer.toHexString(
5230 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5231 s = IccUtils.bytesToHexString(response.payload) + s;
5232 return s;
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Evan Charltonc66da362014-05-16 14:06:40 -07005236 }
5237
Jake Hambye994d462014-02-03 13:10:13 -08005238 /**
5239 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5240 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5241 *
5242 * @param itemID the ID of the item to read
5243 * @return the NV item as a String, or null on error.
5244 */
5245 @Override
5246 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5249 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005254 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5256 return value;
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Jake Hambye994d462014-02-03 13:10:13 -08005260 }
5261
5262 /**
5263 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5264 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5265 *
5266 * @param itemID the ID of the item to read
5267 * @param itemValue the value to write, as a String
5268 * @return true on success; false on any failure
5269 */
5270 @Override
5271 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5274 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275
5276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5279 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005280 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5282 return success;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Jake Hambye994d462014-02-03 13:10:13 -08005286 }
5287
5288 /**
5289 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5290 * Used for device configuration by some CDMA operators.
5291 *
5292 * @param preferredRoamingList byte array containing the new PRL
5293 * @return true on success; false on any failure
5294 */
5295 @Override
5296 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5298 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5303 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5304 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5305 return success;
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
Jake Hambye994d462014-02-03 13:10:13 -08005309 }
5310
5311 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005312 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005313 * Used for device configuration by some CDMA operators.
5314 *
chen xu6dac5ab2018-10-26 17:39:23 -07005315 * @param slotIndex - device slot.
5316 *
Jake Hambye994d462014-02-03 13:10:13 -08005317 * @return true on success; false on any failure
5318 */
5319 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005320 public boolean resetModemConfig(int slotIndex) {
5321 Phone phone = PhoneFactory.getPhone(slotIndex);
5322 if (phone != null) {
5323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5324 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
chen xu6dac5ab2018-10-26 17:39:23 -07005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5329 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5330 return success;
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 }
chen xu6dac5ab2018-10-26 17:39:23 -07005335 return false;
5336 }
5337
5338 /**
5339 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5340 *
5341 * @param slotIndex - device slot.
5342 *
5343 * @return true on success; false on any failure
5344 */
5345 @Override
5346 public boolean rebootModem(int slotIndex) {
5347 Phone phone = PhoneFactory.getPhone(slotIndex);
5348 if (phone != null) {
5349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, phone.getSubId(), "rebootModem");
5351
5352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5355 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5356 return success;
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
5360 }
5361 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005362 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005363
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005364 public String[] getPcscfAddress(String apnType, String callingPackage,
5365 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005366 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5368 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005369 return new String[0];
5370 }
5371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 final long identity = Binder.clearCallingIdentity();
5373 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005374 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
Wink Saville36469e72014-06-11 15:17:00 -07005378 }
5379
Brad Ebinger51f743a2017-01-23 13:50:20 -08005380 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005381 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5382 * {@link #disableIms(int)}.
5383 * @param slotIndex device slot.
5384 */
5385 public void resetIms(int slotIndex) {
5386 enforceModifyPermission();
5387
5388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 if (mImsResolver == null) {
5391 // may happen if the does not support IMS.
5392 return;
5393 }
5394 mImsResolver.disableIms(slotIndex);
5395 mImsResolver.enableIms(slotIndex);
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
5399 }
5400
5401 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005402 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5403 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005404 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005405 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005406 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407
5408 final long identity = Binder.clearCallingIdentity();
5409 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005410 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005411 // may happen if the device does not support IMS.
5412 return;
5413 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005414 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005418 }
5419
5420 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005421 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5422 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005423 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005424 public void disableIms(int slotId) {
5425 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426
5427 final long identity = Binder.clearCallingIdentity();
5428 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005429 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005430 // may happen if the device does not support IMS.
5431 return;
5432 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005433 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005437 }
5438
5439 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005440 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5441 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005442 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005443 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005444 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446
5447 final long identity = Binder.clearCallingIdentity();
5448 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005449 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005450 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5451 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005452 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005453 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005457 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005458 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005459 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5460 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005461 @Override
5462 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005463 enforceModifyPermission();
5464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005468 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
5472 }
5473
5474 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005475 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005476 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005477 */
5478 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480
5481 final long identity = Binder.clearCallingIdentity();
5482 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005483 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005484 // may happen if the device does not support IMS.
5485 return null;
5486 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005487 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005491 }
5492
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005493 /**
5494 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005495 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005496 */
5497 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5498 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005502 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005503 // may happen if the device does not support IMS.
5504 return null;
5505 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005506 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005510 }
5511
Brad Ebinger884c07b2018-02-15 16:17:40 -08005512 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005513 * Sets the ImsService Package Name that Telephony will bind to.
5514 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005515 * @param slotIndex the slot ID that the ImsService should bind for.
5516 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005517 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005518 * @param featureTypes An integer array of feature types associated with a packageName.
5519 * @param packageName The name of the package that the current configuration will be replaced
5520 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005521 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005522 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005523 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5524 int[] featureTypes, String packageName) {
5525 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5526 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5528 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005529 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 final long identity = Binder.clearCallingIdentity();
5532 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005533 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005534 // may happen if the device does not support IMS.
5535 return false;
5536 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005537 Map<Integer, String> featureConfig = new HashMap<>();
5538 for (int featureType : featureTypes) {
5539 featureConfig.put(featureType, packageName);
5540 }
5541 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5542 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 } finally {
5544 Binder.restoreCallingIdentity(identity);
5545 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005546 }
5547
5548 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005549 * Clears any carrier ImsService overrides for the slot index specified that were previously
5550 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5551 *
5552 * This should only be used for testing.
5553 *
5554 * @param slotIndex the slot ID that the ImsService should bind for.
5555 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5556 */
5557 @Override
5558 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5559 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5560 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5561 "clearCarrierImsServiceOverride");
5562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5563 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5564 "clearCarrierImsServiceOverride");
5565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 if (mImsResolver == null) {
5569 // may happen if the device does not support IMS.
5570 return false;
5571 }
5572 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
5576 }
5577
5578 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005579 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005580 *
5581 * @param slotId The slot that the ImsService is associated with.
5582 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5583 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005584 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005585 * @return the package name of the ImsService configuration.
5586 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005587 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5588 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005589 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005590 TelephonyPermissions
5591 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5592 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5593 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 final long identity = Binder.clearCallingIdentity();
5596 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005598 // may happen if the device does not support IMS.
5599 return "";
5600 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005601 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005602 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5603 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005607 }
5608
Brad Ebinger77b832e2019-10-17 17:03:22 -07005609 /**
5610 * Get the MmTelFeature state associated with the requested subscription id.
5611 * @param subId The subscription that the MmTelFeature is associated with.
5612 * @param callback A callback with an integer containing the
5613 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5614 */
5615 @Override
5616 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5617 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5618 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5619 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5620 "IMS not available on device.");
5621 }
5622 final long token = Binder.clearCallingIdentity();
5623 try {
5624 int slotId = getSlotIndex(subId);
5625 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5626 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5627 + subId + "'");
5628 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5629 }
5630 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5631 try {
5632 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5633 } catch (RemoteException e) {
5634 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5635 + "Ignore");
5636 }
5637 });
5638 } finally {
5639 Binder.restoreCallingIdentity(token);
5640 }
5641 }
5642
Daniel Brightbb5840b2021-01-12 15:48:18 -08005643 /**
5644 * Sets the ims registration state on all valid {@link Phone}s.
5645 */
5646 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648
5649 final long identity = Binder.clearCallingIdentity();
5650 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005651 // NOTE: Before S, this method only set the default phone.
5652 for (final Phone phone : PhoneFactory.getPhones()) {
5653 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5654 phone.setImsRegistrationState(registered);
5655 }
5656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Wink Saville36469e72014-06-11 15:17:00 -07005660 }
5661
5662 /**
Stuart Scott54788802015-03-30 13:18:01 -07005663 * Set the network selection mode to automatic.
5664 *
5665 */
5666 @Override
5667 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5669 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
shilufc958392020-01-20 11:36:01 -08005673 if (!isActiveSubscription(subId)) {
5674 return;
5675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005677 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5678 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
Stuart Scott54788802015-03-30 13:18:01 -07005682 }
5683
Jack Yud10cdd42020-09-28 20:28:01 -07005684 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005685 * Ask the radio to connect to the input network and change selection mode to manual.
5686 *
5687 * @param subId the id of the subscription.
5688 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5689 * the operator to attach to.
5690 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5691 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5692 * normal network selection next time.
5693 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005694 */
5695 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005696 public boolean setNetworkSelectionModeManual(
5697 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5699 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005700
5701 if (!isActiveSubscription(subId)) {
5702 return false;
5703 }
5704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 final long identity = Binder.clearCallingIdentity();
5706 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005707 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005709 if (DBG) {
5710 log("setNetworkSelectionModeManual: subId: " + subId
5711 + " operator: " + operatorInfo);
5712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005717 }
shilu84f6e8b2019-12-19 13:58:01 -08005718 /**
5719 * Get the manual network selection
5720 *
5721 * @param subId the id of the subscription.
5722 *
5723 * @return the previously saved user selected PLMN
5724 */
5725 @Override
5726 public String getManualNetworkSelectionPlmn(int subId) {
5727 TelephonyPermissions
5728 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5729 mApp, subId, "getManualNetworkSelectionPlmn");
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 if (!isActiveSubscription(subId)) {
5734 return "";
5735 }
5736
5737 final Phone phone = getPhone(subId);
5738 if (phone == null) {
5739 return "";
5740 }
5741 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5742 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5743 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
5746 }
5747 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005748
5749 /**
5750 * Scans for available networks.
5751 */
5752 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005753 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5754 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5756 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005757 LocationAccessPolicy.LocationPermissionResult locationResult =
5758 LocationAccessPolicy.checkLocationPermission(mApp,
5759 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5760 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005761 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005762 .setCallingPid(Binder.getCallingPid())
5763 .setCallingUid(Binder.getCallingUid())
5764 .setMethod("getCellNetworkScanResults")
5765 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5766 .build());
5767 switch (locationResult) {
5768 case DENIED_HARD:
5769 throw new SecurityException("Not allowed to access scan results -- location");
5770 case DENIED_SOFT:
5771 return null;
5772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773
Pengquan Menga1bb6272018-09-06 09:59:22 -07005774 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 try {
5776 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005777 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779 } finally {
5780 Binder.restoreCallingIdentity(identity);
5781 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005782 }
5783
5784 /**
sqian80370722020-01-29 15:02:51 -08005785 * Get the call forwarding info, given the call forwarding reason.
5786 */
5787 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005788 public void getCallForwarding(int subId, int callForwardingReason,
5789 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005790 enforceReadPrivilegedPermission("getCallForwarding");
5791 long identity = Binder.clearCallingIdentity();
5792 try {
5793 if (DBG) {
5794 log("getCallForwarding: subId " + subId
5795 + " callForwardingReason" + callForwardingReason);
5796 }
Hall Liua1acea22020-09-18 19:04:59 -07005797
5798 Phone phone = getPhone(subId);
5799 if (phone == null) {
5800 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005801 callback.onError(
5802 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005803 } catch (RemoteException e) {
5804 // ignore
5805 }
5806 return;
5807 }
5808
5809 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5810 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5811 @Override
5812 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5813 try {
5814 callback.onCallForwardingInfoAvailable(info);
5815 } catch (RemoteException e) {
5816 // ignore
5817 }
5818 }
5819
5820 @Override
5821 public void onError(int error) {
5822 try {
5823 callback.onError(error);
5824 } catch (RemoteException e) {
5825 // ignore
5826 }
5827 }
5828 });
5829 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
5833 }
5834
5835 /**
5836 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5837 * reason, the number to forward, and the timeout before the forwarding is attempted.
5838 */
5839 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005840 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5841 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005842 enforceModifyPermission();
5843 long identity = Binder.clearCallingIdentity();
5844 try {
5845 if (DBG) {
5846 log("setCallForwarding: subId " + subId
5847 + " callForwardingInfo" + callForwardingInfo);
5848 }
Hall Liua1acea22020-09-18 19:04:59 -07005849
5850 Phone phone = getPhone(subId);
5851 if (phone == null) {
5852 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005853 callback.accept(
5854 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005855 } catch (RemoteException e) {
5856 // ignore
5857 }
5858 return;
5859 }
5860
5861 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5862 FunctionalUtils.ignoreRemoteException(callback::accept));
5863
5864 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
5870 /**
Hall Liua1acea22020-09-18 19:04:59 -07005871 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005872 */
5873 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005874 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005875 enforceReadPrivilegedPermission("getCallForwarding");
5876 long identity = Binder.clearCallingIdentity();
5877 try {
Hall Liua1acea22020-09-18 19:04:59 -07005878
5879 Phone phone = getPhone(subId);
5880 if (phone == null) {
5881 try {
5882 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5883 } catch (RemoteException e) {
5884 // ignore
5885 }
5886 return;
5887 }
5888
5889 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5890
sqian80370722020-01-29 15:02:51 -08005891 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005892 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
5896 }
5897
5898 /**
Hall Liua1acea22020-09-18 19:04:59 -07005899 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005900 */
5901 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005902 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005903 enforceModifyPermission();
5904 long identity = Binder.clearCallingIdentity();
5905 try {
Hall Liua1acea22020-09-18 19:04:59 -07005906 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5907
5908 Phone phone = getPhone(subId);
5909 if (phone == null) {
5910 try {
5911 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5912 } catch (RemoteException e) {
5913 // ignore
5914 }
5915 return;
5916 }
5917
5918 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5919 FunctionalUtils.ignoreRemoteException(callback::accept));
5920
5921 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
5925 }
5926
5927 /**
yinxub1bed742017-04-17 11:45:04 -07005928 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005929 *
yinxub1bed742017-04-17 11:45:04 -07005930 * @param subId id of the subscription
5931 * @param request contains the radio access networks with bands/channels to scan
5932 * @param messenger callback messenger for scan results or errors
5933 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005934 * @return the id of the requested scan which can be used to stop the scan.
5935 */
5936 @Override
5937 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005938 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5940 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005941 LocationAccessPolicy.LocationPermissionResult locationResult =
5942 LocationAccessPolicy.checkLocationPermission(mApp,
5943 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5944 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005945 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005946 .setCallingPid(Binder.getCallingPid())
5947 .setCallingUid(Binder.getCallingUid())
5948 .setMethod("requestNetworkScan")
5949 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5950 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005951 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005952 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5953 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005954 if (e != null) {
5955 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5956 throw e;
5957 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005958 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005959 return TelephonyScanManager.INVALID_SCAN_ID;
5960 }
5961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 }
Hall Liu912dfd32019-04-25 14:02:26 -07005963 int callingUid = Binder.getCallingUid();
5964 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 return mNetworkScanRequestTracker.startNetworkScan(
5968 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005969 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
yinxu504e1392017-04-12 16:03:22 -07005973 }
5974
Hall Liub2ac8ef2019-02-28 15:56:23 -08005975 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005976 NetworkScanRequest request, int subId, String callingPackage) {
5977 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005978 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5979 boolean hasNetworkScanPermission =
5980 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5981 == PERMISSION_GRANTED;
5982
5983 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5984 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5985 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005986 }
5987
5988 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5989 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005990 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5991 return new SecurityException("Specific channels must not be"
5992 + " scanned without location access.");
5993 }
5994 }
5995 }
5996
Hall Liub2ac8ef2019-02-28 15:56:23 -08005997 return null;
5998 }
5999
yinxu504e1392017-04-12 16:03:22 -07006000 /**
6001 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006002 *
6003 * @param subId id of the subscription
6004 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006005 */
6006 @Override
6007 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
Hall Liu912dfd32019-04-25 14:02:26 -07006011 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 final long identity = Binder.clearCallingIdentity();
6013 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006014 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
yinxu504e1392017-04-12 16:03:22 -07006018 }
6019
6020 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006021 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006022 *
SongFerngWang9e060372020-12-21 16:41:52 +08006023 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006024 */
6025 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006026 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006027 TelephonyPermissions
6028 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006029 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006033 if (DBG) log("getAllowedNetworkTypesBitmask");
6034 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6035 int networkTypesBitmask = (result != null ? result[0] : -1);
6036 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6037 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
6040 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006041 }
6042
6043 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006044 * Get the allowed network types for certain reason.
6045 *
6046 * @param subId the id of the subscription.
6047 * @param reason the reason the allowed network type change is taking place
6048 * @return the allowed network types.
6049 */
6050 @Override
6051 public long getAllowedNetworkTypesForReason(int subId,
6052 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6053 TelephonyPermissions
6054 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6055 mApp, subId, "getAllowedNetworkTypesForReason");
6056 final long identity = Binder.clearCallingIdentity();
6057 try {
6058 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
6062 }
6063
6064 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006065 * Enable/Disable E-UTRA-NR Dual Connectivity
6066 * @param subId subscription id of the sim card
6067 * @param nrDualConnectivityState expected NR dual connectivity state
6068 * This can be passed following states
6069 * <ol>
6070 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6071 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6072 * <li>Disable NR dual connectivity and force secondary cell to be released
6073 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6074 * </ol>
6075 * @return operation result.
6076 */
6077 @Override
6078 public int setNrDualConnectivityState(int subId,
6079 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6081 mApp, subId, "enableNRDualConnectivity");
6082 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6086 nrDualConnectivityState, subId,
6087 workSource);
6088 if (DBG) log("enableNRDualConnectivity result: " + result);
6089 return result;
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
6093 }
6094
6095 /**
6096 * Is E-UTRA-NR Dual Connectivity enabled
6097 * @return true if dual connectivity is enabled else false
6098 */
6099 @Override
6100 public boolean isNrDualConnectivityEnabled(int subId) {
6101 TelephonyPermissions
6102 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6103 mApp, subId, "isNRDualConnectivityEnabled");
6104 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
6107 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6108 null, subId, workSource);
6109 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6110 return isEnabled;
6111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
6114 }
6115
6116 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006117 * get carrier bandwidth per primary and secondary carrier
6118 * @param subId subscription id of the sim card
6119 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6120 */
6121 @Override
6122 public CarrierBandwidth getCarrierBandwidth(int subId) {
6123 TelephonyPermissions
6124 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6125 mApp, subId, "isNRDualConnectivityEnabled");
6126 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 CarrierBandwidth carrierBandwidth =
6130 getPhoneFromSubId(subId).getCarrierBandwidth();
6131 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6132 return carrierBandwidth;
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
6136 }
6137
6138 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006139 * Set the allowed network types of the device and
6140 * provide the reason triggering the allowed network change.
6141 *
6142 * @param subId the id of the subscription.
6143 * @param reason the reason the allowed network type change is taking place
6144 * @param allowedNetworkTypes the allowed network types.
6145 * @return true on success; false on any failure.
6146 */
6147 @Override
6148 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006149 @TelephonyManager.AllowedNetworkTypesReason int reason,
6150 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6152 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006153 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6154 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6155 return false;
6156 }
6157
6158 if (DBG) {
6159 log("setAllowedNetworkTypesForReason: " + reason
6160 + " value: " + allowedNetworkTypes);
6161 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006162 final long identity = Binder.clearCallingIdentity();
6163 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006164 Boolean success = (Boolean) sendRequest(
6165 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6166 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6167
6168 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6169 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
6173 }
6174
6175 /**
Miaoa84611c2019-03-15 09:21:10 +08006176 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006177 *
Miaoa84611c2019-03-15 09:21:10 +08006178 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006179 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006180 * @hide
6181 */
6182 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006183 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006186 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 try {
Miaoa84611c2019-03-15 09:21:10 +08006188 if (phone != null) {
6189 return phone.hasMatchedTetherApnSetting();
6190 } else {
6191 return false;
6192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 } finally {
6194 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006195 }
Junda Liu475951f2014-11-07 16:45:03 -08006196 }
6197
6198 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006199 * Enable or disable always reporting signal strength changes from radio.
6200 *
6201 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6202 */
6203 @Override
6204 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6205 enforceModifyPermission();
6206 enforceSystemCaller();
6207
6208 final long identity = Binder.clearCallingIdentity();
6209 final Phone phone = getPhone(subId);
6210 try {
6211 if (phone != null) {
6212 if (DBG) {
6213 log("setAlwaysReportSignalStrength: subId=" + subId
6214 + " isEnable=" + isEnable);
6215 }
6216 phone.setAlwaysReportSignalStrength(isEnable);
6217 } else {
6218 loge("setAlwaysReportSignalStrength: no phone found for subId="
6219 + subId);
6220 }
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
6223 }
6224 }
6225
6226 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006227 * Get the user enabled state of Mobile Data.
6228 *
6229 * TODO: remove and use isUserDataEnabled.
6230 * This can't be removed now because some vendor codes
6231 * calls through ITelephony directly while they should
6232 * use TelephonyManager.
6233 *
6234 * @return true on enabled
6235 */
6236 @Override
6237 public boolean getDataEnabled(int subId) {
6238 return isUserDataEnabled(subId);
6239 }
6240
6241 /**
6242 * Get whether mobile data is enabled per user setting.
6243 *
6244 * There are other factors deciding whether mobile data is actually enabled, but they are
6245 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006246 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006247 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006248 *
6249 * @return {@code true} if data is enabled else {@code false}
6250 */
6251 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006252 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006253 try {
6254 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6255 null);
6256 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6258 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260
6261 final long identity = Binder.clearCallingIdentity();
6262 try {
6263 int phoneId = mSubscriptionController.getPhoneId(subId);
6264 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6265 Phone phone = PhoneFactory.getPhone(phoneId);
6266 if (phone != null) {
6267 boolean retVal = phone.isUserDataEnabled();
6268 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6269 return retVal;
6270 } else {
6271 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6272 return false;
6273 }
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006276 }
6277 }
6278
6279 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006280 * Checks if the device is capable of mobile data by considering whether whether the
6281 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6282 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006283 *
Shuo Qian985d1232020-01-08 14:30:06 -08006284 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006285 */
6286 @Override
6287 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006288 try {
6289 try {
6290 mApp.enforceCallingOrSelfPermission(
6291 android.Manifest.permission.ACCESS_NETWORK_STATE,
6292 null);
6293 } catch (Exception e) {
6294 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6295 "isDataEnabled");
6296 }
6297 } catch (Exception e) {
6298 enforceReadPrivilegedPermission("isDataEnabled");
6299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 int phoneId = mSubscriptionController.getPhoneId(subId);
6304 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6305 Phone phone = PhoneFactory.getPhone(phoneId);
6306 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006307 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6309 return retVal;
6310 } else {
6311 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6312 return false;
6313 }
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006316 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006317 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006318
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006319 /**
6320 * Check if data is enabled for a specific reason
6321 * @param subId Subscription index
6322 * @param reason the reason the data enable change is taking place
6323 * @return {@code true} if the overall data is enabled; {@code false} if not.
6324 */
6325 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006326 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006327 @TelephonyManager.DataEnabledReason int reason) {
6328 try {
6329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6330 null);
6331 } catch (Exception e) {
6332 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006333 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006334 }
6335
6336
6337 final long identity = Binder.clearCallingIdentity();
6338 try {
6339 int phoneId = mSubscriptionController.getPhoneId(subId);
6340 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006341 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006342 + " reason=" + reason);
6343 }
6344 Phone phone = PhoneFactory.getPhone(phoneId);
6345 if (phone != null) {
6346 boolean retVal;
6347 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6348 retVal = phone.isUserDataEnabled();
6349 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006350 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006351 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006352 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006353 return retVal;
6354 } else {
6355 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006356 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006357 + subId + " retVal=false");
6358 }
6359 return false;
6360 }
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
6365
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006366 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006367 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006368 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6369 // Skip the check if it's one of these special uids
6370 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6371 }
6372
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006373 //load access rules from carrier configs, and check those as well: b/139133814
6374 SubscriptionController subController = SubscriptionController.getInstance();
6375 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6376 || subController == null) return privilegeFromSim;
6377
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006378 PackageManager pkgMgr = phone.getContext().getPackageManager();
6379 String[] packages = pkgMgr.getPackagesForUid(uid);
6380
6381 final long identity = Binder.clearCallingIdentity();
6382 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006383 int subId = phone.getSubId();
6384 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6385 // A test override is in place for the privileges for this subId, so don't try to
6386 // read the subscription privileges.
6387 return privilegeFromSim;
6388 }
6389 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006390 SubscriptionManager subManager = (SubscriptionManager)
6391 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6392 for (String pkg : packages) {
6393 if (subManager.canManageSubscription(subInfo, pkg)) {
6394 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6395 }
6396 }
6397 return privilegeFromSim;
6398 } finally {
6399 Binder.restoreCallingIdentity(identity);
6400 }
6401 }
6402
6403 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6404 String pkgName) {
6405 //load access rules from carrier configs, and check those as well: b/139133814
6406 SubscriptionController subController = SubscriptionController.getInstance();
6407 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6408 || subController == null) return privilegeFromSim;
6409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006412 int subId = phone.getSubId();
6413 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6414 // A test override is in place for the privileges for this subId, so don't try to
6415 // read the subscription privileges.
6416 return privilegeFromSim;
6417 }
6418 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006419 SubscriptionManager subManager = (SubscriptionManager)
6420 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6421 return subManager.canManageSubscription(subInfo, pkgName)
6422 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
6426 }
6427
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006428 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006429 public int getCarrierPrivilegeStatus(int subId) {
6430 final Phone phone = getPhone(subId);
6431 if (phone == null) {
6432 loge("getCarrierPrivilegeStatus: Invalid subId");
6433 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6434 }
6435 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006436 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006437 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006438 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6439 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006440
6441 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6442 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006443 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006444 }
Junda Liu29340342014-07-10 15:23:27 -07006445
6446 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006447 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006448 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006449 final Phone phone = getPhone(subId);
6450 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006451 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006452 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6453 }
6454 UiccProfile profile =
6455 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6456 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006457 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6459 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006460 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006461 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006462 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006463 }
6464
6465 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006466 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6467 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006468 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006469 }
6470
6471 int phoneId = SubscriptionManager.getPhoneId(subId);
6472 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006473 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006474 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006475 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6476 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006477 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6478 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6479 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006480 }
6481
6482 @Override
6483 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006484 if (TextUtils.isEmpty(pkgName))
6485 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006486 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6487 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6488 UiccCard card = UiccController.getInstance().getUiccCard(i);
6489 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006490 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006491 continue;
6492 }
6493
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006494 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6495 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6496 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006497 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6498 break;
6499 }
6500 }
6501
6502 return result;
Junda Liu29340342014-07-10 15:23:27 -07006503 }
Derek Tan89e89d42014-07-08 17:00:10 -07006504
6505 @Override
Junda Liue64de782015-04-16 17:19:16 -07006506 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6507 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6508 loge("phoneId " + phoneId + " is not valid.");
6509 return null;
6510 }
6511 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006512 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006513 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006514 return null ;
6515 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006516 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006517 }
6518
Amith Yamasani6e118872016-02-19 12:53:51 -08006519 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006520 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006521 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006522 List<String> privilegedPackages = new ArrayList<>();
6523 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006524 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6525 // has UICC in that slot.
6526 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006527 if (card.hasCarrierPrivilegeRules()) {
6528 if (packages == null) {
6529 // Only check packages in user 0 for now
6530 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006531 PackageManager.MATCH_DISABLED_COMPONENTS
6532 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006533 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006534 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006535 }
6536 for (int p = packages.size() - 1; p >= 0; p--) {
6537 PackageInfo pkgInfo = packages.get(p);
6538 if (pkgInfo != null && pkgInfo.packageName != null
6539 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006540 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006541 privilegedPackages.add(pkgInfo.packageName);
6542 }
6543 }
6544 }
6545 }
6546 return privilegedPackages;
6547 }
6548
chen xuf7e9fe82019-05-09 19:31:02 -07006549 @Override
6550 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006551 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6552
6553 final long identity = Binder.clearCallingIdentity();
6554
chen xuf7e9fe82019-05-09 19:31:02 -07006555 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006556 try {
6557 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6558 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6559 }
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006562 }
6563 return privilegedPackages;
6564 }
6565
Wink Savilleb564aae2014-10-23 10:18:09 -07006566 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006567 final Phone phone = getPhone(subId);
6568 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006569 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006570 return null;
6571 }
6572 String iccId = card.getIccId();
6573 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006574 return null;
6575 }
6576 return iccId;
6577 }
6578
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006579 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006580 public void setCallComposerStatus(int subId, int status) {
6581 enforceModifyPermission();
6582
6583 final long identity = Binder.clearCallingIdentity();
6584 try {
6585 Phone phone = getPhone(subId);
6586 if (phone != null) {
6587 Phone defaultPhone = phone.getImsPhone();
6588 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6589 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6590 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006591 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6592 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006593 }
6594 }
Shuo Qiand8782462020-12-22 19:10:14 -08006595 } catch (ImsException e) {
6596 throw new ServiceSpecificException(e.getCode());
6597 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006598 Binder.restoreCallingIdentity(identity);
6599 }
6600 }
6601
6602 @Override
6603 public int getCallComposerStatus(int subId) {
6604 enforceReadPrivilegedPermission("getCallComposerStatus");
6605
6606 final long identity = Binder.clearCallingIdentity();
6607 try {
6608 Phone phone = getPhone(subId);
6609 if (phone != null) {
6610 Phone defaultPhone = phone.getImsPhone();
6611 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6612 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6613 return imsPhone.getCallComposerStatus();
6614 }
6615 }
6616 } finally {
6617 Binder.restoreCallingIdentity(identity);
6618 }
6619 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6620 }
6621
6622 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006623 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6624 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006625 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006626 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 final String iccId = getIccId(subId);
6631 final Phone phone = getPhone(subId);
6632 if (phone == null) {
6633 return false;
6634 }
6635 final String subscriberId = phone.getSubscriberId();
6636
6637 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006638 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 + subscriberId + " to " + number);
6640 }
6641
6642 if (TextUtils.isEmpty(iccId)) {
6643 return false;
6644 }
6645
6646 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6647
6648 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6649 if (alphaTag == null) {
6650 editor.remove(alphaTagPrefKey);
6651 } else {
6652 editor.putString(alphaTagPrefKey, alphaTag);
6653 }
6654
6655 // Record both the line number and IMSI for this ICCID, since we need to
6656 // track all merged IMSIs based on line number
6657 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6658 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6659 if (number == null) {
6660 editor.remove(numberPrefKey);
6661 editor.remove(subscriberPrefKey);
6662 } else {
6663 editor.putString(numberPrefKey, number);
6664 editor.putString(subscriberPrefKey, subscriberId);
6665 }
6666
6667 editor.commit();
6668 return true;
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006671 }
Derek Tan7226c842014-07-02 17:42:23 -07006672 }
6673
6674 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006675 public String getLine1NumberForDisplay(int subId, String callingPackage,
6676 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006677 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006679 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006680 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006681 return null;
6682 }
Derek Tan97ebb422014-09-05 16:55:38 -07006683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 String iccId = getIccId(subId);
6687 if (iccId != null) {
6688 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6689 if (DBG_MERGE) {
6690 log("getLine1NumberForDisplay returning "
6691 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6692 }
6693 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6696 return null;
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006699 }
Derek Tan7226c842014-07-02 17:42:23 -07006700 }
6701
6702 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006703 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6704 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006706 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006707 return null;
6708 }
Derek Tan97ebb422014-09-05 16:55:38 -07006709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 String iccId = getIccId(subId);
6713 if (iccId != null) {
6714 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6715 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6716 }
6717 return null;
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006720 }
Derek Tan7226c842014-07-02 17:42:23 -07006721 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006722
6723 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006724 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6725 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006726 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6727 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006729 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006730 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006731 return null;
6732 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006733
Jordan Liub49b04b2019-05-06 14:45:15 -07006734 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6735 // the process, where TelephonyManager was instantiated.
6736 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006737 final long identity = Binder.clearCallingIdentity();
6738 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006739 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 final TelephonyManager tele = TelephonyManager.from(context);
6741 final SubscriptionManager sub = SubscriptionManager.from(context);
6742
6743 // Figure out what subscribers are currently active
6744 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745
Jordan Liub49b04b2019-05-06 14:45:15 -07006746 // Only consider subs which match the current subId
6747 // This logic can be simplified. See b/131189269 for progress.
6748 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006749 activeSubscriberIds.add(tele.getSubscriberId(subId));
6750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751
6752 // First pass, find a number override for an active subscriber
6753 String mergeNumber = null;
6754 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6755 for (String key : prefs.keySet()) {
6756 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6757 final String subscriberId = (String) prefs.get(key);
6758 if (activeSubscriberIds.contains(subscriberId)) {
6759 final String iccId = key.substring(
6760 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6761 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6762 mergeNumber = (String) prefs.get(numberKey);
6763 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006764 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 + " for active subscriber " + subscriberId);
6766 }
6767 if (!TextUtils.isEmpty(mergeNumber)) {
6768 break;
6769 }
6770 }
6771 }
6772 }
6773
6774 // Shortcut when no active merged subscribers
6775 if (TextUtils.isEmpty(mergeNumber)) {
6776 return null;
6777 }
6778
6779 // Second pass, find all subscribers under that line override
6780 final ArraySet<String> result = new ArraySet<>();
6781 for (String key : prefs.keySet()) {
6782 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6783 final String number = (String) prefs.get(key);
6784 if (mergeNumber.equals(number)) {
6785 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6786 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6787 final String subscriberId = (String) prefs.get(subscriberKey);
6788 if (!TextUtils.isEmpty(subscriberId)) {
6789 result.add(subscriberId);
6790 }
6791 }
6792 }
6793 }
6794
6795 final String[] resultArray = result.toArray(new String[result.size()]);
6796 Arrays.sort(resultArray);
6797 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006798 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6800 }
6801 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006802 } finally {
6803 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006804 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006805 }
6806
6807 @Override
zoey chen38003472019-12-13 17:16:31 +08006808 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6809 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 final TelephonyManager telephonyManager = mApp.getSystemService(
6814 TelephonyManager.class);
6815 String subscriberId = telephonyManager.getSubscriberId(subId);
6816 if (subscriberId == null) {
6817 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006818 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006819 + subId);
6820 }
6821 return null;
6822 }
6823
6824 final SubscriptionInfo info = SubscriptionController.getInstance()
6825 .getSubscriptionInfo(subId);
6826 final ParcelUuid groupUuid = info.getGroupUuid();
6827 // If it doesn't belong to any group, return just subscriberId of itself.
6828 if (groupUuid == null) {
6829 return new String[]{subscriberId};
6830 }
6831
6832 // Get all subscriberIds from the group.
6833 final List<String> mergedSubscriberIds = new ArrayList<>();
6834 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006835 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006836 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006837 for (SubscriptionInfo subInfo : groupInfos) {
6838 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6839 if (subscriberId != null) {
6840 mergedSubscriberIds.add(subscriberId);
6841 }
6842 }
6843
6844 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847
6848 }
6849 }
6850
6851 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006852 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006853 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006854 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855
6856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 final Phone phone = getPhone(subId);
6859 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6860 } finally {
6861 Binder.restoreCallingIdentity(identity);
6862 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006863 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006864
6865 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006866 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006867 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6868 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006869 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6870 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
6874 final Phone phone = getPhone(subId);
6875 if (phone == null) {
6876 return false;
6877 }
6878 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6879 cdmaNonRoamingList);
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006882 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006883 }
6884
6885 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006886 @Deprecated
6887 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6888 enforceModifyPermission();
6889
6890 int returnValue = 0;
6891 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006892 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006893 if(result.exception == null) {
6894 if (result.result != null) {
6895 byte[] responseData = (byte[])(result.result);
6896 if(responseData.length > oemResp.length) {
6897 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6898 responseData.length + "bytes. Buffer Size is " +
6899 oemResp.length + "bytes.");
6900 }
6901 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6902 returnValue = responseData.length;
6903 }
6904 } else {
6905 CommandException ex = (CommandException) result.exception;
6906 returnValue = ex.getCommandError().ordinal();
6907 if(returnValue > 0) returnValue *= -1;
6908 }
6909 } catch (RuntimeException e) {
6910 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6911 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6912 if(returnValue > 0) returnValue *= -1;
6913 }
6914
6915 return returnValue;
6916 }
6917
6918 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006919 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006920 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006921 try {
6922 TelephonyPermissions
6923 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6924 mApp, phone.getSubId(), "getRadioAccessFamily");
6925 } catch (SecurityException e) {
6926 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6927 throw e;
6928 }
chen xub97461a2018-10-26 14:17:57 -07006929 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006930 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006931 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006933 final long identity = Binder.clearCallingIdentity();
6934 try {
chen xub97461a2018-10-26 14:17:57 -07006935 TelephonyPermissions
6936 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6937 mApp, phone.getSubId(), "getRadioAccessFamily");
6938 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
chen xub97461a2018-10-26 14:17:57 -07006942 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006943 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006944
6945 @Override
6946 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006947 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949
6950 final long identity = Binder.clearCallingIdentity();
6951 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006952 ImsManager.getInstance(defaultPhone.getContext(),
6953 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 } finally {
6955 Binder.restoreCallingIdentity(identity);
6956 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006957 }
6958
6959 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006960 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006961 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6963 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006964 return false;
6965 }
Svet Ganovb320e182015-04-16 12:30:10 -07006966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 // Check the user preference and the system-level IMS setting. Even if the user has
6970 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6971 // In the long run, we may instead need to check if there exists a connection service
6972 // which can support video calling.
6973 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006974 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 return imsManager.isVtEnabledByPlatform()
6976 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6977 && imsManager.isVtEnabledByUser();
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
6980 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006981 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006982
Andrew Leea1239f22015-03-02 17:44:07 -08006983 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006984 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6985 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006987 mApp, subId, callingPackage, callingFeatureId,
6988 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989 return false;
6990 }
6991
6992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 CarrierConfigManager configManager =
6995 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006996 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
Andrew Leea1239f22015-03-02 17:44:07 -08007001 }
7002
7003 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007004 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007006 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 return false;
7008 }
7009
7010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 CarrierConfigManager configManager =
7013 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007014 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
Andrew Leea1239f22015-03-02 17:44:07 -08007019 }
7020
Andrew Lee9431b832015-03-09 18:46:45 -07007021 @Override
7022 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007023 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007024 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007025 }
7026
7027 @Override
7028 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007031 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
Andrew Lee9431b832015-03-09 18:46:45 -07007035 }
7036
Hall Liuf6668912018-10-31 17:05:23 -07007037 /**
7038 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7039 * support for the feature and device firmware support.
7040 *
7041 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7042 */
7043 @Override
7044 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007046 final Phone phone = getPhone(subscriptionId);
7047 if (phone == null) {
7048 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7049 return false;
7050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007052 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7054 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007055 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 return isCarrierSupported && isDeviceSupported;
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
7059 }
Hall Liu98187582018-01-22 19:15:32 -08007060 }
7061
Hall Liuf6668912018-10-31 17:05:23 -07007062 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007063 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7064 * RTT setting, will return true if the device and carrier both support RTT.
7065 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007066 */
7067 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 final long identity = Binder.clearCallingIdentity();
7069 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007070 boolean isRttSupported = isRttSupported(subscriptionId);
7071 boolean isUserRttSettingOn = Settings.Secure.getInt(
7072 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7073 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7074 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7075 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 } finally {
7077 Binder.restoreCallingIdentity(identity);
7078 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007079 }
7080
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007081 @Deprecated
7082 @Override
7083 public String getDeviceId(String callingPackage) {
7084 return getDeviceIdWithFeature(callingPackage, null);
7085 }
7086
Sanket Padawe7310cc72015-01-14 09:53:20 -08007087 /**
7088 * Returns the unique device ID of phone, for example, the IMEI for
7089 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7090 *
7091 * <p>Requires Permission:
7092 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7093 */
7094 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007095 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007096 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007097 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007098 return null;
7099 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007100 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007101 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007102 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007103 return null;
7104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105
7106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 return phone.getDeviceId();
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
7111 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007112 }
7113
Ping Sunc67b7c22016-03-02 19:16:45 +08007114 /**
7115 * {@hide}
7116 * Returns the IMS Registration Status on a particular subid
7117 *
7118 * @param subId
7119 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007120 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007121 Phone phone = getPhone(subId);
7122 if (phone != null) {
7123 return phone.isImsRegistered();
7124 } else {
7125 return false;
7126 }
7127 }
7128
Santos Cordon7a1885b2015-02-03 11:15:19 -08007129 @Override
7130 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 final long identity = Binder.clearCallingIdentity();
7132 try {
7133 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007137 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007138
Tyler Gunnf70ed162019-04-03 15:28:53 -07007139 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007140 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007141 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007143 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007144 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7145 }
7146 final long identity = Binder.clearCallingIdentity();
7147 try {
7148 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151 }
7152 }
7153
7154 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007155 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007156 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7157 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007158 final long identity = Binder.clearCallingIdentity();
7159 try {
7160 Phone phone = getPhone(subscriptionId);
7161 if (phone == null) {
7162 return null;
7163 }
7164 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007170 /**
7171 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007172 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007173 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 Phone phone = getPhone(subId);
7177 if (phone != null) {
7178 return phone.isWifiCallingEnabled();
7179 } else {
7180 return false;
7181 }
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007184 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007185 }
7186
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007187 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007188 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007189 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007190 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 Phone phone = getPhone(subId);
7194 if (phone != null) {
7195 return phone.isVideoEnabled();
7196 } else {
7197 return false;
7198 }
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007201 }
7202 }
7203
7204 /**
7205 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7206 * defined in {@link ImsRegistrationImplBase}.
7207 */
7208 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 final long identity = Binder.clearCallingIdentity();
7210 try {
7211 Phone phone = getPhone(subId);
7212 if (phone != null) {
7213 return phone.getImsRegistrationTech();
7214 } else {
7215 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7216 }
7217 } finally {
7218 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007219 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007220 }
7221
Stuart Scott8eef64f2015-04-08 15:13:54 -07007222 @Override
7223 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007224 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007225 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7226 return;
7227 }
7228
Svet Ganovcc087f82015-05-12 20:35:54 -07007229 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007230
Svet Ganovcc087f82015-05-12 20:35:54 -07007231 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007232 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7233 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007234 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007235 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007236 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007237 setAllowedNetworkTypesForReason(subId,
7238 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7239 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7240 setAllowedNetworkTypesForReason(subId,
7241 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7242 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7243 setAllowedNetworkTypesForReason(subId,
7244 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7245 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007246 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7247 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007248 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007249 // There has been issues when Sms raw table somehow stores orphan
7250 // fragments. They lead to garbled message when new fragments come
7251 // in and combined with those stale ones. In case this happens again,
7252 // user can reset all network settings which will clean up this table.
7253 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007254 // Clean up IMS settings as well here.
7255 int slotId = getSlotIndex(subId);
7256 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7257 ImsManager.getInstance(mApp, slotId).factoryReset();
7258 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007259
7260 // Erase modem config if erase modem on network setting is enabled.
7261 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7262 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7263 if (configValue != null && Boolean.parseBoolean(configValue)) {
7264 sendEraseModemConfig(getDefaultPhone());
7265 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007266 } finally {
7267 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007268 }
7269 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007270
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007271 private void cleanUpSmsRawTable(Context context) {
7272 ContentResolver resolver = context.getContentResolver();
7273 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7274 resolver.delete(uri, null, null);
7275 }
7276
Narayan Kamath1c496c22015-04-16 14:40:19 +01007277 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007278 public String getSimLocaleForSubscriber(int subId) {
7279 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7280 final Phone phone = getPhone(subId);
7281 if (phone == null) {
7282 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007283 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007285 final long identity = Binder.clearCallingIdentity();
7286 try {
chen xu5d3637b2019-01-21 23:31:38 -08007287 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007288 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007289 if (info == null) {
7290 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7291 return null;
7292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 // Try and fetch the locale from the carrier properties or from the SIM language
7294 // preferences (EF-PL and EF-LI)...
7295 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007297 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7298 if (localeFromDefaultSim != null) {
7299 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7300 if (DBG) log("Using locale from subId: " + subId + " locale: "
7301 + localeFromDefaultSim);
7302 return localeFromDefaultSim.toLanguageTag();
7303 } else {
7304 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 }
7306 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 // The SIM language preferences only store a language (e.g. fr = French), not an
7309 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7310 // the SIM and carrier preferences does not include a country we add the country
7311 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007312 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007314 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 return mccLocale.toLanguageTag();
7316 }
7317
7318 if (DBG) log("No locale found - returning null");
7319 return null;
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007323 }
7324
7325 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007326 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007327 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007328 }
7329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 /**
7331 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7332 */
7333 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007334 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007335 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007336 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007337
Chenjie Yu1ba97252018-01-11 18:16:20 -08007338 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007339 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007340
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007341 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007342 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7343 * representing the state of the modem.
7344 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007345 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7346 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007347 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007348 */
7349 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007350 public void requestModemActivityInfo(ResultReceiver result) {
7351 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007352 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
sqian1a1be542020-03-05 11:37:28 -08007356 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 } finally {
7358 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007359 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007360 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007361
Siddharth Rayb8114062018-06-17 15:02:38 -07007362 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7363 // less than total activity duration.
7364 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7365 if (info == null) {
7366 return false;
7367 }
7368 int activityDurationMs =
7369 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7370 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007371 int[] txTimeMs = info.getTransmitTimeMillis();
7372 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7373 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007374 }
7375 return (info.isValid()
7376 && (info.getSleepTimeMillis() <= activityDurationMs)
7377 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007378 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007379 && (totalTxTimeMs <= activityDurationMs));
7380 }
7381
Jack Yu85bd38a2015-11-09 11:34:32 -08007382 /**
7383 * {@hide}
7384 * Returns the service state information on specified subscription.
7385 */
7386 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007387 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7388 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007390 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007391 return null;
7392 }
7393
Hall Liuf19c44f2018-11-27 14:38:17 -08007394 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7395 LocationAccessPolicy.checkLocationPermission(mApp,
7396 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7397 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007398 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007399 .setCallingPid(Binder.getCallingPid())
7400 .setCallingUid(Binder.getCallingUid())
7401 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007402 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007403 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7404 .build());
7405
7406 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7407 LocationAccessPolicy.checkLocationPermission(mApp,
7408 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7409 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007410 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007411 .setCallingPid(Binder.getCallingPid())
7412 .setCallingUid(Binder.getCallingUid())
7413 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007414 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007415 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7416 .build());
7417 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7418 boolean hasFinePermission =
7419 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7420 boolean hasCoarsePermission =
7421 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 final long identity = Binder.clearCallingIdentity();
7424 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007425 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7426 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7427 Rlog.d(LOG_TAG,
7428 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7429 return null;
7430 }
7431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 final Phone phone = getPhone(subId);
7433 if (phone == null) {
7434 return null;
7435 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007436
Hall Liuf19c44f2018-11-27 14:38:17 -08007437 ServiceState ss = phone.getServiceState();
7438
7439 // Scrub out the location info in ServiceState depending on what level of access
7440 // the caller has.
7441 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007442 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7443 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007447 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007448
7449 /**
7450 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7451 *
7452 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7453 * voicemail ringtone.
7454 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7455 * PhoneAccount.
7456 */
7457 @Override
7458 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 final long identity = Binder.clearCallingIdentity();
7460 try {
7461 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7462 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007470 }
7471
7472 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007473 * Sets the per-account voicemail ringtone.
7474 *
7475 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7476 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7477 *
7478 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7479 * voicemail ringtone.
7480 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7481 * PhoneAccount.
7482 */
7483 @Override
7484 public void setVoicemailRingtoneUri(String callingPackage,
7485 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007488 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7489 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7491 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7492 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494
7495 final long identity = Binder.clearCallingIdentity();
7496 try {
7497 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7498 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007499 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 }
7501 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007504 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007505 }
7506
7507 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007508 * Returns whether vibration is set for voicemail notification in Phone settings.
7509 *
7510 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7511 * voicemail vibration setting.
7512 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7513 */
7514 @Override
7515 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7519 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007527 }
7528
Youhan Wange64578a2016-05-02 15:32:42 -07007529 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007530 * Sets the per-account voicemail vibration.
7531 *
7532 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7533 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7534 *
7535 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7536 * voicemail vibration setting.
7537 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7538 * specific PhoneAccount.
7539 */
7540 @Override
7541 public void setVoicemailVibrationEnabled(String callingPackage,
7542 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007544 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007545 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7546 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7548 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7549 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007550 }
7551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7555 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007556 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 }
7558 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007561 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007562 }
7563
7564 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007565 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7566 *
7567 * @throws SecurityException if the caller does not have the required permission
7568 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007569 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007570 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007571 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007572 }
7573
7574 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007575 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7576 * permission.
7577 *
7578 * @throws SecurityException if the caller does not have the required permission
7579 */
7580 private void enforceSendSmsPermission() {
7581 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7582 }
7583
7584 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007585 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007586 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007587 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007588 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007589 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007593 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 if (componentName == null) {
7595 throw new SecurityException(
7596 "Caller not current active visual voicemail package[null]");
7597 }
7598 String vvmPackage = componentName.getPackageName();
7599 if (!callingPackage.equals(vvmPackage)) {
7600 throw new SecurityException("Caller not current active visual voicemail package["
7601 + vvmPackage + "]");
7602 }
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007605 }
7606 }
7607
7608 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007609 * Return the application ID for the app type.
7610 *
7611 * @param subId the subscription ID that this request applies to.
7612 * @param appType the uicc app type.
7613 * @return Application ID for specificied app type, or null if no uicc.
7614 */
7615 @Override
7616 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007617 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007618 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619
7620 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007621 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 if (phone == null) {
7623 return null;
7624 }
7625 String aid = null;
7626 try {
7627 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7628 .getApplicationByType(appType).getAid();
7629 } catch (Exception e) {
7630 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7631 }
7632 return aid;
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007635 }
Youhan Wange64578a2016-05-02 15:32:42 -07007636 }
7637
Youhan Wang4001d252016-05-11 10:29:41 -07007638 /**
7639 * Return the Electronic Serial Number.
7640 *
7641 * @param subId the subscription ID that this request applies to.
7642 * @return ESN or null if error.
7643 */
7644 @Override
7645 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007646 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007647 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648
7649 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007650 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 if (phone == null) {
7652 return null;
7653 }
7654 String esn = null;
7655 try {
7656 esn = phone.getEsn();
7657 } catch (Exception e) {
7658 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7659 }
7660 return esn;
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007663 }
Youhan Wang4001d252016-05-11 10:29:41 -07007664 }
7665
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007666 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007667 * Return the Preferred Roaming List Version.
7668 *
7669 * @param subId the subscription ID that this request applies to.
7670 * @return PRLVersion or null if error.
7671 */
7672 @Override
7673 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007674 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007675 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676
7677 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007678 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 if (phone == null) {
7680 return null;
7681 }
7682 String cdmaPrlVersion = null;
7683 try {
7684 cdmaPrlVersion = phone.getCdmaPrlVersion();
7685 } catch (Exception e) {
7686 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7687 }
7688 return cdmaPrlVersion;
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007691 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007692 }
7693
7694 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007695 * Get snapshot of Telephony histograms
7696 * @return List of Telephony histograms
7697 * @hide
7698 */
7699 @Override
7700 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7702 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703
7704 final long identity = Binder.clearCallingIdentity();
7705 try {
7706 return RIL.getTelephonyRILTimingHistograms();
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
7709 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007710 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007711
7712 /**
7713 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007714 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7715 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007716 * Require system privileges. In the future we may add this to carrier APIs.
7717 *
Michele Berionne482f8202018-11-27 18:57:59 -08007718 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007719 */
7720 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007721 @TelephonyManager.SetCarrierRestrictionResult
7722 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007723 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007724 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007725
Michele Berionne482f8202018-11-27 18:57:59 -08007726 if (carrierRestrictionRules == null) {
7727 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007728 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 final long identity = Binder.clearCallingIdentity();
7731 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007732 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007733 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 } finally {
7735 Binder.restoreCallingIdentity(identity);
7736 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007737 }
7738
7739 /**
7740 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007741 * Get the allowed carrier list and the excluded carrier list, including the priority between
7742 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007743 * Require system privileges. In the future we may add this to carrier APIs.
7744 *
Michele Berionne482f8202018-11-27 18:57:59 -08007745 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007746 */
7747 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007748 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007749 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007750 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751
7752 final long identity = Binder.clearCallingIdentity();
7753 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007754 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7755 if (response instanceof CarrierRestrictionRules) {
7756 return (CarrierRestrictionRules) response;
7757 }
7758 // Response is an Exception of some kind,
7759 // which is signalled to the user as a NULL retval
7760 return null;
7761 } catch (Exception e) {
7762 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7763 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 } finally {
7765 Binder.restoreCallingIdentity(identity);
7766 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007767 }
7768
fionaxu59545b42016-05-25 15:53:37 -07007769 /**
fionaxu59545b42016-05-25 15:53:37 -07007770 * Action set from carrier signalling broadcast receivers to enable/disable radio
7771 * @param subId the subscription ID that this action applies to.
7772 * @param enabled control enable or disable radio.
7773 * {@hide}
7774 */
7775 @Override
7776 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7777 enforceModifyPermission();
7778 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779
7780 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007781 if (phone == null) {
7782 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7783 return;
7784 }
7785 try {
7786 phone.carrierActionSetRadioEnabled(enabled);
7787 } catch (Exception e) {
7788 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 } finally {
7790 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007791 }
7792 }
7793
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007794 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007795 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7796 * network status based on which carrier apps could apply actions accordingly,
7797 * enable/disable default url handler for example.
7798 *
7799 * @param subId the subscription ID that this action applies to.
7800 * @param report control start/stop reporting the default network status.
7801 * {@hide}
7802 */
7803 @Override
7804 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7805 enforceModifyPermission();
7806 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807
7808 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007809 if (phone == null) {
7810 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7811 return;
7812 }
7813 try {
7814 phone.carrierActionReportDefaultNetworkStatus(report);
7815 } catch (Exception e) {
7816 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 } finally {
7818 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007819 }
7820 }
7821
7822 /**
fionaxud9622282017-07-17 17:51:30 -07007823 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7824 * @param subId the subscription ID that this action applies to.
7825 * {@hide}
7826 */
7827 @Override
7828 public void carrierActionResetAll(int subId) {
7829 enforceModifyPermission();
7830 final Phone phone = getPhone(subId);
7831 if (phone == null) {
7832 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7833 return;
7834 }
7835 try {
7836 phone.carrierActionResetAll();
7837 } catch (Exception e) {
7838 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7839 }
7840 }
7841
7842 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007843 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7844 * bug report is being generated.
7845 */
7846 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007847 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007848 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7849 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007850 writer.println("Permission Denial: can't dump Phone from pid="
7851 + Binder.getCallingPid()
7852 + ", uid=" + Binder.getCallingUid()
7853 + "without permission "
7854 + android.Manifest.permission.DUMP);
7855 return;
7856 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007857 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007858 }
Jack Yueb89b242016-06-22 13:27:47 -07007859
Brad Ebingerdac2f002018-04-03 15:17:52 -07007860 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007861 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7862 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7863 @NonNull String[] args) {
7864 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7865 this, in.getFileDescriptor(), out.getFileDescriptor(),
7866 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007867 }
7868
Jack Yueb89b242016-06-22 13:27:47 -07007869 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007870 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007871 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007872 * @param reason the reason the data enable change is taking place
7873 * @param enabled True if enabling the data, otherwise disabling.
7874 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007875 */
7876 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007877 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007878 boolean enabled) {
7879 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7880 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7881 try {
7882 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007883 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007884 } catch (SecurityException se) {
7885 enforceModifyPermission();
7886 }
7887 } else {
7888 enforceModifyPermission();
7889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 Phone phone = getPhone(subId);
7894 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007895 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7896 phone.carrierActionSetMeteredApnsEnabled(enabled);
7897 } else {
7898 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 }
7901 } finally {
7902 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007903 }
7904 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007905
7906 /**
7907 * Get Client request stats
7908 * @return List of Client Request Stats
7909 * @hide
7910 */
7911 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007912 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7913 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007915 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007916 return null;
7917 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007918 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 final long identity = Binder.clearCallingIdentity();
7921 try {
7922 if (phone != null) {
7923 return phone.getClientRequestStats();
7924 }
7925
7926 return null;
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
7929 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007930 }
7931
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007932 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007933 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007934 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007935 }
Jack Yueb4124c2017-02-16 15:32:43 -08007936
7937 /**
Grace Chen70990072017-03-24 17:21:30 -07007938 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007939 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007940 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007941 * @param state State of SIM (power down, power up, pass through)
7942 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7943 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7944 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007945 *
7946 **/
7947 @Override
Grace Chen70990072017-03-24 17:21:30 -07007948 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007949 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007950 Phone phone = PhoneFactory.getPhone(slotIndex);
7951
vagdeviaf9a5b92018-08-15 16:01:53 -07007952 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007957 phone.setSimPowerState(state, null, workSource);
7958 }
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
7962 }
7963
7964 /**
7965 * Set SIM card power state.
7966 *
7967 * @param slotIndex SIM slot id.
7968 * @param state State of SIM (power down, power up, pass through)
7969 * @param callback callback to trigger after success or failure
7970 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7971 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7972 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7973 *
7974 **/
7975 @Override
7976 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7977 IIntegerConsumer callback) {
7978 enforceModifyPermission();
7979 Phone phone = PhoneFactory.getPhone(slotIndex);
7980
7981 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7982
7983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 if (phone != null) {
7986 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7987 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 }
7989 } finally {
7990 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007991 }
7992 }
Shuo Qiandd210312017-04-12 22:11:33 +00007993
Tyler Gunn65d45c22017-06-05 11:22:26 -07007994 private boolean isUssdApiAllowed(int subId) {
7995 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007997 if (configManager == null) {
7998 return false;
7999 }
8000 PersistableBundle pb = configManager.getConfigForSubId(subId);
8001 if (pb == null) {
8002 return false;
8003 }
8004 return pb.getBoolean(
8005 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8006 }
8007
Shuo Qiandd210312017-04-12 22:11:33 +00008008 /**
8009 * Check if phone is in emergency callback mode
8010 * @return true if phone is in emergency callback mode
8011 * @param subId sub id
8012 */
goneil9c5f4872017-12-05 14:07:56 -08008013 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008014 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008015 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008016 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017
8018 final long identity = Binder.clearCallingIdentity();
8019 try {
8020 if (phone != null) {
8021 return phone.isInEcm();
8022 } else {
8023 return false;
8024 }
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008027 }
8028 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008029
8030 /**
8031 * Get the current signal strength information for the given subscription.
8032 * Because this information is not updated when the device is in a low power state
8033 * it should not be relied-upon to be current.
8034 * @param subId Subscription index
8035 * @return the most recent cached signal strength info from the modem
8036 */
8037 @Override
8038 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 Phone p = getPhone(subId);
8042 if (p == null) {
8043 return null;
8044 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 return p.getSignalStrength();
8047 } finally {
8048 Binder.restoreCallingIdentity(identity);
8049 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008050 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008051
Pengquan Meng77b7f132018-08-22 14:49:57 -07008052 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008053 * Get the current modem radio state for the given slot.
8054 * @param slotIndex slot index.
8055 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008056 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008057 * @return the current radio power state from the modem
8058 */
8059 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008060 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008061 Phone phone = PhoneFactory.getPhone(slotIndex);
8062 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8064 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008065 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8066 }
8067
8068 final long identity = Binder.clearCallingIdentity();
8069 try {
8070 return phone.getRadioPowerState();
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
8073 }
8074 }
8075 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8076 }
8077
8078 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008079 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8080 *
8081 * <p>Requires one of the following permissions:
8082 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8083 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8084 * privileges.
8085 *
8086 * @param subId subscription id
8087 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8088 * {@code false}.
8089 */
8090 @Override
8091 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008092 try {
8093 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8094 null);
8095 } catch (Exception e) {
8096 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8097 mApp, subId, "isDataRoamingEnabled");
8098 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008099
Pengquan Menga1bb6272018-09-06 09:59:22 -07008100 boolean isEnabled = false;
8101 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008102 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008103 Phone phone = getPhone(subId);
8104 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008105 } finally {
8106 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008108 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008109 }
8110
8111
8112 /**
8113 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8114 *
8115 * <p> Requires permission:
8116 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8117 * privileges.
8118 *
8119 * @param subId subscription id
8120 * @param isEnabled {@code true} means enable, {@code false} means disable.
8121 */
8122 @Override
8123 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8125 mApp, subId, "setDataRoamingEnabled");
8126
Pengquan Menga1bb6272018-09-06 09:59:22 -07008127 final long identity = Binder.clearCallingIdentity();
8128 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008129 Phone phone = getPhone(subId);
8130 if (phone != null) {
8131 phone.setDataRoamingEnabled(isEnabled);
8132 }
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008135 }
8136 }
8137
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008138 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008139 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008140 TelephonyPermissions
8141 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008142 mApp, subId, "isManualNetworkSelectionAllowed");
8143
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008144 boolean isAllowed = true;
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008147 Phone phone = getPhone(subId);
8148 if (phone != null) {
8149 isAllowed = phone.isCspPlmnEnabled();
8150 }
8151 } finally {
8152 Binder.restoreCallingIdentity(identity);
8153 }
8154 return isAllowed;
8155 }
8156
8157 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008158 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008159 // Verify that tha callingPackage belongs to the calling UID
8160 mApp.getSystemService(AppOpsManager.class)
8161 .checkPackage(Binder.getCallingUid(), callingPackage);
8162
Jordan Liu1e142fc2019-04-22 15:10:43 -07008163 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008164 try {
8165 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008166 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008167 } catch (SecurityException e) {
8168 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8169 // has carrier privileges on an active UICC
8170 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8171 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008172 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008173 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008174 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008175
8176 final long identity = Binder.clearCallingIdentity();
8177 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008178 UiccController uiccController = UiccController.getInstance();
8179 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008180 if (hasReadPermission) {
8181 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008182 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008183
8184 // Remove private info if the caller doesn't have access
8185 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8186 for (UiccCardInfo cardInfo : cardInfos) {
8187 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8188 // is available
8189 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8190 if (card == null || card.getUiccProfile() == null) {
8191 // assume no access if the card or profile is unavailable
8192 filteredInfos.add(cardInfo.getUnprivileged());
8193 continue;
8194 }
8195 UiccProfile profile = card.getUiccProfile();
8196 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8197 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8198 filteredInfos.add(cardInfo);
8199 } else {
8200 filteredInfos.add(cardInfo.getUnprivileged());
8201 }
8202 }
8203 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008204 } finally {
8205 Binder.restoreCallingIdentity(identity);
8206 }
8207 }
8208
8209 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008210 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008211 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8216 if (slots == null) {
8217 Rlog.i(LOG_TAG, "slots is null.");
8218 return null;
8219 }
8220
8221 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8222 for (int i = 0; i < slots.length; i++) {
8223 UiccSlot slot = slots[i];
8224 if (slot == null) {
8225 continue;
8226 }
8227
Jordan Liu7be7e652019-05-06 18:55:02 +00008228 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 UiccCard card = slot.getUiccCard();
8230 if (card != null) {
8231 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008232 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008233 cardId = slot.getEid();
8234 if (TextUtils.isEmpty(cardId)) {
8235 cardId = slot.getIccId();
8236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 }
8238
Jordan Liu857451f2019-05-09 16:35:35 -07008239 if (cardId != null) {
8240 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8241 // if cardId is an EID, it's all digits so this is fine
8242 cardId = IccUtils.stripTrailingFs(cardId);
8243 }
8244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 int cardState = 0;
8246 switch (slot.getCardState()) {
8247 case CARDSTATE_ABSENT:
8248 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8249 break;
8250 case CARDSTATE_PRESENT:
8251 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8252 break;
8253 case CARDSTATE_ERROR:
8254 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8255 break;
8256 case CARDSTATE_RESTRICTED:
8257 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8258 break;
8259 default:
8260 break;
8261
8262 }
8263
8264 infos[i] = new UiccSlotInfo(
8265 slot.isActive(),
8266 slot.isEuicc(),
8267 cardId,
8268 cardState,
8269 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008270 slot.isExtendedApduSupported(),
8271 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 }
8273 return infos;
8274 } finally {
8275 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008276 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008277 }
8278
8279 @Override
8280 public boolean switchSlots(int[] physicalSlots) {
8281 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8286 } finally {
8287 Binder.restoreCallingIdentity(identity);
8288 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008289 }
Jack Yu4c988042018-02-27 15:30:01 -08008290
8291 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008292 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 return UiccController.getInstance().getCardIdForDefaultEuicc();
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
8299 }
8300
Pengquan Meng85728fb2018-03-12 16:31:21 -07008301 /**
goneil47ffb6e2018-04-06 15:40:58 -07008302 * A test API to reload the UICC profile.
8303 *
8304 * <p>Requires that the calling app has permission
8305 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8306 * @hide
8307 */
8308 @Override
8309 public void refreshUiccProfile(int subId) {
8310 enforceModifyPermission();
8311
8312 final long identity = Binder.clearCallingIdentity();
8313 try {
8314 Phone phone = getPhone(subId);
8315 if (phone == null) {
8316 return;
8317 }
8318 UiccCard uiccCard = phone.getUiccCard();
8319 if (uiccCard == null) {
8320 return;
8321 }
8322 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8323 if (uiccProfile == null) {
8324 return;
8325 }
8326 uiccProfile.refresh();
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008333 * Returns false if the mobile data is disabled by default, otherwise return true.
8334 */
8335 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008336 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008337 }
8338
8339 /**
8340 * Returns true if the data roaming is enabled by default, i.e the system property
8341 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8342 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8343 */
8344 private boolean getDefaultDataRoamingEnabled(int subId) {
8345 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008346 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008347 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008348 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8349 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8350 return isDataRoamingEnabled;
8351 }
8352
8353 /**
8354 * Returns the default network type for the given {@code subId}, if the default network type is
8355 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8356 */
8357 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008358 List<Integer> list = TelephonyProperties.default_network();
8359 int phoneId = mSubscriptionController.getPhoneId(subId);
8360 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8361 return list.get(phoneId);
8362 }
8363 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008364 }
fionaxua13278b2018-03-21 00:08:13 -07008365
8366 @Override
8367 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008368 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008369 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370
8371 final long identity = Binder.clearCallingIdentity();
8372 try {
8373 final Phone phone = getPhone(subId);
8374 if (phone == null) {
8375 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8376 return;
8377 }
chen xueaba88a2019-03-15 13:15:10 -07008378 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8379 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008380 if (carrierPrivilegeRules == null) {
8381 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8382 } else {
8383 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 } finally {
8386 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008387 }
fionaxua13278b2018-03-21 00:08:13 -07008388 }
8389
8390 @Override
8391 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008392 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 final Phone phone = getPhone(subId);
8397 if (phone == null) {
8398 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8399 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8400 }
8401 return phone.getCarrierIdListVersion();
8402 } finally {
8403 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008404 }
fionaxua13278b2018-03-21 00:08:13 -07008405 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008406
8407 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008408 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8409 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008411 mApp, subId, callingPackage, callingFeatureId,
8412 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008413 return -1;
8414 }
8415
8416 final long identity = Binder.clearCallingIdentity();
8417 try {
8418 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
8421 }
8422 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008423
8424 @Override
8425 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008426 TelephonyPermissions
8427 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008428 mApp, subId, "getCdmaRoamingMode");
8429
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8433 } finally {
8434 Binder.restoreCallingIdentity(identity);
8435 }
8436 }
8437
8438 @Override
8439 public boolean setCdmaRoamingMode(int subId, int mode) {
8440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8441 mApp, subId, "setCdmaRoamingMode");
8442
8443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
8449 }
8450
8451 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008452 public int getCdmaSubscriptionMode(int subId) {
8453 TelephonyPermissions
8454 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8455 mApp, subId, "getCdmaSubscriptionMode");
8456
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
8462 }
8463 }
8464
8465 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008466 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8468 mApp, subId, "setCdmaSubscriptionMode");
8469
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008477
sqianc5eccab2018-10-19 18:46:41 -07008478 @Override
sqian8c685422019-02-22 15:55:18 -08008479 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008480 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008482 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8483 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008484 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8485 }
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
sqian854d44b2018-12-12 16:48:18 -08008488 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8489 for (Phone phone: PhoneFactory.getPhones()) {
8490 if (phone.getEmergencyNumberTracker() != null
8491 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8492 emergencyNumberListInternal.put(
8493 phone.getSubId(),
8494 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8495 }
sqian11b7a0e2018-12-05 18:48:28 -08008496 }
sqian854d44b2018-12-12 16:48:18 -08008497 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008498 } finally {
8499 Binder.restoreCallingIdentity(identity);
8500 }
sqianc5eccab2018-10-19 18:46:41 -07008501 }
8502
8503 @Override
sqian8c685422019-02-22 15:55:18 -08008504 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008505 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008506 if (!exactMatch) {
8507 TelephonyPermissions
8508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008509 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008510 }
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
sqian854d44b2018-12-12 16:48:18 -08008513 for (Phone phone: PhoneFactory.getPhones()) {
8514 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008515 && phone.getEmergencyNumberTracker()
8516 .isEmergencyNumber(number, exactMatch)) {
8517 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008518 }
sqian11b7a0e2018-12-05 18:48:28 -08008519 }
8520 return false;
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
8524 }
8525
sqianf4ca7ed2019-01-15 18:32:07 -08008526 /**
8527 * Update emergency number list for test mode.
8528 */
8529 @Override
8530 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8531 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8532 "updateEmergencyNumberListTestMode");
8533
8534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 for (Phone phone: PhoneFactory.getPhones()) {
8537 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8538 if (tracker != null) {
8539 tracker.executeEmergencyNumberTestModeCommand(action, num);
8540 }
8541 }
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
8547 /**
8548 * Get the full emergency number list for test mode.
8549 */
8550 @Override
8551 public List<String> getEmergencyNumberListTestMode() {
8552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8553 "getEmergencyNumberListTestMode");
8554
8555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 Set<String> emergencyNumbers = new HashSet<>();
8558 for (Phone phone: PhoneFactory.getPhones()) {
8559 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8560 if (tracker != null) {
8561 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8562 emergencyNumbers.add(num.getNumber());
8563 }
8564 }
8565 }
8566 return new ArrayList<>(emergencyNumbers);
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
8569 }
8570 }
8571
chen xud6b45bd2018-10-30 22:27:10 -07008572 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008573 public int getEmergencyNumberDbVersion(int subId) {
8574 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 final Phone phone = getPhone(subId);
8579 if (phone == null) {
8580 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8581 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8582 }
8583 return phone.getEmergencyNumberDbVersion();
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
8586 }
8587 }
8588
8589 @Override
8590 public void notifyOtaEmergencyNumberDbInstalled() {
8591 enforceModifyPermission();
8592
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 for (Phone phone: PhoneFactory.getPhones()) {
8596 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8597 if (tracker != null) {
8598 tracker.updateOtaEmergencyNumberDatabase();
8599 }
8600 }
8601 } finally {
8602 Binder.restoreCallingIdentity(identity);
8603 }
8604 }
8605
8606 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008607 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008608 enforceActiveEmergencySessionPermission();
8609
8610 final long identity = Binder.clearCallingIdentity();
8611 try {
8612 for (Phone phone: PhoneFactory.getPhones()) {
8613 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8614 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008615 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8616 }
8617 }
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
8623 @Override
8624 public void resetOtaEmergencyNumberDbFilePath() {
8625 enforceActiveEmergencySessionPermission();
8626
8627 final long identity = Binder.clearCallingIdentity();
8628 try {
8629 for (Phone phone: PhoneFactory.getPhones()) {
8630 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8631 if (tracker != null) {
8632 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008633 }
8634 }
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
8638 }
8639
8640 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008641 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8642 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8643 Phone phone = getPhone(subId);
8644 if (phone == null) {
8645 return null;
8646 }
8647 final long identity = Binder.clearCallingIdentity();
8648 try {
8649 UiccProfile profile = UiccController.getInstance()
8650 .getUiccProfileForPhone(phone.getPhoneId());
8651 if (profile != null) {
8652 return profile.getCertsFromCarrierPrivilegeAccessRules();
8653 }
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
8657 return null;
8658 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008659
8660 /**
8661 * Enable or disable a modem stack.
8662 */
8663 @Override
8664 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8665 enforceModifyPermission();
8666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 Phone phone = PhoneFactory.getPhone(slotIndex);
8670 if (phone == null) {
8671 return false;
8672 } else {
8673 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8674 }
8675 } finally {
8676 Binder.restoreCallingIdentity(identity);
8677 }
8678 }
Michelecea4cf22018-12-21 15:00:11 -08008679
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008680 /**
8681 * Whether a modem stack is enabled or not.
8682 */
8683 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008684 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8685 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008686 Phone phone = PhoneFactory.getPhone(slotIndex);
8687 if (phone == null) return false;
8688
8689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008690 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8691 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008692 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8693 }
8694
8695 final long identity = Binder.clearCallingIdentity();
8696 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008697 try {
8698 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8699 } catch (NoSuchElementException ex) {
8700 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8701 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008702 } finally {
8703 Binder.restoreCallingIdentity(identity);
8704 }
8705 }
8706
Michelecea4cf22018-12-21 15:00:11 -08008707 @Override
Michele0ea7d782019-03-19 14:58:42 -07008708 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008709 enforceModifyPermission();
8710
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008714 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008715 .commit();
8716 } finally {
8717 Binder.restoreCallingIdentity(identity);
8718 }
8719 }
8720
8721 @Override
Michele0ea7d782019-03-19 14:58:42 -07008722 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008723 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008725 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8726 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008727 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008728 }
Michelecea4cf22018-12-21 15:00:11 -08008729
8730 final long identity = Binder.clearCallingIdentity();
8731 try {
Michele0ea7d782019-03-19 14:58:42 -07008732 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008733 } finally {
8734 Binder.restoreCallingIdentity(identity);
8735 }
8736 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008737
Michele0ea7d782019-03-19 14:58:42 -07008738 @TelephonyManager.IsMultiSimSupportedResult
8739 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008740 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8741 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8742 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008743 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8744 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008745 }
8746 // Check if the hardware supports multisim functionality. If usage of multisim is not
8747 // supported by the modem, indicate that it is restricted.
8748 PhoneCapability staticCapability =
8749 mPhoneConfigurationManager.getStaticPhoneCapability();
8750 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008751 loge("isMultiSimSupportedInternal: no static configuration available");
8752 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008753 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008754 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008755 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8756 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008757 }
8758 // Check if support of multiple SIMs is restricted by carrier
8759 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008760 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008761 }
8762
Michele0ea7d782019-03-19 14:58:42 -07008763 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008764 }
8765
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008766 /**
8767 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008768 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8769 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8770 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008771 * @param numOfSims number of active sims we want to switch to
8772 */
8773 @Override
8774 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008775 if (numOfSims == 1) {
8776 enforceModifyPermission();
8777 } else {
8778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8779 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8780 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008781 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008782
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008783 try {
Michele30b57b22019-03-01 12:01:14 -08008784 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008785 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008786 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8787 return;
8788 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008789 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8790 } finally {
8791 Binder.restoreCallingIdentity(identity);
8792 }
8793 }
8794
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008795 @Override
8796 public boolean isApplicationOnUicc(int subId, int appType) {
8797 enforceReadPrivilegedPermission("isApplicationOnUicc");
8798 Phone phone = getPhone(subId);
8799 if (phone == null) {
8800 return false;
8801 }
8802 final long identity = Binder.clearCallingIdentity();
8803 try {
8804 UiccCard uiccCard = phone.getUiccCard();
8805 if (uiccCard == null) {
8806 return false;
8807 }
8808 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8809 if (uiccProfile == null) {
8810 return false;
8811 }
8812 if (TelephonyManager.APPTYPE_SIM <= appType
8813 && appType <= TelephonyManager.APPTYPE_ISIM) {
8814 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8815 }
8816 return false;
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008822 /**
chen xub4baa772019-04-03 10:23:41 -07008823 * Get whether making changes to modem configurations will trigger reboot.
8824 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008825 */
8826 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008827 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8828 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008830 mApp, subId, callingPackage, callingFeatureId,
8831 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008832 return false;
8833 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008834 final long identity = Binder.clearCallingIdentity();
8835 try {
8836 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8837 } finally {
8838 Binder.restoreCallingIdentity(identity);
8839 }
8840 }
8841
Nathan Harold29f5f052019-02-15 13:41:57 -08008842 private void updateModemStateMetrics() {
8843 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8844 // TODO: check the state for each modem if the api is ready.
8845 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8846 }
8847
Pengquan Meng3889a572019-01-23 11:16:29 -08008848 @Override
8849 public int[] getSlotsMapping() {
8850 enforceReadPrivilegedPermission("getSlotsMapping");
8851
8852 final long identity = Binder.clearCallingIdentity();
8853 try {
8854 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8855 // All logical slots should have a mapping to a physical slot.
8856 int[] logicalSlotsMapping = new int[phoneCount];
8857 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8858 for (int i = 0; i < slotInfos.length; i++) {
8859 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8860 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8861 }
8862 }
8863 return logicalSlotsMapping;
8864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
8867 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008868
8869 /**
8870 * Get the IRadio HAL Version
8871 */
8872 @Override
8873 public int getRadioHalVersion() {
8874 Phone phone = getDefaultPhone();
8875 if (phone == null) return -1;
8876 HalVersion hv = phone.getHalVersion();
8877 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8878 return hv.major * 100 + hv.minor;
8879 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008880
8881 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008882 * Get the current calling package name.
8883 * @return the current calling package name
8884 */
8885 @Override
8886 public String getCurrentPackageName() {
8887 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8888 }
8889
8890 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008891 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8892 * corresponding network requests on a subId.
8893 *
8894 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008895 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008896 * 2) APN is un-metered for this subscription, or
8897 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008898 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008899 *
8900 * @return whether data is allowed for a apn type.
8901 *
8902 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008903 */
8904 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008905 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008906 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8907 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008908
8909 // Now that all security checks passes, perform the operation as ourselves.
8910 final long identity = Binder.clearCallingIdentity();
8911 try {
8912 Phone phone = getPhone(subId);
8913 if (phone == null) return false;
8914
Jack Yu41407ee2019-05-13 16:54:09 -07008915 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008916 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8917 } finally {
8918 Binder.restoreCallingIdentity(identity);
8919 }
8920 }
8921
8922 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008923 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008924 enforceReadPrivilegedPermission("isApnMetered");
8925
8926 // Now that all security checks passes, perform the operation as ourselves.
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 Phone phone = getPhone(subId);
8930 if (phone == null) return true; // By default return true.
8931
Jack Yu41407ee2019-05-13 16:54:09 -07008932 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
8936 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008937
8938 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008939 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8940 int subscriptionId, IBooleanConsumer resultCallback) {
8941 enforceModifyPermission();
8942 long token = Binder.clearCallingIdentity();
8943 try {
8944 Phone phone = getPhone(subscriptionId);
8945 if (phone == null) {
8946 try {
8947 if (resultCallback != null) {
8948 resultCallback.accept(false);
8949 }
8950 } catch (RemoteException e) {
8951 // ignore
8952 }
8953 return;
8954 }
8955 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8956 Pair.create(specifiers, (x) -> {
8957 try {
8958 if (resultCallback != null) {
8959 resultCallback.accept(x);
8960 }
8961 } catch (RemoteException e) {
8962 // ignore
8963 }
8964 });
8965 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8966 } finally {
8967 Binder.restoreCallingIdentity(token);
8968 }
8969 }
8970
8971 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008972 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8973 TelephonyPermissions
8974 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8975 mApp, subId, "getSystemSelectionChannels");
8976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 List<RadioAccessSpecifier> specifiers =
8980 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8981 null, subId, workSource);
8982 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8983 return specifiers;
8984 } finally {
8985 Binder.restoreCallingIdentity(identity);
8986 }
8987 }
8988
8989 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008990 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008991 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008992 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8993 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8994 if (iccRecords == null) {
8995 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8996 return false;
8997 }
8998 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8999 }
9000
9001 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009002 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9003 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009004 if (callingPackage == null) {
9005 callingPackage = getCurrentPackageName();
9006 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009007 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9008 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009009 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9010 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009011 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9012 }
9013 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9014 Intent intent = new Intent();
9015 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9016 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9017 // Bring up choose default SMS subscription dialog right now
9018 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9019 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9020 mApp.startActivity(intent);
9021 }
chen xud5ca2d52019-05-28 15:20:57 -07009022
9023 @Override
9024 public String getMmsUAProfUrl(int subId) {
9025 //TODO investigate if this API should require proper permission check in R b/133791609
9026 final long identity = Binder.clearCallingIdentity();
9027 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009028 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9029 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9030 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9031 return carrierUAProfUrl;
9032 }
chen xud5ca2d52019-05-28 15:20:57 -07009033 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9034 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
9041 public String getMmsUserAgent(int subId) {
9042 //TODO investigate if this API should require proper permission check in R b/133791609
9043 final long identity = Binder.clearCallingIdentity();
9044 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009045 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9046 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9047 if (!TextUtils.isEmpty(carrierUserAgent)) {
9048 return carrierUserAgent;
9049 }
chen xud5ca2d52019-05-28 15:20:57 -07009050 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9051 .getString(com.android.internal.R.string.config_mms_user_agent);
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
Jack Yub07d4972019-05-28 16:12:25 -07009056
9057 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009058 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9059 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9060
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
9063 Phone phone = getPhone(subscriptionId);
9064 if (phone == null) return false;
9065
9066 switch (policy) {
9067 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9068 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9069 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9070 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9071 default:
9072 throw new IllegalArgumentException(policy + " is not a valid policy");
9073 }
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
9077 }
9078
9079 @Override
9080 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9081 boolean enabled) {
9082 enforceModifyPermission();
9083
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
9086 Phone phone = getPhone(subscriptionId);
9087 if (phone == null) return;
9088
9089 switch (policy) {
9090 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9091 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9092 break;
9093 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9094 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9095 break;
9096 default:
9097 throw new IllegalArgumentException(policy + " is not a valid policy");
9098 }
9099 } finally {
9100 Binder.restoreCallingIdentity(identity);
9101 }
9102 }
9103
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009104 /**
Hall Liub48cf452020-09-25 11:13:49 -07009105 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009106 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9107 * otherwise.
9108 */
9109 @Override
9110 public void setCepEnabled(boolean isCepEnabled) {
9111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9112
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9116 for (Phone phone : PhoneFactory.getPhones()) {
9117 Phone defaultPhone = phone.getImsPhone();
9118 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9119 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9120 ImsPhoneCallTracker imsPhoneCallTracker =
9121 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9122 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9123 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9124 + imsPhone.getMsisdn());
9125 }
9126 }
9127 } finally {
9128 Binder.restoreCallingIdentity(identity);
9129 }
9130 }
allenwtsu46dcc572020-01-08 18:24:03 +08009131
9132 /**
9133 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9134 *
9135 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9136 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9137 * before being read.
9138 */
9139 @Override
9140 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9141 isCompressed) {
9142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9143 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9145 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9146 }
9147 if (!isImsAvailableOnDevice()) {
9148 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9149 "IMS not available on device.");
9150 }
9151
9152 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009153 try {
Hui Wang068ab862020-10-31 05:12:53 +00009154 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009157 }
9158 }
zoey chenf95ca592019-12-30 16:11:23 +08009159
9160 @Override
9161 public boolean isIccLockEnabled(int subId) {
9162 enforceReadPrivilegedPermission("isIccLockEnabled");
9163
9164 // Now that all security checks passes, perform the operation as ourselves.
9165 final long identity = Binder.clearCallingIdentity();
9166 try {
9167 Phone phone = getPhone(subId);
9168 if (phone != null && phone.getIccCard() != null) {
9169 return phone.getIccCard().getIccLockEnabled();
9170 } else {
9171 return false;
9172 }
9173 } finally {
9174 Binder.restoreCallingIdentity(identity);
9175 }
9176 }
9177
9178 /**
zoey chene02881a2019-12-30 16:11:23 +08009179 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009180 *
zoey chene02881a2019-12-30 16:11:23 +08009181 * @return an integer representing the status of IccLock enabled or disabled in the following
9182 * three cases:
9183 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9184 * successfully.
9185 * - Positive number and zero for remaining password attempts.
9186 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009187 *
9188 */
9189 @Override
9190 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9191 enforceModifyPermission();
9192
9193 Phone phone = getPhone(subId);
9194 if (phone == null) {
9195 return 0;
9196 }
9197 // Now that all security checks passes, perform the operation as ourselves.
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
9200 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9201 new Pair<Boolean, String>(enabled, password), phone, null);
9202 return attemptsRemaining;
9203
9204 } catch (Exception e) {
9205 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9206 } finally {
9207 Binder.restoreCallingIdentity(identity);
9208 }
9209 return 0;
9210 }
9211
9212 /**
9213 * Change the ICC password used in ICC pin lock.
9214 *
zoey chene02881a2019-12-30 16:11:23 +08009215 * @return an integer representing the status of IccLock changed in the following three cases:
9216 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9217 * - Positive number and zero for remaining password attempts.
9218 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009219 *
9220 */
9221 @Override
9222 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9223 enforceModifyPermission();
9224
9225 Phone phone = getPhone(subId);
9226 if (phone == null) {
9227 return 0;
9228 }
9229 // Now that all security checks passes, perform the operation as ourselves.
9230 final long identity = Binder.clearCallingIdentity();
9231 try {
9232 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9233 new Pair<String, String>(oldPassword, newPassword), phone, null);
9234 return attemptsRemaining;
9235
9236 } catch (Exception e) {
9237 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9238 } finally {
9239 Binder.restoreCallingIdentity(identity);
9240 }
9241 return 0;
9242 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009243
Peter Wangdafb9ac2020-01-15 14:13:38 -08009244 /**
9245 * Request for receiving user activity notification
9246 */
9247 @Override
9248 public void requestUserActivityNotification() {
9249 if (!mNotifyUserActivity.get()
9250 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9251 mNotifyUserActivity.set(true);
9252 }
9253 }
9254
9255 /**
9256 * Called when userActivity is signalled in the power manager.
9257 * This is safe to call from any thread, with any window manager locks held or not.
9258 */
9259 @Override
9260 public void userActivity() {
9261 // ***************************************
9262 // * Inherited from PhoneWindowManager *
9263 // ***************************************
9264 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9265 // WITH ITS LOCKS HELD.
9266 //
9267 // This code must be VERY careful about the locks
9268 // it acquires.
9269 // In fact, the current code acquires way too many,
9270 // and probably has lurking deadlocks.
9271
9272 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9273 throw new SecurityException("Only the OS may call notifyUserActivity()");
9274 }
9275
9276 if (mNotifyUserActivity.getAndSet(false)) {
9277 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9278 USER_ACTIVITY_NOTIFICATION_DELAY);
9279 }
9280 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009281
Malcolm Chen884180b2020-04-13 11:59:40 -07009282 @Override
9283 public boolean canConnectTo5GInDsdsMode() {
9284 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9285 }
Jack Yud10cdd42020-09-28 20:28:01 -07009286
9287 @Override
9288 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9289 String callingFeatureId) {
9290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9291 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9292 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9293 }
9294
9295 Phone phone = getPhone(subId);
9296 if (phone == null) {
9297 throw new RuntimeException("phone is not available");
9298 }
9299 // Now that all security checks passes, perform the operation as ourselves.
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
9302 return phone.getEquivalentHomePlmns();
9303 } finally {
9304 Binder.restoreCallingIdentity(identity);
9305 }
9306 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009307
Hui Wang0866fcc2020-10-12 12:14:23 -07009308 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009309 public boolean isRadioInterfaceCapabilitySupported(
9310 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009311 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009312 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009313 if (radioInterfaceCapabilities == null) {
9314 throw new RuntimeException("radio interface capabilities are not available");
9315 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009316 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009317 }
9318 }
9319
9320 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009321 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9322 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009323 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9324 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9325 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9326 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9327 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009328 if (DBG) {
9329 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9330 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9331 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9332 }
9333
9334 if (!SubscriptionManager.isValidSubscriptionId(subId)
9335 || appType < TelephonyManager.APPTYPE_UNKNOWN
9336 || appType > TelephonyManager.APPTYPE_ISIM
9337 || nafUrl == null || securityProtocol == null || callback == null) {
9338 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9339 if (callback != null) {
9340 try {
9341 callback.onAuthenticationFailure(
9342 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9343 } catch (RemoteException exception) {
9344 log("Fail to notify onAuthenticationFailure due to " + exception);
9345 }
9346 return;
9347 }
9348 }
9349
9350 final long token = Binder.clearCallingIdentity();
9351 try {
9352 getGbaManager(subId).bootstrapAuthenticationRequest(
9353 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9354 forceBootStrapping, callback));
9355 } finally {
9356 Binder.restoreCallingIdentity(token);
9357 }
9358 }
9359
Jack Nudelman24d51a52020-11-24 12:08:04 -08009360 /**
9361 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9362 * requested radio power state will actually be set. See {@link
9363 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9364 *
9365 * @param subId the subscription ID of the phone requesting to set the radio power state.
9366 * @param enable {@code true} if trying to turn radio on.
9367 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9368 * false}.
9369 */
9370 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9371 Phone phone = getPhone(subId);
9372 if (phone != null) {
9373 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9374 return true;
9375 }
9376 return false;
9377 }
9378
9379 private int handleDataThrottlingRequest(int subId,
9380 DataThrottlingRequest dataThrottlingRequest) {
9381 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9382 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9383 if (!setRadioPowerForThermal(subId, true)) {
9384 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9385 }
9386
9387 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9388
9389 int thermalMitigationResult =
9390 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9391 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9392 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9393 }
9394 return thermalMitigationResult;
9395 }
9396
9397 /**
9398 * Thermal mitigation request to control functionalities at modem.
9399 *
9400 * @param subId the id of the subscription.
9401 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9402 *
9403 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9404 */
9405 @Override
9406 @ThermalMitigationResult
9407 public int sendThermalMitigationRequest(
9408 int subId,
9409 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9410 enforceModifyPermission();
9411
9412 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9413 final long identity = Binder.clearCallingIdentity();
9414
9415 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9416 try {
9417 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9418 switch (thermalMitigationAction) {
9419 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9420 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009421 handleDataThrottlingRequest(subId,
9422 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009423 break;
9424 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9425 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9426 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9427 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9428 }
9429
9430 // Ensure that radio is on. If not able to power on due to phone being
9431 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9432 if (!setRadioPowerForThermal(subId, true)) {
9433 thermalMitigationResult =
9434 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9435 break;
9436 }
9437
9438 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9439 false);
9440 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9441 break;
9442 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9443 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9444 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9445 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9446 }
9447
9448 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9449 if (registry != null) {
9450 TelephonyConnectionService service =
9451 registry.getTelephonyConnectionService();
9452 Phone phone = getPhone(subId);
9453 if (phone == null) {
9454 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009455 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009456 break;
9457 }
9458
9459 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009460 != TelephonyManager.CALL_STATE_IDLE
9461 || phone.isInEmergencySmsMode() || phone.isInEcm()
9462 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009463 String errorMessage = "Phone state is not valid. call state = "
9464 + PhoneConstantConversions.convertCallState(phone.getState())
9465 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9466 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9467 errorMessage += service == null
9468 ? " TelephonyConnectionService is null"
9469 : " isEmergencyCallPending = "
9470 + service.isEmergencyCallPending();
9471 Log.e(LOG_TAG, errorMessage);
9472 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009473 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009474 break;
9475 }
9476 } else {
9477 thermalMitigationResult =
9478 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9479 break;
9480 }
9481
9482 // Turn radio off. If not able to power off due to phone being unavailable,
9483 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9484 if (!setRadioPowerForThermal(subId, false)) {
9485 thermalMitigationResult =
9486 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9487 break;
9488 }
9489 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009490 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009491 break;
9492 default:
9493 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9494 + "not exist. Requested action: " + thermalMitigationAction);
9495 }
9496 } catch (IllegalArgumentException e) {
9497 throw e;
9498 } catch (Exception e) {
9499 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9500 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9501 } finally {
9502 Binder.restoreCallingIdentity(identity);
9503 }
9504
9505 if (DBG) {
9506 log("thermalMitigationRequest returning with thermalMitigationResult: "
9507 + thermalMitigationResult);
9508 }
9509
9510 return thermalMitigationResult;
9511 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009512
9513 /**
9514 * Set the GbaService Package Name that Telephony will bind to.
9515 *
9516 * @param subId The sim that the GbaService is associated with.
9517 * @param packageName The name of the package to be replaced with.
9518 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9519 */
9520 @Override
9521 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9522 enforceModifyPermission();
9523
9524 final long identity = Binder.clearCallingIdentity();
9525 try {
9526 return getGbaManager(subId).overrideServicePackage(packageName);
9527 } finally {
9528 Binder.restoreCallingIdentity(identity);
9529 }
9530 }
9531
9532 /**
9533 * Return the package name of the currently bound GbaService.
9534 *
9535 * @param subId The sim that the GbaService is associated with.
9536 * @return the package name of the GbaService configuration, null if GBA is not supported.
9537 */
9538 @Override
9539 public String getBoundGbaService(int subId) {
9540 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9541
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 return getGbaManager(subId).getServicePackage();
9545 } finally {
9546 Binder.restoreCallingIdentity(identity);
9547 }
9548 }
9549
9550 /**
9551 * Set the release time for telephony to unbind GbaService.
9552 *
9553 * @param subId The sim that the GbaService is associated with.
9554 * @param interval The release time to unbind GbaService by millisecond.
9555 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9556 */
9557 @Override
9558 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9559 enforceModifyPermission();
9560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
9563 return getGbaManager(subId).overrideReleaseTime(interval);
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
9569 /**
9570 * Return the release time for telephony to unbind GbaService.
9571 *
9572 * @param subId The sim that the GbaService is associated with.
9573 * @return The release time to unbind GbaService by millisecond.
9574 */
9575 @Override
9576 public int getGbaReleaseTime(int subId) {
9577 enforceReadPrivilegedPermission("getGbaReleaseTime");
9578
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
9581 return getGbaManager(subId).getReleaseTime();
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
9586
9587 private GbaManager getGbaManager(int subId) {
9588 GbaManager instance = GbaManager.getInstance(subId);
9589 if (instance == null) {
9590 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9591 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9592 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9593 }
9594 return instance;
9595 }
Hui Wang068ab862020-10-31 05:12:53 +00009596
9597 /**
9598 * indicate whether the device and the carrier can support
9599 * RCS VoLTE single registration.
9600 */
9601 @Override
9602 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009603 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9604 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9605 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9606 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009607
9608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9610 }
9611
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9615 if (rpm != null) {
9616 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9617 }
9618 return false;
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
9624 /**
9625 * Register RCS provisioning callback.
9626 */
9627 @Override
9628 public void registerRcsProvisioningChangedCallback(int subId,
9629 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009630 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9631 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9632 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9633 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009634
9635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9636 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9637 }
9638 if (!isImsAvailableOnDevice()) {
9639 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9640 "IMS not available on device.");
9641 }
9642
9643 final long identity = Binder.clearCallingIdentity();
9644 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009645 if (!RcsProvisioningMonitor.getInstance()
9646 .registerRcsProvisioningChangedCallback(subId, callback)) {
9647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9648 "Service not available for the subscription.");
9649 }
Hui Wang068ab862020-10-31 05:12:53 +00009650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 /**
9656 * Unregister RCS provisioning callback.
9657 */
9658 @Override
9659 public void unregisterRcsProvisioningChangedCallback(int subId,
9660 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009661 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9662 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9663 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9664 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009665
9666 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9667 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9668 }
9669 if (!isImsAvailableOnDevice()) {
9670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9671 "IMS not available on device.");
9672 }
9673
9674 final long identity = Binder.clearCallingIdentity();
9675 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009676 RcsProvisioningMonitor.getInstance()
9677 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009678 } finally {
9679 Binder.restoreCallingIdentity(identity);
9680 }
9681 }
9682
9683 /**
9684 * trigger RCS reconfiguration.
9685 */
9686 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009687 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9688 "triggerRcsReconfiguration",
9689 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009690
9691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9692 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9693 }
9694 if (!isImsAvailableOnDevice()) {
9695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9696 "IMS not available on device.");
9697 }
9698
9699 final long identity = Binder.clearCallingIdentity();
9700 try {
9701 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9702 } finally {
9703 Binder.restoreCallingIdentity(identity);
9704 }
9705 }
9706
9707 /**
9708 * Provide the client configuration parameters of the RCS application.
9709 */
9710 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009711 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9712 "setRcsClientConfiguration",
9713 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009714
9715 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9716 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9717 }
9718 if (!isImsAvailableOnDevice()) {
9719 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9720 "IMS not available on device.");
9721 }
9722
9723 final long identity = Binder.clearCallingIdentity();
9724
9725 try {
9726 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9727 if (configBinder == null) {
9728 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9729 } else {
9730 configBinder.setRcsClientConfiguration(rcc);
9731 }
9732 } catch (RemoteException e) {
9733 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9734 } finally {
9735 Binder.restoreCallingIdentity(identity);
9736 }
9737 }
9738
9739 /**
Hui Wang19a21872021-02-19 20:45:36 -08009740 * Enables or disables the test mode for RCS VoLTE single registration.
9741 */
9742 @Override
9743 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9745 "setRcsSingleRegistrationTestModeEnabled");
9746
9747 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9748 }
9749
9750 /**
9751 * Gets the test mode for RCS VoLTE single registration.
9752 */
9753 @Override
9754 public boolean getRcsSingleRegistrationTestModeEnabled() {
9755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9756 "getRcsSingleRegistrationTestModeEnabled");
9757
9758 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9759 }
9760
9761 /**
Hui Wang068ab862020-10-31 05:12:53 +00009762 * Overrides the config of RCS VoLTE single registration enabled for the device.
9763 */
9764 @Override
9765 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9767 "setDeviceSingleRegistrationEnabledOverride");
9768 enforceModifyPermission();
9769
9770 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9771 : Boolean.parseBoolean(enabledStr);
9772 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009773 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009774 }
9775
9776 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009777 * Sends a device to device communication message. Only usable via shell.
9778 * @param message message to send.
9779 * @param value message value.
9780 */
9781 @Override
9782 public void sendDeviceToDeviceMessage(int message, int value) {
9783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9784 "setCarrierSingleRegistrationEnabledOverride");
9785 enforceModifyPermission();
9786
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 TelephonyConnectionService service =
9790 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9791 if (service == null) {
9792 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9793 return;
9794 }
9795 service.sendTestDeviceToDeviceMessage(message, value);
9796 } finally {
9797 Binder.restoreCallingIdentity(identity);
9798 }
9799 }
9800
9801
9802 /**
Hui Wang068ab862020-10-31 05:12:53 +00009803 * Gets the config of RCS VoLTE single registration enabled for the device.
9804 */
9805 @Override
9806 public boolean getDeviceSingleRegistrationEnabled() {
9807 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9808 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9809 }
9810
9811 /**
9812 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9813 */
9814 @Override
9815 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9817 "setCarrierSingleRegistrationEnabledOverride");
9818 enforceModifyPermission();
9819
9820 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9821 : Boolean.parseBoolean(enabledStr);
9822 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9823 subId, enabled);
9824 }
9825
9826 /**
9827 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9828 */
9829 @Override
9830 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9831 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9832 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9833 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009834
9835 /**
9836 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9837 * their mobile plan.
9838 */
9839 @Override
9840 public String getMobileProvisioningUrl() {
9841 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9842 final long identity = Binder.clearCallingIdentity();
9843 try {
9844 return getDefaultPhone().getMobileProvisioningUrl();
9845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009849
James.cf Linbcdf8b32021-01-14 16:44:13 +08009850 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009851 * Get the EAB contact from the EAB database.
9852 */
9853 @Override
9854 public String getContactFromEab(String contact) {
9855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9856 enforceModifyPermission();
9857 final long identity = Binder.clearCallingIdentity();
9858 try {
9859 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
9864
9865 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009866 * Remove the EAB contacts from the EAB database.
9867 */
9868 @Override
9869 public int removeContactFromEab(int subId, String contacts) {
9870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9871 enforceModifyPermission();
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009880 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009881 public boolean getDeviceUceEnabled() {
9882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9883 final long identity = Binder.clearCallingIdentity();
9884 try {
9885 return mApp.getDeviceUceEnabled();
9886 } finally {
9887 Binder.restoreCallingIdentity(identity);
9888 }
9889 }
9890
9891 @Override
9892 public void setDeviceUceEnabled(boolean isEnabled) {
9893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 mApp.setDeviceUceEnabled(isEnabled);
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
9901
9902 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009903 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9904 String callingPackage) {
9905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9906 mApp, subId, "setSignalStrengthUpdateRequest");
9907
9908 final int callingUid = Binder.getCallingUid();
9909 // Verify that tha callingPackage belongs to the calling UID
9910 mApp.getSystemService(AppOpsManager.class)
9911 .checkPackage(callingUid, callingPackage);
9912
9913 validateSignalStrengthUpdateRequest(request, callingUid);
9914
9915 final long identity = Binder.clearCallingIdentity();
9916 try {
9917 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9918 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9919
9920 if (result instanceof IllegalStateException) {
9921 throw (IllegalStateException) result;
9922 }
9923 } finally {
9924 Binder.restoreCallingIdentity(identity);
9925 }
9926 }
9927
9928 @Override
9929 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9930 String callingPackage) {
9931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9932 mApp, subId, "clearSignalStrengthUpdateRequest");
9933
9934 final int callingUid = Binder.getCallingUid();
9935 // Verify that tha callingPackage belongs to the calling UID
9936 mApp.getSystemService(AppOpsManager.class)
9937 .checkPackage(callingUid, callingPackage);
9938
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9942 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9943
9944 if (result instanceof IllegalStateException) {
9945 throw (IllegalStateException) result;
9946 }
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
9949 }
9950 }
9951
9952 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9953 int callingUid) {
9954 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9955 // phone/system process do not have further restriction on request
9956 return;
9957 }
9958
9959 // Applications has restrictions on how to use the request:
9960 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9961 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9962 // This is not system caller which has been checked above
9963 throw new IllegalArgumentException(
9964 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9965 }
9966
9967 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9968 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9969 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9970 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9971 || info.isEnabled()) {
9972 throw new IllegalArgumentException(
9973 "Only system can set hide fields in SignalThresholdInfo");
9974 }
9975
9976 // Thresholds length for each RAN need in range. This has been validated in
9977 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9978 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9979 final int[] thresholds = info.getThresholds();
9980 Objects.requireNonNull(thresholds);
9981 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9982 || thresholds.length
9983 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9984 throw new IllegalArgumentException(
9985 "thresholds length is out of range: " + thresholds.length);
9986 }
9987 }
9988 }
Michele Berionned9fbae52020-11-13 02:36:59 +00009989
9990 /**
9991 * Prepare TelephonyManager for an unattended reboot. The reboot is
9992 * required to be done shortly after the API is invoked.
9993 */
9994 @Override
9995 @TelephonyManager.PrepareUnattendedRebootResult
9996 public int prepareForUnattendedReboot() {
9997 enforceRebootPermission();
9998
9999 final long identity = Binder.clearCallingIdentity();
10000 try {
10001 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
10004 }
10005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010006}