blob: 76d239c3b1e0ac0c0d80a4fad3596c9251ece74e [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
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshinfa314642021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjs0a502c42021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
Chen Xu9040b472021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjs0a502c42021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
joonhunshin2c3e4232021-11-28 07:32:01 +0000126import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700127import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700129import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700133import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800135import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wanga7436882022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wange162e302021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshinfa314642021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800197import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -0800230import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800231import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800233import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100234import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700236import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800240import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800241import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243/**
244 * Implementation of the ITelephony interface.
245 */
Santos Cordon117fee72014-05-16 17:56:12 -0700246public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 private static final String LOG_TAG = "PhoneInterfaceManager";
248 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
249 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252 // Message codes used with mMainThreadHandler
253 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700254 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
255 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700256 private static final int CMD_OPEN_CHANNEL = 9;
257 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
258 private static final int CMD_CLOSE_CHANNEL = 11;
259 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800260 private static final int CMD_NV_READ_ITEM = 13;
261 private static final int EVENT_NV_READ_ITEM_DONE = 14;
262 private static final int CMD_NV_WRITE_ITEM = 15;
263 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
264 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
265 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_RESET_MODEM_CONFIG = 19;
267 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800268 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
269 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800270 private static final int CMD_SEND_ENVELOPE = 25;
271 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000272 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
273 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700274 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
275 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
276 private static final int CMD_EXCHANGE_SIM_IO = 31;
277 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800278 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
279 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700280 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
281 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700282 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
283 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700284 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
285 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
286 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
287 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700288 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
289 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
290 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
291 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700292 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800293 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
294 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000295 private static final int CMD_SWITCH_SLOTS = 50;
296 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700297 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
298 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
299 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
300 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
301 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
302 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
303 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
304 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700305 private static final int CMD_GET_ALL_CELL_INFO = 60;
306 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
307 private static final int CMD_GET_CELL_LOCATION = 62;
308 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700309 private static final int CMD_MODEM_REBOOT = 64;
310 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700311 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
312 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800313 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
314 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700315 private static final int CMD_GET_MODEM_STATUS = 70;
316 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700317 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
318 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700319 private static final int CMD_ERASE_MODEM_CONFIG = 74;
320 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800321 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
322 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
323 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
324 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800325 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
326 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800327 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800328 private static final int CMD_GET_CALL_FORWARDING = 83;
329 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
330 private static final int CMD_SET_CALL_FORWARDING = 85;
331 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
332 private static final int CMD_GET_CALL_WAITING = 87;
333 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
334 private static final int CMD_SET_CALL_WAITING = 89;
335 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700336 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
337 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
338 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
339 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700340 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
341 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800342 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
343 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800344 private static final int CMD_SET_DATA_THROTTLING = 99;
345 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800346 private static final int CMD_SET_SIM_POWER = 101;
347 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800348 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
349 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
350 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
351 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800352 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
353 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000354 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800355 private static final int CMD_GET_SLICING_CONFIG = 110;
356 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800357 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700358 private static final int CMD_ENABLE_VONR = 113;
359 private static final int EVENT_ENABLE_VONR_DONE = 114;
360 private static final int CMD_IS_VONR_ENABLED = 115;
361 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800363 // Parameters of select command.
364 private static final int SELECT_COMMAND = 0xA4;
365 private static final int SELECT_P1 = 0x04;
366 private static final int SELECT_P2 = 0;
367 private static final int SELECT_P3 = 0x10;
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 /** The singleton instance. */
370 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800371 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800375 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700376 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700378 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800380 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700382 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800383 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 /** User Activity */
386 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
388
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700389 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
390
Derek Tan97ebb422014-09-05 16:55:38 -0700391 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
392 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800393 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800394 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700395
Michelecea4cf22018-12-21 15:00:11 -0800396 // String to store multi SIM allowed
397 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
398
Derek Tan740e1672017-06-27 14:56:27 -0700399 // The AID of ISD-R.
400 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
401
yinxub1bed742017-04-17 11:45:04 -0700402 private NetworkScanRequestTracker mNetworkScanRequestTracker;
403
David Kelly5e06a7f2018-03-12 14:10:59 +0000404 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
405 private static final int MANUFACTURER_CODE_LENGTH = 8;
406
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800408 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409
Derek Tan89e89d42014-07-08 17:00:10 -0700410 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700411 * Experiment flag to enable erase modem config on reset network, default value is false
412 */
413 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
414 "reset_network_erase_modem_config_enabled";
415
Rambo Wang0f050d82021-02-12 11:43:36 -0800416 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu9040b472021-12-14 17:15:47 -0800417
sandeepjs0a502c42021-09-27 15:34:44 +0000418 /**
419 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
420 * one ICCID active at the same time.
421 * Apps should use below API signatures if targeting SDK is T and beyond.
422 *
423 * @hide
424 */
425 @ChangeId
426 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
427 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800428
Naina Nallurid63128d2019-09-17 14:10:30 -0700429 /**
Chen Xu9040b472021-12-14 17:15:47 -0800430 * Apps targeting on Android T and beyond will get exception whenever icc close channel
431 * operation fails.
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
436
437 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 * A request object to use for transmitting data to an ICC.
439 */
440 private static final class IccAPDUArgument {
441 public int channel, cla, command, p1, p2, p3;
442 public String data;
443
444 public IccAPDUArgument(int channel, int cla, int command,
445 int p1, int p2, int p3, String data) {
446 this.channel = channel;
447 this.cla = cla;
448 this.command = command;
449 this.p1 = p1;
450 this.p2 = p2;
451 this.p3 = p3;
452 this.data = data;
453 }
454 }
455
456 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class ManualNetworkSelectionArgument {
460 public OperatorInfo operatorInfo;
461 public boolean persistSelection;
462
463 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
464 this.operatorInfo = operatorInfo;
465 this.persistSelection = persistSelection;
466 }
467 }
468
469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
471 * request after sending. The main thread will notify the request when it is complete.
472 */
473 private static final class MainThreadRequest {
474 /** The argument to use for the request */
475 public Object argument;
476 /** The result of the request that is run on the main thread */
477 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800478 // The subscriber id that this request applies to. Defaults to
479 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
480 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Nathan Harold92bed182018-10-12 18:16:49 -0700482 // In cases where subId is unavailable, the caller needs to specify the phone.
483 public Phone phone;
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 public WorkSource workSource;
486
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 public MainThreadRequest(Object argument) {
488 this.argument = argument;
489 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490
Nathan Harold92bed182018-10-12 18:16:49 -0700491 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
492 this.argument = argument;
493 if (phone != null) {
494 this.phone = phone;
495 }
496 this.workSource = workSource;
497 }
498
vagdeviaf9a5b92018-08-15 16:01:53 -0700499 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800500 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 if (subId != null) {
502 this.subId = subId;
503 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800508 private static final class IncomingThirdPartyCallArgs {
509 public final ComponentName component;
510 public final String callId;
511 public final String callerDisplayName;
512
513 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
514 String callerDisplayName) {
515 this.component = component;
516 this.callId = callId;
517 this.callerDisplayName = callerDisplayName;
518 }
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * A handler that processes messages on the main thread in the phone process. Since many
523 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
524 * inbound binder threads to the main thread in the phone process. The Binder thread
525 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
526 * on, which will be notified when the operation completes and will contain the result of the
527 * request.
528 *
529 * <p>If a MainThreadRequest object is provided in the msg.obj field,
530 * note that request.result must be set to something non-null for the calling thread to
531 * unblock.
532 */
533 private final class MainThreadHandler extends Handler {
534 @Override
535 public void handleMessage(Message msg) {
536 MainThreadRequest request;
537 Message onCompleted;
538 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000539 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800541 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
543 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 case CMD_HANDLE_USSD_REQUEST: {
545 request = (MainThreadRequest) msg.obj;
546 final Phone phone = getPhoneFromRequest(request);
547 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
548 String ussdRequest = ussdObject.first;
549 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 if (!isUssdApiAllowed(request.subId)) {
552 // Carrier does not support use of this API, return failure.
553 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
554 UssdResponse response = new UssdResponse(ussdRequest, null);
555 Bundle returnData = new Bundle();
556 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
557 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700558
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 request.result = true;
560 notifyRequester(request);
561 return;
562 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700563
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 try {
565 request.result = phone != null
566 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
567 } catch (CallStateException cse) {
568 request.result = false;
569 }
570 // Wake up the requesting thread
571 notifyRequester(request);
572 break;
pkanwar32d516d2016-10-14 19:37:38 -0700573 }
574
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 final Phone phone = getPhoneFromRequest(request);
578 request.result = phone != null ?
579 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
580 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000589 uiccPort = getUiccPortFromRequest(request);
590 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 loge("iccTransmitApduLogicalChannel: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
596 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
611 if (ar.result == null) {
612 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800613 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800615 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
617 loge("iccTransmitApduLogicalChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 loge("iccTransmitApduBasicChannel: No UICC");
629 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
633 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
665 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
682 request.result = new IccIoResult(0x6f, 0, (byte[])null);
683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000696 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 request.result = new IccIoResult(0x6F, 0, (byte[])null);
707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wange162e302021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wange162e302021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 if (ar.result == null) {
754 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 if (ar.exception != null) {
757 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
758 }
759
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700760 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700761 if (ar.exception instanceof CommandException) {
762 CommandException.Error error =
763 ((CommandException) (ar.exception)).getCommandError();
764 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700765 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700766 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700767 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700768 }
769 }
770 openChannelResp = new IccOpenLogicalChannelResponse(
771 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700773 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 break;
776
777 case CMD_CLOSE_CHANNEL:
778 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000779 uiccPort = getUiccPortFromRequest(request);
780 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 loge("iccCloseLogicalChannel: No UICC");
Chen Xu9040b472021-12-14 17:15:47 -0800782 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 } else {
784 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000785 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 break;
788
789 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu9040b472021-12-14 17:15:47 -0800790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 if (ar.exception == null) {
793 request.result = true;
794 } else {
795 request.result = false;
796 if (ar.exception instanceof CommandException) {
797 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
798 CommandException.Error error =
799 ((CommandException) (ar.exception)).getCommandError();
800 // before this feature is enabled, this API should only return false if
801 // the operation fails instead of throwing runtime exception for
802 // backward-compatibility.
803 if (Compatibility.isChangeEnabled(
804 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
805 && error == CommandException.Error.INVALID_ARGUMENTS) {
806 throw new IllegalArgumentException(
807 "iccCloseLogicalChannel: invalid argument ");
808 }
809 } else {
810 loge("iccCloseLogicalChannel: Unknown exception");
811 }
812 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
813 throw new IllegalStateException(
814 "exception from modem to close iccLogical Channel");
815 }
816 }
817 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800818 break;
819
820 case CMD_NV_READ_ITEM:
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800823 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
824 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800825 break;
826
827 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800830 if (ar.exception == null && ar.result != null) {
831 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800833 request.result = "";
834 if (ar.result == null) {
835 loge("nvReadItem: Empty response");
836 } else if (ar.exception instanceof CommandException) {
837 loge("nvReadItem: CommandException: " +
838 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800840 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 }
842 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700843 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 break;
845
Jake Hambye994d462014-02-03 13:10:13 -0800846 case CMD_NV_WRITE_ITEM:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
849 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800850 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700851 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800852 break;
853
854 case EVENT_NV_WRITE_ITEM_DONE:
855 handleNullReturnEvent(msg, "nvWriteItem");
856 break;
857
858 case CMD_NV_WRITE_CDMA_PRL:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800861 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800862 break;
863
864 case EVENT_NV_WRITE_CDMA_PRL_DONE:
865 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
866 break;
867
chen xu6dac5ab2018-10-26 17:39:23 -0700868 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800869 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700870 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800871 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800872 break;
873
chen xu6dac5ab2018-10-26 17:39:23 -0700874 case EVENT_RESET_MODEM_CONFIG_DONE:
875 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800876 break;
877
Sooraj Sasindran37444802020-08-11 10:40:43 -0700878 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
881 request);
882 Phone phone = getPhoneFromRequest(request);
883 if (phone != null) {
884 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
885 } else {
886 loge("isNRDualConnectivityEnabled: No phone object");
887 request.result = false;
888 notifyRequester(request);
889 }
890 break;
891 }
892
893 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
899 // request.result must be set to something non-null
900 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700901 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700902 request.result = ar.result;
903 } else {
904 request.result = false;
905 }
906 if (ar.result == null) {
907 loge("isNRDualConnectivityEnabled: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("isNRDualConnectivityEnabled: CommandException: "
910 + ar.exception);
911 } else {
912 loge("isNRDualConnectivityEnabled: Unknown exception");
913 }
914 }
915 notifyRequester(request);
916 break;
917
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700918 case CMD_IS_VONR_ENABLED: {
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
921 request);
922 Phone phone = getPhoneFromRequest(request);
923 if (phone != null) {
924 phone.isVoNrEnabled(onCompleted, request.workSource);
925 } else {
926 loge("isVoNrEnabled: No phone object");
927 request.result = false;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_IS_VONR_ENABLED_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null && ar.result != null) {
937 request.result = ar.result;
938 } else {
939 // request.result must be set to something non-null
940 // for the calling thread to unblock
941 if (ar.result != null) {
942 request.result = ar.result;
943 } else {
944 request.result = false;
945 }
946 if (ar.result == null) {
947 loge("isVoNrEnabled: Empty response");
948 } else if (ar.exception instanceof CommandException) {
949 loge("isVoNrEnabled: CommandException: "
950 + ar.exception);
951 } else {
952 loge("isVoNrEnabled: Unknown exception");
953 }
954 }
955 notifyRequester(request);
956 break;
957
Sooraj Sasindran37444802020-08-11 10:40:43 -0700958 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
961 Phone phone = getPhoneFromRequest(request);
962 if (phone != null) {
963 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
964 request.workSource);
965 } else {
966 loge("enableNrDualConnectivity: No phone object");
967 request.result =
968 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
969 notifyRequester(request);
970 }
971 break;
972 }
973
974 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 if (ar.exception == null) {
978 request.result =
979 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
980 } else {
981 request.result =
982 TelephonyManager
983 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
984 if (ar.exception instanceof CommandException) {
985 CommandException.Error error =
986 ((CommandException) (ar.exception)).getCommandError();
987 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
988 request.result =
989 TelephonyManager
990 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000991 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
992 request.result =
993 TelephonyManager
994 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700995 }
996 loge("enableNrDualConnectivity" + ": CommandException: "
997 + ar.exception);
998 } else {
999 loge("enableNrDualConnectivity" + ": Unknown exception");
1000 }
1001 }
1002 notifyRequester(request);
1003 break;
1004 }
1005
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07001006 case CMD_ENABLE_VONR: {
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1009 Phone phone = getPhoneFromRequest(request);
1010 if (phone != null) {
1011 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1012 request.workSource);
1013 } else {
1014 loge("setVoNrEnabled: No phone object");
1015 request.result =
1016 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1017 notifyRequester(request);
1018 }
1019 break;
1020 }
1021
1022 case EVENT_ENABLE_VONR_DONE: {
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
1025 if (ar.exception == null) {
1026 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1027 } else {
1028 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1029 if (ar.exception instanceof CommandException) {
1030 CommandException.Error error =
1031 ((CommandException) (ar.exception)).getCommandError();
1032 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1033 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1034 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1035 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1036 } else {
1037 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1038 }
1039 loge("setVoNrEnabled" + ": CommandException: "
1040 + ar.exception);
1041 } else {
1042 loge("setVoNrEnabled" + ": Unknown exception");
1043 }
1044 }
1045 notifyRequester(request);
1046 break;
1047 }
1048
SongFerngWang3ef3e072020-12-21 16:41:52 +08001049 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001050 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001051 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1052 request);
1053 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001054 break;
1055
SongFerngWang3ef3e072020-12-21 16:41:52 +08001056 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 if (ar.exception == null && ar.result != null) {
1060 request.result = ar.result; // Integer
1061 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301062 // request.result must be set to something non-null
1063 // for the calling thread to unblock
1064 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001067 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001068 loge("getAllowedNetworkTypesBitmask: CommandException: "
1069 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 }
1073 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001074 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001075 break;
1076
SongFerngWang3ef3e072020-12-21 16:41:52 +08001077 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001078 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001079 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1080 request);
1081 Pair<Integer, Long> reasonWithNetworkTypes =
1082 (Pair<Integer, Long>) request.argument;
1083 getPhoneFromRequest(request).setAllowedNetworkTypes(
1084 reasonWithNetworkTypes.first,
1085 reasonWithNetworkTypes.second,
1086 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 break;
1088
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1090 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 break;
1092
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001093 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1094 request = (MainThreadRequest)msg.obj;
1095 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001096 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001097 break;
1098
1099 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1100 ar = (AsyncResult)msg.obj;
1101 request = (MainThreadRequest)ar.userObj;
1102 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001103 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001104 break;
1105
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001106 case CMD_SET_VOICEMAIL_NUMBER:
1107 request = (MainThreadRequest) msg.obj;
1108 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1109 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001110 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1111 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001112 break;
1113
1114 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1115 handleNullReturnEvent(msg, "setVoicemailNumber");
1116 break;
1117
Stuart Scott54788802015-03-30 13:18:01 -07001118 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1121 request);
1122 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1123 break;
1124
1125 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1126 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1127 break;
1128
Shishir Agrawal302c8692015-06-19 13:49:39 -07001129 case CMD_PERFORM_NETWORK_SCAN:
1130 request = (MainThreadRequest) msg.obj;
1131 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1132 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1133 break;
1134
Hall Liu27d24262020-09-18 19:04:59 -07001135 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001136 request = (MainThreadRequest) msg.obj;
1137 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001138 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1139 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1140 request.argument;
1141 int callForwardingReason = args.first;
1142 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001143 break;
Hall Liu27d24262020-09-18 19:04:59 -07001144 }
1145 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001148 TelephonyManager.CallForwardingInfoCallback callback =
1149 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1150 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001152 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001153 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1154 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1155 // Service Class is a bit mask per 3gpp 27.007. Search for
1156 // any service for voice call.
1157 if ((callForwardInfo.serviceClass
1158 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001159 callForwardingInfo = new CallForwardingInfo(
1160 callForwardInfo.status
1161 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001162 callForwardInfo.reason,
1163 callForwardInfo.number,
1164 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001165 break;
1166 }
1167 }
1168 // Didn't find a call forward info for voice call.
1169 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001170 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1171 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 }
Hall Liu27d24262020-09-18 19:04:59 -07001173 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001174 } else {
1175 if (ar.result == null) {
1176 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1177 }
1178 if (ar.exception != null) {
1179 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1180 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001181 int errorCode = TelephonyManager
1182 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001183 if (ar.exception instanceof CommandException) {
1184 CommandException.Error error =
1185 ((CommandException) (ar.exception)).getCommandError();
1186 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001187 errorCode = TelephonyManager
1188 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001189 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 errorCode = TelephonyManager
1191 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001192 }
1193 }
Hall Liu27d24262020-09-18 19:04:59 -07001194 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001195 }
Shuo Qian4a594052020-01-23 11:59:30 -08001196 break;
Hall Liu27d24262020-09-18 19:04:59 -07001197 }
Shuo Qian4a594052020-01-23 11:59:30 -08001198
Hall Liu27d24262020-09-18 19:04:59 -07001199 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001202 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001204 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1205 request.argument).first;
1206 request.phone.setCallForwardingOption(
1207 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001208 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001209 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001210 callForwardingInfoToSet.getReason(),
1211 callForwardingInfoToSet.getNumber(),
1212 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1213 break;
Hall Liu27d24262020-09-18 19:04:59 -07001214 }
Shuo Qian4a594052020-01-23 11:59:30 -08001215
Hall Liu27d24262020-09-18 19:04:59 -07001216 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001219 Consumer<Integer> callback =
1220 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1221 request.argument).second;
1222 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001223 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001224 int errorCode = TelephonyManager.CallForwardingInfoCallback
1225 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001226 if (ar.exception instanceof CommandException) {
1227 CommandException.Error error =
1228 ((CommandException) (ar.exception)).getCommandError();
1229 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001230 errorCode = TelephonyManager.CallForwardingInfoCallback
1231 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001232 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001233 errorCode = TelephonyManager.CallForwardingInfoCallback
1234 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001235 }
1236 }
1237 callback.accept(errorCode);
1238 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001240 }
Shuo Qian4a594052020-01-23 11:59:30 -08001241 break;
Hall Liu27d24262020-09-18 19:04:59 -07001242 }
Shuo Qian4a594052020-01-23 11:59:30 -08001243
Hall Liu27d24262020-09-18 19:04:59 -07001244 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001245 request = (MainThreadRequest) msg.obj;
1246 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1247 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 ar = (AsyncResult) msg.obj;
1253 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001254 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1256 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001257 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001258 // Service Class is a bit mask per 3gpp 27.007.
1259 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001260 if (callForwardResults.length > 1
1261 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001262 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001263 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001264 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1265 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001267 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 }
1269 } else {
1270 if (ar.result == null) {
1271 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1272 }
1273 if (ar.exception != null) {
1274 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1275 }
1276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1280 callForwardingStatus =
1281 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1282 }
1283 }
1284 }
Hall Liu27d24262020-09-18 19:04:59 -07001285 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 request = (MainThreadRequest) msg.obj;
1291 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001292 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1293 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001294 break;
Hall Liu27d24262020-09-18 19:04:59 -07001295 }
Shuo Qian4a594052020-01-23 11:59:30 -08001296
Hall Liu27d24262020-09-18 19:04:59 -07001297 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001300 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1301 Consumer<Integer> callback =
1302 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1303 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001304 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001305 if (ar.exception instanceof CommandException) {
1306 CommandException.Error error =
1307 ((CommandException) (ar.exception)).getCommandError();
1308 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1309 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1310 } else {
1311 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1312 }
1313 } else {
1314 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1315 }
1316 } else {
1317 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1318 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001319 }
Shuo Qian4a594052020-01-23 11:59:30 -08001320 break;
Hall Liu27d24262020-09-18 19:04:59 -07001321 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001322 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 CellNetworkScanResult cellScanResult;
1326 if (ar.exception == null && ar.result != null) {
1327 cellScanResult = new CellNetworkScanResult(
1328 CellNetworkScanResult.STATUS_SUCCESS,
1329 (List<OperatorInfo>) ar.result);
1330 } else {
1331 if (ar.result == null) {
1332 loge("getCellNetworkScanResults: Empty response");
1333 }
1334 if (ar.exception != null) {
1335 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1336 }
1337 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1338 if (ar.exception instanceof CommandException) {
1339 CommandException.Error error =
1340 ((CommandException) (ar.exception)).getCommandError();
1341 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1342 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1343 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1344 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1345 }
1346 }
1347 cellScanResult = new CellNetworkScanResult(errorCode, null);
1348 }
1349 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001351 break;
1352
1353 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1354 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001355 ManualNetworkSelectionArgument selArg =
1356 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001357 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1358 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001359 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1360 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001361 break;
1362
1363 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 if (ar.exception == null) {
1367 request.result = true;
1368 } else {
1369 request.result = false;
1370 loge("setNetworkSelectionModeManual " + ar.exception);
1371 }
1372 notifyRequester(request);
1373 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001374 break;
1375
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 case CMD_GET_MODEM_ACTIVITY_INFO:
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001379 if (defaultPhone != null) {
1380 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001381 } else {
1382 ResultReceiver result = (ResultReceiver) request.argument;
1383 Bundle bundle = new Bundle();
1384 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001385 new ModemActivityInfo(0, 0, 0,
1386 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001387 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 break;
1390
Hall Liud0f208c2020-10-14 16:54:44 -07001391 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001394 ResultReceiver result = (ResultReceiver) request.argument;
1395
Hall Liud0f208c2020-10-14 16:54:44 -07001396 ModemActivityInfo ret = null;
1397 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001399 // Update the last modem activity info and the result of the request.
1400 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1401 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001402 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 int[] txTimeMs = info.getTransmitTimeMillis();
1404 int[] lastModemTxTimeMs = mLastModemActivityInfo
1405 .getTransmitTimeMillis();
1406 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1407 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1408 }
Hall Liu49656c02020-10-09 19:00:11 -07001409 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1411 + mLastModemActivityInfo.getSleepTimeMillis());
1412 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1413 + mLastModemActivityInfo.getIdleTimeMillis());
1414 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1415 mLastModemActivityInfo.setReceiveTimeMillis(
1416 info.getReceiveTimeMillis()
1417 + mLastModemActivityInfo.getReceiveTimeMillis());
1418 }
Hall Liu49656c02020-10-09 19:00:11 -07001419 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001420 mLastModemActivityInfo.getSleepTimeMillis(),
1421 mLastModemActivityInfo.getIdleTimeMillis(),
1422 mLastModemActivityInfo.getTransmitTimeMillis(),
1423 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001424 } else {
1425 if (ar.result == null) {
1426 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001427 error = TelephonyManager.ModemActivityInfoException
1428 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001429 } else if (ar.exception instanceof CommandException) {
1430 loge("queryModemActivityInfo: CommandException: " +
1431 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001432 error = TelephonyManager.ModemActivityInfoException
1433 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 } else {
1435 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001436 error = TelephonyManager.ModemActivityInfoException
1437 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001438 }
1439 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001440 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001441 if (ret != null) {
1442 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1443 } else {
1444 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1445 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001446 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001447 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001449 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450
Meng Wang1a7c35a2016-05-05 20:56:15 -07001451 case CMD_SET_ALLOWED_CARRIERS:
1452 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001453 CarrierRestrictionRules argument =
1454 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001455 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001456 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001457 break;
1458
1459 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null && ar.result != null) {
1463 request.result = ar.result;
1464 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001465 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1466 if (ar.exception instanceof CommandException) {
1467 loge("setAllowedCarriers: CommandException: " + ar.exception);
1468 CommandException.Error error =
1469 ((CommandException) (ar.exception)).getCommandError();
1470 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1471 request.result =
1472 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1473 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001474 } else {
1475 loge("setAllowedCarriers: Unknown exception");
1476 }
1477 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001479 break;
1480
1481 case CMD_GET_ALLOWED_CARRIERS:
1482 request = (MainThreadRequest) msg.obj;
1483 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001484 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001485 break;
1486
1487 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
1490 if (ar.exception == null && ar.result != null) {
1491 request.result = ar.result;
1492 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001493 request.result = new IllegalStateException(
1494 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001495 if (ar.result == null) {
1496 loge("getAllowedCarriers: Empty response");
1497 } else if (ar.exception instanceof CommandException) {
1498 loge("getAllowedCarriers: CommandException: " +
1499 ar.exception);
1500 } else {
1501 loge("getAllowedCarriers: Unknown exception");
1502 }
1503 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001505 break;
1506
Nathan Haroldb3014052017-01-25 15:57:32 -08001507 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null && ar.result != null) {
1511 request.result = ar.result;
1512 } else {
1513 request.result = new IllegalArgumentException(
1514 "Failed to retrieve Forbidden Plmns");
1515 if (ar.result == null) {
1516 loge("getForbiddenPlmns: Empty response");
1517 } else {
1518 loge("getForbiddenPlmns: Unknown exception");
1519 }
1520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001522 break;
1523
1524 case CMD_GET_FORBIDDEN_PLMNS:
1525 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001526 uiccPort = getUiccPortFromRequest(request);
1527 if (uiccPort == null) {
1528 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001529 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001530 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001531 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001532 break;
1533 }
1534 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001535 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001536 if (uiccApp == null) {
1537 loge("getForbiddenPlmns() no app with specified type -- "
1538 + appType);
1539 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001541 break;
1542 } else {
1543 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1544 + " specified type -- " + appType);
1545 }
1546 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1547 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1548 onCompleted);
1549 break;
1550
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001551 case CMD_SWITCH_SLOTS:
1552 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001553 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001554 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001555 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001556 break;
1557
1558 case EVENT_SWITCH_SLOTS_DONE:
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
1563 break;
1564 case CMD_GET_NETWORK_SELECTION_MODE:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1567 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1568 break;
1569
1570 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 if (ar.exception != null) {
1574 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1575 } else {
1576 int mode = ((int[]) ar.result)[0];
1577 if (mode == 0) {
1578 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1579 } else {
1580 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1581 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001583 notifyRequester(request);
1584 break;
1585 case CMD_GET_CDMA_ROAMING_MODE:
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1588 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1589 break;
1590 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 if (ar.exception != null) {
1594 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1595 } else {
1596 request.result = ((int[]) ar.result)[0];
1597 }
1598 notifyRequester(request);
1599 break;
1600 case CMD_SET_CDMA_ROAMING_MODE:
1601 request = (MainThreadRequest) msg.obj;
1602 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1603 int mode = (int) request.argument;
1604 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1605 break;
1606 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
1609 request.result = ar.exception == null;
1610 notifyRequester(request);
1611 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001612 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1615 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1616 break;
1617 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception != null) {
1621 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1622 } else {
1623 request.result = ((int[]) ar.result)[0];
1624 }
1625 notifyRequester(request);
1626 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001627 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1628 request = (MainThreadRequest) msg.obj;
1629 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1630 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001631 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1632 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001633 break;
1634 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1635 ar = (AsyncResult) msg.obj;
1636 request = (MainThreadRequest) ar.userObj;
1637 request.result = ar.exception == null;
1638 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001639 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001640 case CMD_GET_ALL_CELL_INFO:
1641 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001643 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001644 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001645 case EVENT_GET_ALL_CELL_INFO_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001648 // If a timeout occurs, the response will be null
1649 request.result = (ar.exception == null && ar.result != null)
1650 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 synchronized (request) {
1652 request.notifyAll();
1653 }
1654 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001655 case CMD_REQUEST_CELL_INFO_UPDATE:
1656 request = (MainThreadRequest) msg.obj;
1657 request.phone.requestCellInfoUpdate(request.workSource,
1658 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1659 break;
1660 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1664 try {
1665 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001666 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001667 cb.onError(
1668 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1669 ar.exception.getClass().getName(),
1670 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001671 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001672 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001673 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001674 } else {
1675 // use the result as returned
1676 cb.onCellInfo((List<CellInfo>) ar.result);
1677 }
1678 } catch (RemoteException re) {
1679 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1680 }
1681 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001682 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001683 request = (MainThreadRequest) msg.obj;
1684 WorkSource ws = (WorkSource) request.argument;
1685 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001686 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001687 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001688 }
1689 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
1692 if (ar.exception == null) {
1693 request.result = ar.result;
1694 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001695 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001697 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001698 }
1699
1700 synchronized (request) {
1701 request.notifyAll();
1702 }
1703 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001704 }
chen xu6dac5ab2018-10-26 17:39:23 -07001705 case CMD_MODEM_REBOOT:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001708 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001709 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001710 case EVENT_CMD_MODEM_REBOOT_DONE:
1711 handleNullReturnEvent(msg, "rebootModem");
1712 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001713 case CMD_REQUEST_ENABLE_MODEM:
1714 request = (MainThreadRequest) msg.obj;
1715 boolean enable = (boolean) request.argument;
1716 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001717 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001718 PhoneConfigurationManager.getInstance()
1719 .enablePhone(request.phone, enable, onCompleted);
1720 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001721 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001722 ar = (AsyncResult) msg.obj;
1723 request = (MainThreadRequest) ar.userObj;
1724 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001725 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001726 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001727 if ((boolean) request.result) {
1728 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1729 updateModemStateMetrics();
1730 } else {
1731 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1732 + ar.exception);
1733 }
1734 notifyRequester(request);
1735 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001736 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001737 case CMD_GET_MODEM_STATUS:
1738 request = (MainThreadRequest) msg.obj;
1739 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1740 PhoneConfigurationManager.getInstance()
1741 .getPhoneStatusFromModem(request.phone, onCompleted);
1742 break;
1743 case EVENT_GET_MODEM_STATUS_DONE:
1744 ar = (AsyncResult) msg.obj;
1745 request = (MainThreadRequest) ar.userObj;
1746 int id = request.phone.getPhoneId();
1747 if (ar.exception == null && ar.result != null) {
1748 request.result = ar.result;
1749 //update the cache as modem status has changed
1750 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1751 (boolean) request.result);
1752 } else {
1753 // Return true if modem status cannot be retrieved. For most cases,
1754 // modem status is on. And for older version modems, GET_MODEM_STATUS
1755 // and disable modem are not supported. Modem is always on.
1756 // TODO: this should be fixed in R to support a third
1757 // status UNKNOWN b/131631629
1758 request.result = true;
1759 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1760 + ar.exception);
1761 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001762 notifyRequester(request);
1763 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001764 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1765 request = (MainThreadRequest) msg.obj;
1766 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1767 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1768 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1769 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1770 break;
1771 }
1772 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
1775 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1776 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1777 args.second.accept(ar.exception == null);
1778 notifyRequester(request);
1779 break;
1780 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001781 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1784 Phone phone = getPhoneFromRequest(request);
1785 if (phone != null) {
1786 phone.getSystemSelectionChannels(onCompleted);
1787 } else {
1788 loge("getSystemSelectionChannels: No phone object");
1789 request.result = new ArrayList<RadioAccessSpecifier>();
1790 notifyRequester(request);
1791 }
1792 break;
1793 }
1794 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1795 ar = (AsyncResult) msg.obj;
1796 request = (MainThreadRequest) ar.userObj;
1797 if (ar.exception == null && ar.result != null) {
1798 request.result = ar.result;
1799 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001800 request.result = new IllegalStateException(
1801 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 if (ar.result == null) {
1803 loge("getSystemSelectionChannels: Empty response");
1804 } else {
1805 loge("getSystemSelectionChannels: Unknown exception");
1806 }
1807 }
1808 notifyRequester(request);
1809 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001810 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1811 ar = (AsyncResult) msg.obj;
1812 request = (MainThreadRequest) ar.userObj;
1813 if (ar.exception == null && ar.result != null) {
1814 request.result = ar.result;
1815 } else {
1816 request.result = -1;
1817 loge("Failed to set Forbidden Plmns");
1818 if (ar.result == null) {
1819 loge("setForbidenPlmns: Empty response");
1820 } else if (ar.exception != null) {
1821 loge("setForbiddenPlmns: Exception: " + ar.exception);
1822 request.result = -1;
1823 } else {
1824 loge("setForbiddenPlmns: Unknown exception");
1825 }
1826 }
1827 notifyRequester(request);
1828 break;
1829 case CMD_SET_FORBIDDEN_PLMNS:
1830 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001831 uiccPort = getUiccPortFromRequest(request);
1832 if (uiccPort == null) {
1833 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001834 request.result = -1;
1835 notifyRequester(request);
1836 break;
1837 }
1838 Pair<Integer, List<String>> setFplmnsArgs =
1839 (Pair<Integer, List<String>>) request.argument;
1840 appType = setFplmnsArgs.first;
1841 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001842 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001843 if (uiccApp == null) {
1844 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1845 request.result = -1;
1846 loge("Failed to get UICC App");
1847 notifyRequester(request);
1848 } else {
1849 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1850 ((SIMRecords) uiccApp.getIccRecords())
1851 .setForbiddenPlmns(onCompleted, fplmns);
1852 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001853 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001854 case CMD_ERASE_MODEM_CONFIG:
1855 request = (MainThreadRequest) msg.obj;
1856 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1857 defaultPhone.eraseModemConfig(onCompleted);
1858 break;
1859 case EVENT_ERASE_MODEM_CONFIG_DONE:
1860 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001861 break;
zoey chene02881a2019-12-30 16:11:23 +08001862
Kai Shif70f46f2021-03-03 13:59:46 -08001863 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1864 request = (MainThreadRequest) msg.obj;
1865 request.result = defaultPhone.eraseDataInSharedPreferences();
1866 notifyRequester(request);
1867 break;
1868
zoey chene02881a2019-12-30 16:11:23 +08001869 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1870 request = (MainThreadRequest) msg.obj;
1871 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1872 Pair<String, String> changed = (Pair<String, String>) request.argument;
1873 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1874 changed.first, changed.second, onCompleted);
1875 break;
1876 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1877 ar = (AsyncResult) msg.obj;
1878 request = (MainThreadRequest) ar.userObj;
1879 if (ar.exception == null) {
1880 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001881 // If the operation is successful, update the PIN storage
1882 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1883 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001884 UiccController.getInstance().getPinStorage()
1885 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001886 } else {
1887 request.result = msg.arg1;
1888 }
1889 notifyRequester(request);
1890 break;
1891
Michele Berionne5e411512020-11-13 02:36:59 +00001892 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1895 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1896 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1897 enabled.first, enabled.second, onCompleted);
1898 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001899 }
zoey chene02881a2019-12-30 16:11:23 +08001900 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1901 ar = (AsyncResult) msg.obj;
1902 request = (MainThreadRequest) ar.userObj;
1903 if (ar.exception == null) {
1904 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001905 // If the operation is successful, update the PIN storage
1906 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1907 int phoneId = getPhoneFromRequest(request).getPhoneId();
1908 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001909 UiccController.getInstance().getPinStorage()
1910 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001911 } else {
1912 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1913 }
zoey chene02881a2019-12-30 16:11:23 +08001914 } else {
1915 request.result = msg.arg1;
1916 }
Michele Berionne5e411512020-11-13 02:36:59 +00001917
1918
zoey chene02881a2019-12-30 16:11:23 +08001919 notifyRequester(request);
1920 break;
1921
Peter Wangdafb9ac2020-01-15 14:13:38 -08001922 case MSG_NOTIFY_USER_ACTIVITY:
1923 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001924 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001925 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1926 getDefaultPhone().getContext().sendBroadcastAsUser(
1927 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1928 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001929
1930 case CMD_SET_DATA_THROTTLING: {
1931 request = (MainThreadRequest) msg.obj;
1932 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1933 DataThrottlingRequest dataThrottlingRequest =
1934 (DataThrottlingRequest) request.argument;
1935 Phone phone = getPhoneFromRequest(request);
1936 if (phone != null) {
1937 phone.setDataThrottling(onCompleted,
1938 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1939 dataThrottlingRequest.getCompletionDurationMillis());
1940 } else {
1941 loge("setDataThrottling: No phone object");
1942 request.result =
1943 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1944 notifyRequester(request);
1945 }
1946
1947 break;
1948 }
1949 case EVENT_SET_DATA_THROTTLING_DONE:
1950 ar = (AsyncResult) msg.obj;
1951 request = (MainThreadRequest) ar.userObj;
1952
1953 if (ar.exception == null) {
1954 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1955 } else if (ar.exception instanceof CommandException) {
1956 loge("setDataThrottling: CommandException: " + ar.exception);
1957 CommandException.Error error =
1958 ((CommandException) (ar.exception)).getCommandError();
1959
1960 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1961 request.result = TelephonyManager
1962 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1963 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1964 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001965 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1966 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001967 } else {
1968 request.result =
1969 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1970 }
1971 } else {
1972 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1973 }
1974 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1975 notifyRequester(request);
1976 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001977
1978 case CMD_SET_SIM_POWER: {
1979 request = (MainThreadRequest) msg.obj;
1980 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1981 request = (MainThreadRequest) msg.obj;
1982 int stateToSet =
1983 ((Pair<Integer, IIntegerConsumer>)
1984 request.argument).first;
1985 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1986 break;
1987 }
1988 case EVENT_SET_SIM_POWER_DONE: {
1989 ar = (AsyncResult) msg.obj;
1990 request = (MainThreadRequest) ar.userObj;
1991 IIntegerConsumer callback =
1992 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1993 if (ar.exception != null) {
1994 loge("setSimPower exception: " + ar.exception);
1995 int errorCode = TelephonyManager.CallForwardingInfoCallback
1996 .RESULT_ERROR_UNKNOWN;
1997 if (ar.exception instanceof CommandException) {
1998 CommandException.Error error =
1999 ((CommandException) (ar.exception)).getCommandError();
2000 if (error == CommandException.Error.SIM_ERR) {
2001 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2002 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2003 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2004 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2005 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2006 } else {
2007 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2008 }
2009 }
2010 try {
2011 callback.accept(errorCode);
2012 } catch (RemoteException e) {
2013 // Ignore if the remote process is no longer available to call back.
2014 Log.w(LOG_TAG, "setSimPower: callback not available.");
2015 }
2016 } else {
2017 try {
2018 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2019 } catch (RemoteException e) {
2020 // Ignore if the remote process is no longer available to call back.
2021 Log.w(LOG_TAG, "setSimPower: callback not available.");
2022 }
2023 }
2024 break;
2025 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002026 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2027 request = (MainThreadRequest) msg.obj;
2028
2029 final Phone phone = getPhoneFromRequest(request);
2030 if (phone == null || phone.getServiceStateTracker() == null) {
2031 request.result = new IllegalStateException("Phone or SST is null");
2032 notifyRequester(request);
2033 break;
2034 }
2035
2036 Pair<Integer, SignalStrengthUpdateRequest> pair =
2037 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2038 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2039 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002040 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002041 request.subId, pair.first /*callingUid*/,
2042 pair.second /*request*/, onCompleted);
2043 break;
2044 }
2045 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2046 ar = (AsyncResult) msg.obj;
2047 request = (MainThreadRequest) ar.userObj;
2048 // request.result will be the exception of ar if present, true otherwise.
2049 // Be cautious not to leave result null which will wait() forever
2050 request.result = ar.exception != null ? ar.exception : true;
2051 notifyRequester(request);
2052 break;
2053 }
2054 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2055 request = (MainThreadRequest) msg.obj;
2056
2057 Phone phone = getPhoneFromRequest(request);
2058 if (phone == null || phone.getServiceStateTracker() == null) {
2059 request.result = new IllegalStateException("Phone or SST is null");
2060 notifyRequester(request);
2061 break;
2062 }
2063
2064 Pair<Integer, SignalStrengthUpdateRequest> pair =
2065 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2066 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2067 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002068 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002069 request.subId, pair.first /*callingUid*/,
2070 pair.second /*request*/, onCompleted);
2071 break;
2072 }
2073 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2074 ar = (AsyncResult) msg.obj;
2075 request = (MainThreadRequest) ar.userObj;
2076 request.result = ar.exception != null ? ar.exception : true;
2077 notifyRequester(request);
2078 break;
2079 }
Jordan Liu109698e2020-11-24 14:50:34 -08002080
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002081 case CMD_GET_SLICING_CONFIG: {
2082 request = (MainThreadRequest) msg.obj;
2083 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2084 request.phone.getSlicingConfig(onCompleted);
2085 break;
2086 }
2087 case EVENT_GET_SLICING_CONFIG_DONE: {
2088 ar = (AsyncResult) msg.obj;
2089 request = (MainThreadRequest) ar.userObj;
2090 ResultReceiver result = (ResultReceiver) request.argument;
2091
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002092 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002093 Bundle bundle = new Bundle();
2094 int resultCode = 0;
2095 if (ar.exception != null) {
2096 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2097 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002098 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002099 } else if (ar.result == null) {
2100 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002101 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002102 } else {
2103 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002104 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2105 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 }
2107
2108 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002109 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002110 }
2111 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2112 result.send(resultCode, bundle);
2113 notifyRequester(request);
2114 break;
2115 }
2116
Michele Berionne5e411512020-11-13 02:36:59 +00002117 case CMD_PREPARE_UNATTENDED_REBOOT:
2118 request = (MainThreadRequest) msg.obj;
2119 request.result =
2120 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2121 notifyRequester(request);
2122 break;
2123
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 default:
2125 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2126 break;
2127 }
2128 }
Jake Hambye994d462014-02-03 13:10:13 -08002129
Pengquan Menga1bb6272018-09-06 09:59:22 -07002130 private void notifyRequester(MainThreadRequest request) {
2131 synchronized (request) {
2132 request.notifyAll();
2133 }
2134 }
2135
Jake Hambye994d462014-02-03 13:10:13 -08002136 private void handleNullReturnEvent(Message msg, String command) {
2137 AsyncResult ar = (AsyncResult) msg.obj;
2138 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2139 if (ar.exception == null) {
2140 request.result = true;
2141 } else {
2142 request.result = false;
2143 if (ar.exception instanceof CommandException) {
2144 loge(command + ": CommandException: " + ar.exception);
2145 } else {
2146 loge(command + ": Unknown exception");
2147 }
2148 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002149 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 }
2152
2153 /**
2154 * Posts the specified command to be executed on the main thread,
2155 * waits for the request to complete, and returns the result.
2156 * @see #sendRequestAsync
2157 */
2158 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002159 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2160 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002161 }
2162
2163 /**
2164 * Posts the specified command to be executed on the main thread,
2165 * waits for the request to complete, and returns the result.
2166 * @see #sendRequestAsync
2167 */
2168 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2169 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002170 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002171 }
2172
2173 /**
2174 * Posts the specified command to be executed on the main thread,
2175 * waits for the request to complete, and returns the result.
2176 * @see #sendRequestAsync
2177 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002178 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2180 }
2181
2182 /**
2183 * Posts the specified command to be executed on the main thread,
2184 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2185 * if not timeout or null otherwise.
2186 * @see #sendRequestAsync
2187 */
2188 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2189 long timeoutInMs) {
2190 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002191 }
2192
2193 /**
2194 * Posts the specified command to be executed on the main thread,
2195 * waits for the request to complete, and returns the result.
2196 * @see #sendRequestAsync
2197 */
Nathan Harold92bed182018-10-12 18:16:49 -07002198 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002200 }
2201
2202 /**
2203 * Posts the specified command to be executed on the main thread,
2204 * waits for the request to complete, and returns the result.
2205 * @see #sendRequestAsync
2206 */
2207 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002208 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2209 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002210 }
2211
2212 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002213 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2214 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2215 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002216 * @see #sendRequestAsync
2217 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002218 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2219 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2221 throw new RuntimeException("This method will deadlock if called from the main thread.");
2222 }
2223
Nathan Harold92bed182018-10-12 18:16:49 -07002224 MainThreadRequest request = null;
2225 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2226 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2227 } else if (phone != null) {
2228 request = new MainThreadRequest(argument, phone, workSource);
2229 } else {
2230 request = new MainThreadRequest(argument, subId, workSource);
2231 }
2232
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 Message msg = mMainThreadHandler.obtainMessage(command, request);
2234 msg.sendToTarget();
2235
Rambo Wang0f050d82021-02-12 11:43:36 -08002236
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002238 if (timeoutInMs >= 0) {
2239 // Wait for at least timeoutInMs before returning null request result
2240 long now = SystemClock.elapsedRealtime();
2241 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002242 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002243 try {
2244 request.wait(deadline - now);
2245 } catch (InterruptedException e) {
2246 // Do nothing, go back and check if request is completed or timeout
2247 } finally {
2248 now = SystemClock.elapsedRealtime();
2249 }
2250 }
2251 } else {
2252 // Wait for the request to complete
2253 while (request.result == null) {
2254 try {
2255 request.wait();
2256 } catch (InterruptedException e) {
2257 // Do nothing, go back and wait until the request is complete
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260 }
2261 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002262 if (request.result == null) {
2263 Log.wtf(LOG_TAG,
2264 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 return request.result;
2267 }
2268
2269 /**
2270 * Asynchronous ("fire and forget") version of sendRequest():
2271 * Posts the specified command to be executed on the main thread, and
2272 * returns immediately.
2273 * @see #sendRequest
2274 */
2275 private void sendRequestAsync(int command) {
2276 mMainThreadHandler.sendEmptyMessage(command);
2277 }
2278
2279 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002280 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002281 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002282 */
2283 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002284 sendRequestAsync(command, argument, null, null);
2285 }
2286
2287 /**
2288 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2289 * @see {@link #sendRequest(int,Object)}
2290 */
2291 private void sendRequestAsync(
2292 int command, Object argument, Phone phone, WorkSource workSource) {
2293 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002294 Message msg = mMainThreadHandler.obtainMessage(command, request);
2295 msg.sendToTarget();
2296 }
2297
2298 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 * Initialize the singleton PhoneInterfaceManager instance.
2300 * This is only done once, at startup, from PhoneApp.onCreate().
2301 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002302 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 synchronized (PhoneInterfaceManager.class) {
2304 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002305 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 } else {
2307 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2308 }
2309 return sInstance;
2310 }
2311 }
2312
2313 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002314 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002317 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002318 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002320 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002322 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002323 mTelephonySharedPreferences =
2324 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002325 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002326 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002327 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002328 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 publish();
2331 }
2332
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002333 private Phone getDefaultPhone() {
2334 Phone thePhone = getPhone(getDefaultSubscription());
2335 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2336 }
2337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 private void publish() {
2339 if (DBG) log("publish: " + this);
2340
Peter Wangc035ce42020-01-08 21:00:22 -08002341 TelephonyFrameworkInitializer
2342 .getTelephonyServiceManager()
2343 .getTelephonyServiceRegisterer()
2344 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346
Stuart Scott584921c2015-01-15 17:10:34 -08002347 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002348 if (request.phone != null) {
2349 return request.phone;
2350 } else {
2351 return getPhoneFromSubId(request.subId);
2352 }
2353 }
2354
2355 private Phone getPhoneFromSubId(int subId) {
2356 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2357 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002358 }
2359
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002360 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002361 Phone phone = getPhoneFromRequest(request);
2362 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002363 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002364 }
2365
Wink Saville36469e72014-06-11 15:17:00 -07002366 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002368 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370
Kai Shif70f46f2021-03-03 13:59:46 -08002371 private void sendEraseModemConfig(@NonNull Phone phone) {
2372 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2373 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2374 }
2375
2376 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2377 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2378 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002379 }
2380
Peter Wang44b186e2020-01-13 23:33:09 -08002381 private boolean isImsAvailableOnDevice() {
2382 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2383 if (pm == null) {
2384 // For some reason package manger is not available.. This will fail internally anyway,
2385 // so do not throw error and allow.
2386 return true;
2387 }
2388 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2389 }
2390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002392 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
Wink Savilleb564aae2014-10-23 10:18:09 -07002395 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 if (DBG) log("dial: " + number);
2397 // No permission check needed here: This is just a wrapper around the
2398 // ACTION_DIAL intent, which is available to any app since it puts up
2399 // the UI before it does anything.
2400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 String url = createTelUrl(number);
2404 if (url == null) {
2405 return;
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 // PENDING: should we just silently fail if phone is offhook or ringing?
2409 PhoneConstants.State state = mCM.getState(subId);
2410 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2411 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2412 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2413 mApp.startActivity(intent);
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418 }
2419
2420 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002421 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002422 }
2423
Wink Savilleb564aae2014-10-23 10:18:09 -07002424 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 if (DBG) log("call: " + number);
2426
2427 // This is just a wrapper around the ACTION_CALL intent, but we still
2428 // need to do a permission check since we're calling startActivity()
2429 // from the context of the phone app.
2430 enforceCallPermission();
2431
Jordan Liu1617b712019-07-10 15:06:26 -07002432 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 != AppOpsManager.MODE_ALLOWED) {
2434 return;
2435 }
2436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 String url = createTelUrl(number);
2440 if (url == null) {
2441 return;
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 boolean isValid = false;
2445 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2446 if (slist != null) {
2447 for (SubscriptionInfo subInfoRecord : slist) {
2448 if (subInfoRecord.getSubscriptionId() == subId) {
2449 isValid = true;
2450 break;
2451 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002452 }
Wink Saville08874612014-08-31 19:19:58 -07002453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454 if (!isValid) {
2455 return;
2456 }
Wink Saville08874612014-08-31 19:19:58 -07002457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2459 intent.putExtra(SUBSCRIPTION_KEY, subId);
2460 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2461 mApp.startActivity(intent);
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
2464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
Wink Savilleb564aae2014-10-23 10:18:09 -07002467 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002468 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002469 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2470 }
2471
Wink Savilleb564aae2014-10-23 10:18:09 -07002472 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002473 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002474 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2475 }
2476
Wink Savilleb564aae2014-10-23 10:18:09 -07002477 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002482 Phone phone = getPhone(subId);
2483 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 checkSimPin.start();
2485 return checkSimPin.unlockSim(null, pin);
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
2488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002496 Phone phone = getPhone(subId);
2497 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 checkSimPuk.start();
2499 return checkSimPuk.unlockSim(puk, pin);
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
2502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 }
2504
2505 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002506 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 * a synchronous one.
2508 */
2509 private static class UnlockSim extends Thread {
2510
2511 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002512 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513
2514 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002515 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2516 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517
2518 // For replies from SimCard interface
2519 private Handler mHandler;
2520
2521 // For async handler to identify request type
2522 private static final int SUPPLY_PIN_COMPLETE = 100;
2523
Michele Berionne5e411512020-11-13 02:36:59 +00002524 UnlockSim(int phoneId, IccCard simCard) {
2525 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 mSimCard = simCard;
2527 }
2528
2529 @Override
2530 public void run() {
2531 Looper.prepare();
2532 synchronized (UnlockSim.this) {
2533 mHandler = new Handler() {
2534 @Override
2535 public void handleMessage(Message msg) {
2536 AsyncResult ar = (AsyncResult) msg.obj;
2537 switch (msg.what) {
2538 case SUPPLY_PIN_COMPLETE:
2539 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2540 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002541 mRetryCount = msg.arg1;
2542 if (ar.exception != null) {
2543 if (ar.exception instanceof CommandException &&
2544 ((CommandException)(ar.exception)).getCommandError()
2545 == CommandException.Error.PASSWORD_INCORRECT) {
2546 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002547 } //When UiccCardApp dispose,handle message and return exception
2548 else if (ar.exception instanceof CommandException &&
2549 ((CommandException) (ar.exception)).getCommandError()
2550 == CommandException.Error.ABORTED) {
2551 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002552 } else {
2553 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2554 }
2555 } else {
2556 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 mDone = true;
2559 UnlockSim.this.notifyAll();
2560 }
2561 break;
2562 }
2563 }
2564 };
2565 UnlockSim.this.notifyAll();
2566 }
2567 Looper.loop();
2568 }
2569
2570 /*
2571 * Use PIN or PUK to unlock SIM card
2572 *
2573 * If PUK is null, unlock SIM card with PIN
2574 *
2575 * If PUK is not null, unlock SIM card with PUK and set PIN code
2576 */
Wink Saville9de0f752013-10-22 19:04:03 -07002577 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578
2579 while (mHandler == null) {
2580 try {
2581 wait();
2582 } catch (InterruptedException e) {
2583 Thread.currentThread().interrupt();
2584 }
2585 }
2586 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2587
2588 if (puk == null) {
2589 mSimCard.supplyPin(pin, callback);
2590 } else {
2591 mSimCard.supplyPuk(puk, pin, callback);
2592 }
2593
2594 while (!mDone) {
2595 try {
2596 Log.d(LOG_TAG, "wait for done");
2597 wait();
2598 } catch (InterruptedException e) {
2599 // Restore the interrupted status
2600 Thread.currentThread().interrupt();
2601 }
2602 }
2603 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002604 int[] resultArray = new int[2];
2605 resultArray[0] = mResult;
2606 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002607
2608 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002609 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002610 }
2611
Wink Saville9de0f752013-10-22 19:04:03 -07002612 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 }
2614 }
2615
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002616 /**
2617 * This method has been removed due to privacy and stability concerns.
2618 */
2619 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002621 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2622 return;
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Nathan Harold1f889d82020-06-04 17:05:26 -07002625 @Override
2626 public void updateServiceLocationWithPackageName(String callingPackage) {
2627 mApp.getSystemService(AppOpsManager.class)
2628 .checkPackage(Binder.getCallingUid(), callingPackage);
2629
Nathan Haroldf096d982020-11-18 17:18:06 -08002630 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002631 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2632 // Callers targeting S have no business invoking this method.
2633 return;
2634 }
2635
2636 LocationAccessPolicy.LocationPermissionResult locationResult =
2637 LocationAccessPolicy.checkLocationPermission(mApp,
2638 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2639 .setCallingPackage(callingPackage)
2640 .setCallingFeatureId(null)
2641 .setCallingPid(Binder.getCallingPid())
2642 .setCallingUid(Binder.getCallingUid())
2643 .setMethod("updateServiceLocation")
2644 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2645 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2646 .build());
2647 // Apps that lack location permission have no business calling this method;
2648 // however, because no permission was declared in the public API, denials must
2649 // all be "soft".
2650 switch (locationResult) {
2651 case DENIED_HARD: /* fall through */
2652 case DENIED_SOFT:
2653 return;
2654 }
2655
2656 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002659 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002661 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002668 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002669 @Override
2670 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002671 return isRadioOnWithFeature(callingPackage, null);
2672 }
2673
2674
2675 @Override
2676 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2677 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2678 callingFeatureId);
2679 }
2680
2681 @Deprecated
2682 @Override
2683 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2684 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002685 }
2686
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002687 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002688 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2689 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002691 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002692 return false;
2693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 return isRadioOnForSubscriber(subId);
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002701 }
2702
2703 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = getPhone(subId);
2707 if (phone != null) {
2708 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2709 } else {
2710 return false;
2711 }
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
2717 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002718 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 }
Wink Saville36469e72014-06-11 15:17:00 -07002720
Wink Savilleb564aae2014-10-23 10:18:09 -07002721 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 final Phone phone = getPhone(subId);
2727 if (phone != null) {
2728 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 }
Wink Saville36469e72014-06-11 15:17:00 -07002733 }
2734
2735 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002736 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002737 }
2738
Wink Savilleb564aae2014-10-23 10:18:09 -07002739 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 final Phone phone = getPhone(subId);
2745 if (phone == null) {
2746 return false;
2747 }
2748 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2749 toggleRadioOnOffForSubscriber(subId);
2750 }
2751 return true;
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
Wink Saville36469e72014-06-11 15:17:00 -07002756
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002757 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002758 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002759 /*
2760 * If any of the Radios are available, it will need to be
2761 * shutdown. So return true if any Radio is available.
2762 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2766 Phone phone = PhoneFactory.getPhone(i);
2767 if (phone != null && phone.isRadioAvailable()) return true;
2768 }
2769 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2770 return false;
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002773 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002774 }
2775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002777 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 enforceModifyPermission();
2779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2783 logv("Shutting down Phone " + i);
2784 shutdownRadioUsingPhoneId(i);
2785 }
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002788 }
2789 }
2790
2791 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002792 Phone phone = PhoneFactory.getPhone(phoneId);
2793 if (phone != null && phone.isRadioAvailable()) {
2794 phone.shutdownRadio();
2795 }
2796 }
2797
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2804 if (defaultPhone != null) {
2805 defaultPhone.setRadioPower(turnOn);
2806 return true;
2807 } else {
2808 loge("There's no default phone.");
2809 return false;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002813 }
Wink Saville36469e72014-06-11 15:17:00 -07002814 }
2815
Wink Savilleb564aae2014-10-23 10:18:09 -07002816 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
2823 phone.setRadioPower(turnOn);
2824 return true;
2825 } else {
2826 return false;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
Wink Saville36469e72014-06-11 15:17:00 -07002833 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 public boolean enableDataConnectivity() {
2836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 int subId = mSubscriptionController.getDefaultDataSubId();
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002843 if (phone.isUsingNewDataStack()) {
2844 phone.getDataSettingsManager().setDataEnabled(
2845 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2846 } else {
2847 phone.getDataEnabledSettings().setDataEnabled(
2848 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 return true;
2851 } else {
2852 return false;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
Wink Saville36469e72014-06-11 15:17:00 -07002859 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 public boolean disableDataConnectivity() {
2862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 int subId = mSubscriptionController.getDefaultDataSubId();
2867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002869 if (phone.isUsingNewDataStack()) {
2870 phone.getDataSettingsManager().setDataEnabled(
2871 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2872 } else {
2873 phone.getDataEnabledSettings().setDataEnabled(
2874 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 return true;
2877 } else {
2878 return false;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Sanket Padawe356d7632015-06-22 14:03:32 -07002885 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002886 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 final Phone phone = getPhone(subId);
2890 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002891 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } else {
2893 return false;
2894 }
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 }
2899
2900 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002901 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002902 }
2903
pkanwarae03a6b2016-11-06 20:37:09 -08002904 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 enforceCallPermission();
2906
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2910 return;
2911 }
2912 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2913 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
pkanwar32d516d2016-10-14 19:37:38 -07002917 };
2918
Wink Savilleb564aae2014-10-23 10:18:09 -07002919 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2925 return false;
2926 }
2927 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002933 /**
2934 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2935 * tag on getCallState Binder call.
2936 */
2937 @Deprecated
2938 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002940 if (CompatChanges.isChangeEnabled(
2941 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2942 Binder.getCallingUid())) {
2943 // Do not allow this API to be called on API version 31+, it should only be
2944 // called on old apps using this Binder call directly.
2945 throw new SecurityException("This method can only be used for applications "
2946 + "targeting API version 30 or less.");
2947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 final long identity = Binder.clearCallingIdentity();
2949 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002950 Phone phone = getPhone(getDefaultSubscription());
2951 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2952 PhoneConstantConversions.convertCallState(phone.getState());
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
2959 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2960 if (CompatChanges.isChangeEnabled(
2961 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2962 Binder.getCallingUid())) {
2963 // Check READ_PHONE_STATE for API version 31+
2964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2965 featureId, "getCallStateForSubscription")) {
2966 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2967 + "targeting API level 31+.");
2968 }
2969 }
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2974 PhoneConstantConversions.convertCallState(phone.getState());
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002978 }
2979
Sanket Padawe356d7632015-06-22 14:03:32 -07002980 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002981 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002982 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2983 }
2984
2985 @Override
2986 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 final long identity = Binder.clearCallingIdentity();
2988 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002989 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002991 if (phone.isUsingNewDataStack()) {
2992 return phone.getDataNetworkController().getInternetDataNetworkState();
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2995 } else {
2996 return PhoneConstantConversions.convertDataState(
2997 PhoneConstants.DataState.DISCONNECTED);
2998 }
2999 } finally {
3000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003002 }
3003
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003005 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003006 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3007 }
3008
3009 @Override
3010 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 final long identity = Binder.clearCallingIdentity();
3012 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 if (phone != null) {
3015 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3016 } else {
3017 return TelephonyManager.DATA_ACTIVITY_NONE;
3018 }
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003022 }
3023
3024 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003025 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003026 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003027 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003028
3029 LocationAccessPolicy.LocationPermissionResult locationResult =
3030 LocationAccessPolicy.checkLocationPermission(mApp,
3031 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3032 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003033 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003034 .setCallingPid(Binder.getCallingPid())
3035 .setCallingUid(Binder.getCallingUid())
3036 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003037 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003038 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3039 .build());
3040 switch (locationResult) {
3041 case DENIED_HARD:
3042 throw new SecurityException("Not allowed to access cell location");
3043 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003044 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3045 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
3047
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003048 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003052 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003053 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
Svetoslav64fad262015-04-14 14:35:21 -07003057 }
3058
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003060 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003061 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3062 // registered cell info, so return a NULL country instead.
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003065 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3066 // Get default phone in this case.
3067 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3068 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003069 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003071 if (phone == null) return "";
3072 ServiceStateTracker sst = phone.getServiceStateTracker();
3073 if (sst == null) return "";
3074 LocaleTracker lt = sst.getLocaleTracker();
3075 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003076 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003080 }
3081
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003082 /**
3083 * This method was removed due to potential issues caused by performing partial
3084 * updates of service state, and lack of a credible use case.
3085 *
3086 * This has the ability to break the telephony implementation by disabling notification of
3087 * changes in device connectivity. DO NOT USE THIS!
3088 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003089 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 public void enableLocationUpdates() {
3091 mApp.enforceCallingOrSelfPermission(
3092 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 }
3094
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003095 /**
3096 * This method was removed due to potential issues caused by performing partial
3097 * updates of service state, and lack of a credible use case.
3098 *
3099 * This has the ability to break the telephony implementation by disabling notification of
3100 * changes in device connectivity. DO NOT USE THIS!
3101 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 @Override
3103 public void disableLocationUpdates() {
3104 mApp.enforceCallingOrSelfPermission(
3105 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106 }
3107
3108 @Override
3109 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003110 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3111 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003112 try {
3113 mApp.getSystemService(AppOpsManager.class)
3114 .checkPackage(Binder.getCallingUid(), callingPackage);
3115 } catch (SecurityException e) {
3116 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3117 throw e;
3118 }
3119
Nathan Haroldf096d982020-11-18 17:18:06 -08003120 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003121 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3122 throw new SecurityException(
3123 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3124 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003125
Jordan Liu1617b712019-07-10 15:06:26 -07003126 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3128 return null;
3129 }
Svetoslav64fad262015-04-14 14:35:21 -07003130
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003131 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003133 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003134 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135
Nathan Haroldf180aac2018-06-01 18:43:55 -07003136 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3137 for (CellInfo ci : info) {
3138 if (ci instanceof CellInfoGsm) {
3139 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3140 } else if (ci instanceof CellInfoWcdma) {
3141 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003144 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003147 private List<CellInfo> getCachedCellInfo() {
3148 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3149 for (Phone phone : PhoneFactory.getPhones()) {
3150 List<CellInfo> info = phone.getAllCellInfo();
3151 if (info != null) cellInfos.addAll(info);
3152 }
3153 return cellInfos;
3154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003155
3156 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003157 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003158 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003159 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003160
3161 LocationAccessPolicy.LocationPermissionResult locationResult =
3162 LocationAccessPolicy.checkLocationPermission(mApp,
3163 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3164 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003166 .setCallingPid(Binder.getCallingPid())
3167 .setCallingUid(Binder.getCallingUid())
3168 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003169 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003170 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3171 .build());
3172 switch (locationResult) {
3173 case DENIED_HARD:
3174 throw new SecurityException("Not allowed to access cell info");
3175 case DENIED_SOFT:
3176 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
Nathan Haroldf096d982020-11-18 17:18:06 -08003179 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003180 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3181 return getCachedCellInfo();
3182 }
3183
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003184 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3189 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003190 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003191 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 if (info != null) cellInfos.addAll(info);
3193 }
3194 return cellInfos;
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198 }
3199
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003200 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003201 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3202 String callingFeatureId) {
3203 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3204 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003205 }
3206
3207 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003208 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3209 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003210 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003211 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003212 }
3213
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003214 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3215 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003216 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003217 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003218
3219 LocationAccessPolicy.LocationPermissionResult locationResult =
3220 LocationAccessPolicy.checkLocationPermission(mApp,
3221 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3222 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003224 .setCallingPid(Binder.getCallingPid())
3225 .setCallingUid(Binder.getCallingUid())
3226 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003227 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3228 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003229 .build());
3230 switch (locationResult) {
3231 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003232 if (TelephonyPermissions
3233 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003234 // Safetynet logging for b/154934934
3235 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3236 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003237 throw new SecurityException("Not allowed to access cell info");
3238 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003239 if (TelephonyPermissions
3240 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003241 // Safetynet logging for b/154934934
3242 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3243 }
Nathan Harold5320c422019-05-09 10:26:08 -07003244 try {
3245 cb.onCellInfo(new ArrayList<CellInfo>());
3246 } catch (RemoteException re) {
3247 // Drop without consequences
3248 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003249 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003250 }
3251
Nathan Harolda939a962019-05-09 10:13:47 -07003252
3253 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003254 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3255
3256 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3257 }
3258
3259 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003261 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003262 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 }
3271
Shishir Agrawala9f32182016-04-12 12:00:16 -07003272 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003273 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 Phone phone = PhoneFactory.getPhone(slotIndex);
3275 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003276 return null;
3277 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003278 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003279 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003280 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003281 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 return null;
3283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 return phone.getImei();
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003291 }
3292
3293 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003294 public String getTypeAllocationCodeForSlot(int slotIndex) {
3295 Phone phone = PhoneFactory.getPhone(slotIndex);
3296 String tac = null;
3297 if (phone != null) {
3298 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003299 try {
3300 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3301 } catch (IndexOutOfBoundsException e) {
3302 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3303 return null;
3304 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003305 }
3306 return tac;
3307 }
3308
3309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003310 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003311 try {
3312 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3313 } catch (SecurityException se) {
3314 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3315 throw new SecurityException("Package " + callingPackage + " does not belong to "
3316 + Binder.getCallingUid());
3317 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003318 Phone phone = PhoneFactory.getPhone(slotIndex);
3319 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003320 return null;
3321 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003322
Jeff Davidson913390f2018-02-23 17:11:49 -08003323 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003324 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003326 return null;
3327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 return phone.getMeid();
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
Jack Yu2af8d712017-03-15 17:14:14 -07003335 }
3336
3337 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003338 public String getManufacturerCodeForSlot(int slotIndex) {
3339 Phone phone = PhoneFactory.getPhone(slotIndex);
3340 String manufacturerCode = null;
3341 if (phone != null) {
3342 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003343 try {
3344 manufacturerCode =
3345 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3346 } catch (IndexOutOfBoundsException e) {
3347 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3348 return null;
3349 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003350 }
3351 return manufacturerCode;
3352 }
3353
3354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003355 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3356 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003357 Phone phone = PhoneFactory.getPhone(slotIndex);
3358 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003359 return null;
3360 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003361 int subId = phone.getSubId();
3362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003363 mApp, subId, callingPackage, callingFeatureId,
3364 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003365 return null;
3366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 return phone.getDeviceSvn();
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003374 }
3375
fionaxu43304da2017-11-27 22:51:16 -08003376 @Override
3377 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 final Phone phone = getPhone(subId);
3381 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
fionaxu43304da2017-11-27 22:51:16 -08003385 }
3386
3387 @Override
3388 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 return phone == null ? null : phone.getCarrierName();
3393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
fionaxu43304da2017-11-27 22:51:16 -08003396 }
3397
calvinpanffe225e2018-11-01 19:43:06 +08003398 @Override
chen xu0026ca62019-03-06 15:28:50 -08003399 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 final Phone phone = getPhone(subId);
3403 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003404 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
3408 }
3409
3410 @Override
chen xu0026ca62019-03-06 15:28:50 -08003411 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003415 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420
chen xu651eec72018-11-11 19:03:44 -08003421 @Override
chen xu864e11c2018-12-06 22:10:03 -08003422 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3423 if (!isSubscriptionMccMnc) {
3424 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3425 }
chen xu651eec72018-11-11 19:03:44 -08003426 final Phone phone = PhoneFactory.getPhone(slotIndex);
3427 if (phone == null) {
3428 return TelephonyManager.UNKNOWN_CARRIER_ID;
3429 }
3430 final long identity = Binder.clearCallingIdentity();
3431 try {
3432 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
3436 }
3437
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 //
3439 // Internal helper methods.
3440 //
3441
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003442 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003443 * Make sure the caller is the calling package itself
3444 *
3445 * @throws SecurityException if the caller is not the calling package
3446 */
3447 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3448 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003449 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3450 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003451 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003452 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003453 } catch (PackageManager.NameNotFoundException e) {
3454 // packageUid is -1
3455 }
3456 if (packageUid != callingUid) {
3457 throw new SecurityException(message + ": Package " + callingPackage
3458 + " does not belong to " + callingUid);
3459 }
3460 }
3461
3462 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3464 *
3465 * @throws SecurityException if the caller does not have the required permission
3466 */
3467 private void enforceModifyPermission() {
3468 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3469 }
3470
Shuo Qian3b6ee772019-11-13 17:43:31 -08003471 private void enforceActiveEmergencySessionPermission() {
3472 mApp.enforceCallingOrSelfPermission(
3473 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3474 }
3475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 /**
3477 * Make sure the caller has the CALL_PHONE permission.
3478 *
3479 * @throws SecurityException if the caller does not have the required permission
3480 */
3481 private void enforceCallPermission() {
3482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3483 }
3484
paulhu5a773602019-08-23 19:17:33 +08003485 private void enforceSettingsPermission() {
3486 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003487 }
3488
Michele Berionne5e411512020-11-13 02:36:59 +00003489 private void enforceRebootPermission() {
3490 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3491 }
3492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493 private String createTelUrl(String number) {
3494 if (TextUtils.isEmpty(number)) {
3495 return null;
3496 }
3497
Jake Hambye994d462014-02-03 13:10:13 -08003498 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 }
3500
Ihab Awadf9e92732013-12-05 18:02:52 -08003501 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003502 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3503 }
3504
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003505 private static void logv(String msg) {
3506 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3507 }
3508
Ihab Awadf9e92732013-12-05 18:02:52 -08003509 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3511 }
3512
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003513 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003515 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003516 }
3517
Sanket Padawe356d7632015-06-22 14:03:32 -07003518 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003519 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 final Phone phone = PhoneFactory.getPhone(slotIndex);
3523 if (phone == null) {
3524 return PhoneConstants.PHONE_TYPE_NONE;
3525 } else {
3526 return phone.getPhoneType();
3527 }
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 }
3532
3533 /**
3534 * Returns the CDMA ERI icon index to display
3535 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003537 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3538 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3539 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003540 }
3541
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3544 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003546 mApp, subId, callingPackage, callingFeatureId,
3547 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 return -1;
3549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 final Phone phone = getPhone(subId);
3554 if (phone != null) {
3555 return phone.getCdmaEriIconIndex();
3556 } else {
3557 return -1;
3558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003562 }
3563
3564 /**
3565 * Returns the CDMA ERI icon mode,
3566 * 0 - ON
3567 * 1 - FLASHING
3568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003570 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3571 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003573 }
3574
Sanket Padawe356d7632015-06-22 14:03:32 -07003575 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003576 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3577 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003579 mApp, subId, callingPackage, callingFeatureId,
3580 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003581 return -1;
3582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583
3584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 final Phone phone = getPhone(subId);
3587 if (phone != null) {
3588 return phone.getCdmaEriIconMode();
3589 } else {
3590 return -1;
3591 }
3592 } finally {
3593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003595 }
3596
3597 /**
3598 * Returns the CDMA ERI text,
3599 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003600 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003601 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3602 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3603 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003604 }
3605
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003607 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3608 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003610 mApp, subId, callingPackage, callingFeatureId,
3611 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003612 return null;
3613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614
3615 final long identity = Binder.clearCallingIdentity();
3616 try {
3617 final Phone phone = getPhone(subId);
3618 if (phone != null) {
3619 return phone.getCdmaEriText();
3620 } else {
3621 return null;
3622 }
3623 } finally {
3624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 }
3627
3628 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003629 * Returns the CDMA MDN.
3630 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003632 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3634 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 return phone.getLine1Number();
3641 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003642 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 return null;
3644 }
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003647 }
3648 }
3649
3650 /**
3651 * Returns the CDMA MIN.
3652 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003653 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003654 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3656 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 final Phone phone = getPhone(subId);
3661 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3662 return phone.getCdmaMin();
3663 } else {
3664 return null;
3665 }
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003668 }
3669 }
3670
Hall Liud892bec2018-11-30 14:51:45 -08003671 @Override
3672 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3673 INumberVerificationCallback callback, String callingPackage) {
3674 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3675 != PERMISSION_GRANTED) {
3676 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3677 }
3678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3679
3680 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3681 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003682 throw new SecurityException("Calling package must be configured in the device config: "
3683 + "calling package: " + callingPackage
3684 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003685 }
3686
3687 if (range == null) {
3688 throw new NullPointerException("Range must be non-null");
3689 }
3690
3691 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003692 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003693
3694 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3695 }
3696
Junda Liuca05d5d2014-08-14 22:36:34 -07003697 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003698 * Returns true if CDMA provisioning needs to run.
3699 */
3700 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 final long identity = Binder.clearCallingIdentity();
3702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003707 }
3708
3709 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003710 * Sets the voice mail number of a given subId.
3711 */
3712 @Override
3713 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003714 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3715 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3720 new Pair<String, String>(alphaTag, number), new Integer(subId));
3721 return success;
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003725 }
3726
Ta-wei Yen87c49842016-05-13 21:19:52 -07003727 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003728 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003730 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3731 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003732 if (!TextUtils.equals(callingPackage, systemDialer)) {
3733 throw new SecurityException("caller must be system dialer");
3734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3739 if (phoneAccountHandle == null) {
3740 return null;
3741 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003745 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003746 }
3747
3748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003749 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3750 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003753 mApp, subId, callingPackage, callingFeatureId,
3754 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003755 return null;
3756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003758 final long identity = Binder.clearCallingIdentity();
3759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003764 }
3765
3766 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003767 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3768 VisualVoicemailSmsFilterSettings settings) {
3769 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003778 }
3779
3780 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003781 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783
3784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003791 }
3792
3793 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003794 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3795 String callingPackage, int subId) {
3796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003801 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003805 }
3806
3807 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003808 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003809 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810
3811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003814 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003818 }
3819
3820 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003821 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3822 String callingAttributionTag, int subId, String number, int port, String text,
3823 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003824 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003825 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003826 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003827 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003828 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3829 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003830 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003831
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003832 /**
fionaxu0152e512016-11-14 13:36:14 -08003833 * Sets the voice activation state of a given subId.
3834 */
3835 @Override
3836 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3838 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839
3840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 final Phone phone = getPhone(subId);
3843 if (phone != null) {
3844 phone.setVoiceActivationState(activationState);
3845 } else {
3846 loge("setVoiceActivationState fails with invalid subId: " + subId);
3847 }
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003850 }
3851 }
3852
3853 /**
3854 * Sets the data activation state of a given subId.
3855 */
3856 @Override
3857 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3859 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860
3861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 phone.setDataActivationState(activationState);
3866 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003867 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003871 }
3872 }
3873
3874 /**
3875 * Returns the voice activation state of a given subId.
3876 */
3877 @Override
3878 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880
fionaxu0152e512016-11-14 13:36:14 -08003881 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 if (phone != null) {
3885 return phone.getVoiceActivationState();
3886 } else {
3887 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3888 }
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003891 }
3892 }
3893
3894 /**
3895 * Returns the data activation state of a given subId.
3896 */
3897 @Override
3898 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900
fionaxu0152e512016-11-14 13:36:14 -08003901 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 if (phone != null) {
3905 return phone.getDataActivationState();
3906 } else {
3907 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3908 }
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003911 }
3912 }
3913
3914 /**
Wink Saville36469e72014-06-11 15:17:00 -07003915 * Returns the unread count of voicemails for a subId
3916 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003918 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3919 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003921 mApp, subId, callingPackage, callingFeatureId,
3922 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003923 return 0;
3924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925 final long identity = Binder.clearCallingIdentity();
3926 try {
3927 final Phone phone = getPhone(subId);
3928 if (phone != null) {
3929 return phone.getVoiceMessageCount();
3930 } else {
3931 return 0;
3932 }
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003936 }
3937
3938 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003939 * returns true, if the device is in a state where both voice and data
3940 * are supported simultaneously. This can change based on location or network condition.
3941 */
3942 @Override
3943 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 final Phone phone = getPhone(subId);
3947 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003951 }
3952
3953 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003954 * Send the dialer code if called from the current default dialer or the caller has
3955 * carrier privilege.
3956 * @param inputCode The dialer code to send
3957 */
3958 @Override
3959 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003961 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003962 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3963 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003964 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003965 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003966 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968
3969 final long identity = Binder.clearCallingIdentity();
3970 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
fionaxu235cc5e2017-03-06 22:25:57 -08003975 }
3976
Pengquan Menga1bb6272018-09-06 09:59:22 -07003977 @Override
3978 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003979 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003980 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003981 mApp, subId, "getNetworkSelectionMode");
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 if (!isActiveSubscription(subId)) {
3985 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3986 }
3987 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3988 } finally {
3989 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003990 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003991 }
3992
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003994 public boolean isInEmergencySmsMode() {
3995 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 for (Phone phone : PhoneFactory.getPhones()) {
3999 if (phone.isInEmergencySmsMode()) {
4000 return true;
4001 }
4002 }
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
4005 }
4006 return false;
4007 }
4008
shilu366312e2019-12-17 09:28:10 -08004009 /**
4010 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4011 * @param subId The subscription to use to check the configuration.
4012 * @param c The callback that will be used to send the result.
4013 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004014 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004015 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4016 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004017 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004018 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004019
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4022 "IMS not available on device.");
4023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 final long token = Binder.clearCallingIdentity();
4025 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004026 int slotId = getSlotIndexOrException(subId);
4027 verifyImsMmTelConfiguredOrThrow(slotId);
4028 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 } catch (ImsException e) {
4030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 } finally {
4032 Binder.restoreCallingIdentity(token);
4033 }
4034 }
4035
shilu366312e2019-12-17 09:28:10 -08004036 /**
4037 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4038 * @param subId The subscription to use to check the configuration.
4039 * @param c The callback that will be used to send the result.
4040 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004042 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004043 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004044 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004045 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4046 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4047 }
Meng Wangafbc5852019-09-19 17:37:13 -07004048 final long token = Binder.clearCallingIdentity();
4049 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004050 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4051 .removeRegistrationCallbackForSubscription(c, subId);
4052 } catch (ImsException e) {
4053 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4054 + "is inactive, ignoring unregister.");
4055 // If the subscription is no longer active, just return, since the callback
4056 // will already have been removed internally.
4057 } finally {
4058 Binder.restoreCallingIdentity(token);
4059 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 }
4061
Brad Ebingera34a6c22019-10-22 17:36:18 -07004062 /**
4063 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4064 */
4065 @Override
4066 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4067 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4068 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4069 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4070 "IMS not available on device.");
4071 }
4072 final long token = Binder.clearCallingIdentity();
4073 try {
4074 Phone phone = getPhone(subId);
4075 if (phone == null) {
4076 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4077 + subId + "'");
4078 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4079 }
4080 phone.getImsRegistrationState(regState -> {
4081 try {
4082 consumer.accept((regState == null)
4083 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4084 } catch (RemoteException e) {
4085 // Ignore if the remote process is no longer available to call back.
4086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4087 }
4088 });
4089 } finally {
4090 Binder.restoreCallingIdentity(token);
4091 }
4092 }
4093
4094 /**
4095 * Get the transport type for the IMS service registration state.
4096 */
4097 @Override
4098 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004099 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004100 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004101 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4102 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4103 "IMS not available on device.");
4104 }
4105 final long token = Binder.clearCallingIdentity();
4106 try {
4107 Phone phone = getPhone(subId);
4108 if (phone == null) {
4109 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4110 + subId + "'");
4111 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4112 }
4113 phone.getImsRegistrationTech(regTech -> {
4114 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4115 int regTechConverted = (regTech == null)
4116 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4117 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4118 regTechConverted);
4119 try {
4120 consumer.accept(regTechConverted);
4121 } catch (RemoteException e) {
4122 // Ignore if the remote process is no longer available to call back.
4123 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4124 }
4125 });
4126 } finally {
4127 Binder.restoreCallingIdentity(token);
4128 }
4129 }
4130
shilu366312e2019-12-17 09:28:10 -08004131 /**
4132 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4133 * @param subId The subscription to use to check the configuration.
4134 * @param c The callback that will be used to send the result.
4135 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004137 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4138 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004139 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004140 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004141 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4142 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4143 "IMS not available on device.");
4144 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 final long token = Binder.clearCallingIdentity();
4146 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004147 int slotId = getSlotIndexOrException(subId);
4148 verifyImsMmTelConfiguredOrThrow(slotId);
4149 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (ImsException e) {
4151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(token);
4154 }
4155 }
4156
shilu366312e2019-12-17 09:28:10 -08004157 /**
4158 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4159 * @param subId The subscription to use to check the configuration.
4160 * @param c The callback that will be used to send the result.
4161 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004163 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004164 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004165 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004166 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4167 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4168 }
Meng Wangafbc5852019-09-19 17:37:13 -07004169
4170 final long token = Binder.clearCallingIdentity();
4171 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004172 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004173 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004174 } catch (ImsException e) {
4175 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4176 + "is inactive, ignoring unregister.");
4177 // If the subscription is no longer active, just return, since the callback
4178 // will already have been removed internally.
4179 } finally {
4180 Binder.restoreCallingIdentity(token);
4181 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 }
4183
4184 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004185 public boolean isCapable(int subId, int capability, int regTech) {
4186 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 final long token = Binder.clearCallingIdentity();
4188 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004189 int slotId = getSlotIndexOrException(subId);
4190 verifyImsMmTelConfiguredOrThrow(slotId);
4191 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004192 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4194 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004195 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004196 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4197 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 } finally {
4199 Binder.restoreCallingIdentity(token);
4200 }
4201 }
4202
4203 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004204 public boolean isAvailable(int subId, int capability, int regTech) {
4205 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 final long token = Binder.clearCallingIdentity();
4207 try {
4208 Phone phone = getPhone(subId);
4209 if (phone == null) return false;
4210 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004211 } catch (com.android.ims.ImsException e) {
4212 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4213 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 } finally {
4215 Binder.restoreCallingIdentity(token);
4216 }
4217 }
4218
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004219 /**
4220 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4221 * subscription.
4222 * @param subId The subscription to use to check the configuration.
4223 * @param callback The callback that will be used to send the result.
4224 * @param capability The MmTelFeature capability that will be used to send the result.
4225 * @param transportType The transport type of the MmTelFeature capability.
4226 */
4227 @Override
4228 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4229 int transportType) {
4230 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4231 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4232 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4233 "IMS not available on device.");
4234 }
4235 final long token = Binder.clearCallingIdentity();
4236 try {
4237 int slotId = getSlotIndex(subId);
4238 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4239 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4240 + subId + "'");
4241 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4242 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004243 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004244 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4245 transportType, aBoolean -> {
4246 try {
4247 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4248 } catch (RemoteException e) {
4249 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4250 + "running. Ignore");
4251 }
4252 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004253 } catch (ImsException e) {
4254 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004255 } finally {
4256 Binder.restoreCallingIdentity(token);
4257 }
4258 }
4259
shilu366312e2019-12-17 09:28:10 -08004260 /**
4261 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4262 * @param subId The subscription to use to check the configuration.
4263 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 @Override
4265 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004266 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004267 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004268
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 final long token = Binder.clearCallingIdentity();
4270 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004271 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004272 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(token);
4278 }
4279 }
4280
4281 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004282 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004284 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 final long identity = Binder.clearCallingIdentity();
4286 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004287 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004288 // This setting doesn't require an active ImsService connection, so do not verify. The
4289 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004290 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004291 } catch (ImsException e) {
4292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
4296 }
4297
shilu366312e2019-12-17 09:28:10 -08004298 /**
4299 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4300 * @param subId The subscription to use to check the configuration.
4301 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004303 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004304 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004305 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 final long identity = Binder.clearCallingIdentity();
4307 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004308 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004309 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004310 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004311 } catch (ImsException e) {
4312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
4318 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004319 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004321 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 final long identity = Binder.clearCallingIdentity();
4323 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004324 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004325 // This setting doesn't require an active ImsService connection, so do not verify. The
4326 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004327 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004328 } catch (ImsException e) {
4329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
4333 }
4334
shilu366312e2019-12-17 09:28:10 -08004335 /**
4336 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4337 * @param subId The subscription to use to check the configuration.
4338 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 @Override
4340 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004341 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004342 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004343 final long identity = Binder.clearCallingIdentity();
4344 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004345 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004346 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004348 } catch (ImsException e) {
4349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004356 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004358 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 final long identity = Binder.clearCallingIdentity();
4360 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004362 // This setting doesn't require an active ImsService connection, so do not verify. The
4363 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004364 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004365 } catch (ImsException e) {
4366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
4370 }
4371
shilu366312e2019-12-17 09:28:10 -08004372 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004373 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4374 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4375 * @param subId The subscription to use to check the configuration.
4376 */
4377 @Override
4378 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004379 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004380 mApp, subId, "isCrossSimCallingEnabledByUser");
4381 final long identity = Binder.clearCallingIdentity();
4382 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004384 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004386 } catch (ImsException e) {
4387 throw new ServiceSpecificException(e.getCode());
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
4391 }
4392
4393 /**
4394 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4395 * Requires MODIFY_PHONE_STATE permission.
4396 * @param subId The subscription to use to check the configuration.
4397 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4398 * false otherwise
4399 */
4400 @Override
4401 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4403 "setCrossSimCallingEnabled");
4404 final long identity = Binder.clearCallingIdentity();
4405 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004406 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004407 // This setting doesn't require an active ImsService connection, so do not verify. The
4408 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004410 } catch (ImsException e) {
4411 throw new ServiceSpecificException(e.getCode());
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
4415 }
4416
4417 /**
shilu366312e2019-12-17 09:28:10 -08004418 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4419 * @param subId The subscription to use to check the configuration.
4420 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004422
Brad Ebinger35c841c2018-10-01 10:40:55 -07004423 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004424 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004425 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004426 final long identity = Binder.clearCallingIdentity();
4427 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004429 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004430 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004431 } catch (ImsException e) {
4432 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
4436 }
4437
4438 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004439 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004441 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 final long identity = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004445 // This setting doesn't require an active ImsService connection, so do not verify. The
4446 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004447 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (ImsException e) {
4449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
4455 @Override
4456 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 "setVoWiFiNonPersistent");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004462 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
shilu366312e2019-12-17 09:28:10 -08004471 /**
4472 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4473 * @param subId The subscription to use to check the configuration.
4474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 @Override
4476 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004478 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
4492 public void setVoWiFiModeSetting(int subId, int mode) {
4493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4494 "setVoWiFiModeSetting");
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
4508 @Override
4509 public int getVoWiFiRoamingModeSetting(int subId) {
4510 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4511 final long identity = Binder.clearCallingIdentity();
4512 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004514 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
4523 @Override
4524 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4526 "setVoWiFiRoamingModeSetting");
4527 final long identity = Binder.clearCallingIdentity();
4528 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004529 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004530 // This setting doesn't require an active ImsService connection, so do not verify. The
4531 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004532 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004533 } catch (ImsException e) {
4534 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
4538 }
4539
4540 @Override
4541 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4543 "setRttCapabilityEnabled");
4544 final long identity = Binder.clearCallingIdentity();
4545 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004546 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004547 // This setting doesn't require an active ImsService connection, so do not verify. The
4548 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004549 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004550 } catch (ImsException e) {
4551 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
4555 }
4556
shilu366312e2019-12-17 09:28:10 -08004557 /**
4558 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4559 * @param subId The subscription to use to check the configuration.
4560 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 @Override
4562 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004563 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004564 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004565 final long identity = Binder.clearCallingIdentity();
4566 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004567 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004568 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004569 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004570 } catch (ImsException e) {
4571 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 } finally {
4573 Binder.restoreCallingIdentity(identity);
4574 }
4575 }
4576
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004577 @Override
4578 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4579 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004580
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004581 final long identity = Binder.clearCallingIdentity();
4582 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004583 if (!isImsAvailableOnDevice()) {
4584 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4585 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004586 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004587 int slotId = getSlotIndexOrException(subId);
4588 verifyImsMmTelConfiguredOrThrow(slotId);
4589 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004590 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004591 } catch (ImsException e) {
4592 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
4596 }
4597
4598 @Override
4599 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4600 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004601
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004602 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004603 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4604 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4605 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004606 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004607 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004608 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004609 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004610 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4611 + "is inactive, ignoring unregister.");
4612 // If the subscription is no longer active, just return, since the callback will already
4613 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
4617 }
4618
joonhunshin2c3e4232021-11-28 07:32:01 +00004619 @Override
4620 public void registerFeatureProvisioningChangedCallback(int subId,
4621 IFeatureProvisioningCallback callback) {
4622 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4623 mApp, subId, "registerFeatureProvisioningChangedCallback");
4624
4625 final long identity = Binder.clearCallingIdentity();
4626 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4627 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4628 }
4629
4630 ImsProvisioningController.getInstance()
4631 .addFeatureProvisioningChangedCallback(subId, callback);
4632
4633 Binder.restoreCallingIdentity(identity);
4634 }
4635
4636 @Override
4637 public void unregisterFeatureProvisioningChangedCallback(int subId,
4638 IFeatureProvisioningCallback callback) {
4639 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4640 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4641
4642 final long identity = Binder.clearCallingIdentity();
4643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4644 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4645 }
4646
4647 ImsProvisioningController.getInstance()
4648 .removeFeatureProvisioningChangedCallback(subId, callback);
4649
4650 Binder.restoreCallingIdentity(identity);
4651 }
allenwtsu99c623b2020-01-03 18:24:23 +08004652
4653 private void checkModifyPhoneStatePermission(int subId, String message) {
4654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4655 message);
4656 }
4657
4658 private boolean isImsProvisioningRequired(int subId, int capability,
4659 boolean isMmtelCapability) {
4660 Phone phone = getPhone(subId);
4661 if (phone == null) {
4662 loge("phone instance null for subid " + subId);
4663 return false;
4664 }
4665 if (isMmtelCapability) {
4666 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4667 return false;
4668 }
4669 } else {
4670 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4671 return false;
4672 }
4673 }
4674 return true;
4675 }
4676
4677 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004678 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004679 boolean isProvisioned) {
4680 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004684 ImsProvisioningController.getInstance()
4685 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4686 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004687 } finally {
4688 Binder.restoreCallingIdentity(identity);
4689 }
allenwtsu99c623b2020-01-03 18:24:23 +08004690 }
4691
4692
4693 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004694 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4695 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4696 mApp, subId, "getRcsProvisioningStatusForCapability");
4697
allenwtsu99c623b2020-01-03 18:24:23 +08004698 final long identity = Binder.clearCallingIdentity();
4699 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004700 return ImsProvisioningController.getInstance()
4701 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
4705 }
4706
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004707 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4709 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004710 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004711
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 final long identity = Binder.clearCallingIdentity();
4713 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004714 ImsProvisioningController.getInstance()
4715 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
4721 @Override
4722 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004723 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4724 mApp, subId, "getProvisioningStatusForCapability");
4725
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004728 return ImsProvisioningController.getInstance()
4729 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
4734 }
4735
4736 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004737 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4738 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4739 mApp, subId, "isProvisioningRequiredForCapability");
4740
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 return ImsProvisioningController.getInstance()
4744 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004747 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004748 }
4749
4750 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004751 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4752 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4753 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754
joonhunshin2c3e4232021-11-28 07:32:01 +00004755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 return ImsProvisioningController.getInstance()
4758 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004762 }
4763
4764 private static String getMmTelProvisioningKey(int subId, int tech) {
4765 // resulting key is provision_ims_mmtel_{subId}_{tech}
4766 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4767 }
4768
4769 /**
4770 * Query CarrierConfig to see if the specified capability requires provisioning for the
4771 * carrier associated with the subscription id.
4772 */
4773 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4774 int capability) {
4775 CarrierConfigManager configManager = new CarrierConfigManager(context);
4776 PersistableBundle c = configManager.getConfigForSubId(subId);
4777 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004778 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004779 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4780 false);
4781 boolean requireVoiceVtProvisioning = c.getBoolean(
4782 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4783
4784 // First check to make sure that the capability requires provisioning.
4785 switch (capability) {
4786 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4787 // intentional fallthrough
4788 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4789 if (requireVoiceVtProvisioning) {
4790 // Voice and Video requires provisioning
4791 return true;
4792 }
4793 break;
4794 }
4795 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4796 if (requireUtProvisioning) {
4797 // UT requires provisioning
4798 return true;
4799 }
4800 break;
4801 }
4802 }
4803 return false;
4804 }
4805
allenwtsu99c623b2020-01-03 18:24:23 +08004806 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4807 int capability) {
4808 CarrierConfigManager configManager = new CarrierConfigManager(context);
4809 PersistableBundle c = configManager.getConfigForSubId(subId);
4810
4811 boolean requireRcsProvisioning = c.getBoolean(
4812 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4813
4814 // First check to make sure that the capability requires provisioning.
4815 switch (capability) {
4816 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4817 // intentional fallthrough
4818 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4819 if (requireRcsProvisioning) {
4820 // OPTION or PRESENCE requires provisioning
4821 return true;
4822 }
4823 break;
4824 }
4825 }
4826 return false;
4827 }
4828
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004829 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004830 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4832 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4833 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004834 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4835 mApp, subId, "getImsProvisioningInt");
4836
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 int slotId = getSlotIndex(subId);
4841 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4842 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4843 + subId + "' for key:" + key);
4844 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4845 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004846
4847 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4848 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4849 return retVal;
4850 }
4851
calvinpanb5a34062021-02-08 19:59:36 +08004852 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004853 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004854 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4855 + subId + "' for key:" + key);
4856 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
4860 }
4861
4862 @Override
4863 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4865 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4866 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004867 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4868 mApp, subId, "getImsProvisioningString");
4869
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 int slotId = getSlotIndex(subId);
4874 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4875 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4876 + subId + "' for key:" + key);
4877 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4878 }
calvinpanb5a34062021-02-08 19:59:36 +08004879 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4882 + subId + "' for key:" + key);
4883 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
4887 }
4888
4889 @Override
4890 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004891 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4892 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4893 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4895 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004896
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004897 final long identity = Binder.clearCallingIdentity();
4898 try {
4899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 int slotId = getSlotIndex(subId);
4901 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4902 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4903 + subId + "' for key:" + key);
4904 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4905 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004906
4907 int retVal = ImsProvisioningController.getInstance()
4908 .setProvisioningValue(subId, key, value);
4909 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4910 return retVal;
4911 }
4912
calvinpanb5a34062021-02-08 19:59:36 +08004913 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4914 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004916 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
4923 @Override
4924 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4926 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4927 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4929 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 int slotId = getSlotIndex(subId);
4934 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4935 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4936 + subId + "' for key:" + key);
4937 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4938 }
calvinpanb5a34062021-02-08 19:59:36 +08004939 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4940 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004942 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 /**
4950 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4951 * for the given slot ID or no ImsResolver instance has been created.
4952 * @param slotId The slot ID that the IMS service is created for.
4953 * @throws ImsException If there is no ImsService configured for this slot.
4954 */
4955 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4956 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4957 ImsFeature.FEATURE_MMTEL)) {
4958 throw new ImsException("This subscription does not support MMTEL over IMS",
4959 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4960 }
4961 }
4962
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004963 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 int slotId = SubscriptionManager.getSlotIndex(subId);
4965 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004966 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4967 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004968 }
4969 return slotId;
4970 }
4971
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 private int getSlotIndex(int subId) {
4973 int slotId = SubscriptionManager.getSlotIndex(subId);
4974 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4975 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4976 }
4977 return slotId;
4978 }
4979
Wink Saville36469e72014-06-11 15:17:00 -07004980 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004981 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004982 */
4983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4985 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004986 try {
4987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4988 } catch (SecurityException se) {
4989 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4990 throw new SecurityException("Package " + callingPackage + " does not belong to "
4991 + Binder.getCallingUid());
4992 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004993 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004994 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004995 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004996 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004997 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004998 mApp, subId, callingPackage, callingFeatureId,
4999 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005000 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5001 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 final long identity = Binder.clearCallingIdentity();
5004 try {
5005 final Phone phone = getPhone(subId);
5006 if (phone != null) {
5007 return phone.getServiceState().getDataNetworkType();
5008 } else {
5009 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5010 }
5011 } finally {
5012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005014 }
5015
5016 /**
5017 * Returns the data network type
5018 */
5019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005020 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005021 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5022 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005023 }
5024
5025 /**
5026 * Returns the data network type for a subId
5027 */
5028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5030 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005031 String functionName = "getDataNetworkTypeForSubscriber";
5032 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5033 mApp, functionName)) {
5034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5035 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5036 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5037 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005038 }
5039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 final Phone phone = getPhone(subId);
5043 if (phone != null) {
5044 return phone.getServiceState().getDataNetworkType();
5045 } else {
5046 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5047 }
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005051 }
5052
5053 /**
Wink Saville36469e72014-06-11 15:17:00 -07005054 * Returns the Voice network type for a subId
5055 */
5056 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005057 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5058 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005059 String functionName = "getVoiceNetworkTypeForSubscriber";
5060 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5061 mApp, functionName)) {
5062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5063 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5064 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5065 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005066 }
5067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 final Phone phone = getPhone(subId);
5071 if (phone != null) {
5072 return phone.getServiceState().getVoiceNetworkType();
5073 } else {
5074 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5075 }
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005079 }
5080
5081 /**
5082 * @return true if a ICC card is present
5083 */
5084 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005085 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005086 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5087 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005088 }
5089
5090 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005091 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005092 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005093 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005094 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 final Phone phone = PhoneFactory.getPhone(slotIndex);
5098 if (phone != null) {
5099 return phone.getIccCard().hasIccCard();
5100 } else {
5101 return false;
5102 }
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005106 }
5107
5108 /**
5109 * Return if the current radio is LTE on CDMA. This
5110 * is a tri-state return value as for a period of time
5111 * the mode may be unknown.
5112 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005113 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005114 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005115 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005116 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005118 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5119 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5120 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005121 }
5122
Sanket Padawe356d7632015-06-22 14:03:32 -07005123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005124 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5125 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005126 try {
5127 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5128 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005129 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5130 }
5131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 final Phone phone = getPhone(subId);
5135 if (phone == null) {
5136 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5137 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005138 return TelephonyProperties.lte_on_cdma_device()
5139 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 }
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005143 }
Wink Saville36469e72014-06-11 15:17:00 -07005144 }
5145
Wink Saville36469e72014-06-11 15:17:00 -07005146 /**
5147 * {@hide}
5148 * Returns Default subId, 0 in the case of single standby.
5149 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005150 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005151 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005152 }
5153
Shishir Agrawala9f32182016-04-12 12:00:16 -07005154 private int getSlotForDefaultSubscription() {
5155 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5156 }
5157
Wink Savilleb564aae2014-10-23 10:18:09 -07005158 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005159 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005160 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005161
Pengquan Menge92a50d2018-09-21 15:54:48 -07005162 private boolean isActiveSubscription(int subId) {
5163 return mSubscriptionController.isActiveSubId(subId);
5164 }
5165
Ihab Awadf2177b72013-11-25 13:33:23 -08005166 /**
5167 * @see android.telephony.TelephonyManager.WifiCallingChoices
5168 */
5169 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5174 getWhenToMakeWifiCallsDefaultPreference());
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005178 }
5179
5180 /**
5181 * @see android.telephony.TelephonyManager.WifiCallingChoices
5182 */
5183 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005187 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005192 }
5193
Sailesh Nepald1e68152013-12-12 19:08:02 -08005194 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005195 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005196 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005197 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005198
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005199 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5200 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5201 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005202 if (phoneId == -1) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005203 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5204 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005205 }
5206 return PhoneFactory.getPhone(phoneId);
5207 }
5208
Shishir Agrawal566b7612013-10-28 14:41:00 -07005209 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005210 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wange162e302021-11-10 20:15:19 -08005211 @NonNull IccLogicalChannelRequest request) {
5212 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5213 /*message=*/ "iccOpenLogicalChannel");
5214
5215 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5216 // Verify that the callingPackage in the request belongs to the calling UID
5217 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5218
5219 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005220 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005221
Rambo Wange162e302021-11-10 20:15:19 -08005222 private Phone getPhoneFromValidIccLogicalChannelRequest(
5223 @NonNull IccLogicalChannelRequest request, String message) {
5224 Phone phone;
5225 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5227 mApp, request.subId, message);
5228 phone = getPhoneFromSubId(request.subId);
5229 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5230 enforceModifyPermission();
5231 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5232 } else {
5233 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005234 }
Rambo Wange162e302021-11-10 20:15:19 -08005235 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005236 }
5237
5238 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wange162e302021-11-10 20:15:19 -08005239 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 final long identity = Binder.clearCallingIdentity();
5241 try {
Rambo Wange162e302021-11-10 20:15:19 -08005242 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005244 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5245 .getContext().getPackageManager());
Rambo Wange162e302021-11-10 20:15:19 -08005246 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5247 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 loge("The calling package is not allowed to access ISD-R.");
5249 throw new SecurityException(
5250 "The calling package is not allowed to access ISD-R.");
5251 }
Derek Tan740e1672017-06-27 14:56:27 -07005252 }
Derek Tan740e1672017-06-27 14:56:27 -07005253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wange162e302021-11-10 20:15:19 -08005255 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5256 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 return response;
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005261 }
5262
5263 @Override
Rambo Wange162e302021-11-10 20:15:19 -08005264 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5265 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5266 /*message=*/"iccCloseLogicalChannel");
5267
5268 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5269
5270 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005271 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005272
Rambo Wange162e302021-11-10 20:15:19 -08005273 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5274 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
Rambo Wange162e302021-11-10 20:15:19 -08005277 if (request.channel < 0) {
Chen Xu9040b472021-12-14 17:15:47 -08005278 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 }
Rambo Wange162e302021-11-10 20:15:19 -08005280 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005281 null /* workSource */);
Rambo Wange162e302021-11-10 20:15:19 -08005282 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 return success;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005286 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005287 }
5288
5289 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005290 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5293 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005294 if (DBG) {
5295 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5296 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5297 + p3 + " data=" + data);
5298 }
5299 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5300 command, p1, p2, p3, data);
5301 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005302
Jordan Liu4c733742019-02-28 12:03:40 -08005303 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005304 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5305 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005306 enforceModifyPermission();
5307 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005308 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5309 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5310 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005311 }
5312 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005313 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5314 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005315 }
5316
5317 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5318 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005321 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 return "";
5323 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005326 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5327 null /* workSource */);
5328 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 // Append the returned status code to the end of the response payload.
5331 String s = Integer.toHexString(
5332 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5333 if (response.payload != null) {
5334 s = IccUtils.bytesToHexString(response.payload) + s;
5335 }
5336 return s;
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005339 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005340 }
Jake Hambye994d462014-02-03 13:10:13 -08005341
Evan Charltonc66da362014-05-16 14:06:40 -07005342 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005343 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5344 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5346 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005348 if (DBG) {
5349 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5350 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5351 }
5352 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5353 cla, command, p1, p2, p3, data);
5354 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005355
Jordan Liu4c733742019-02-28 12:03:40 -08005356 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005357 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5358 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005359 enforceModifyPermission();
5360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5361 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005362 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5363 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5364 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005365 }
5366
5367 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005368 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5369 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
5371
5372 // open APDU basic channel assuming the caller has sufficient permissions
5373 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5374 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5378 && TextUtils.equals(ISDR_AID, data)) {
5379 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005380 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5381 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 if (bestComponent == null
5383 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5384 loge("The calling package is not allowed to select ISD-R.");
5385 throw new SecurityException(
5386 "The calling package is not allowed to select ISD-R.");
5387 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005388 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005391 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5392 null /* workSource */);
5393 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 // Append the returned status code to the end of the response payload.
5396 String s = Integer.toHexString(
5397 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5398 if (response.payload != null) {
5399 s = IccUtils.bytesToHexString(response.payload) + s;
5400 }
5401 return s;
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005404 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405 }
5406
5407 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005408 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005409 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5411 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 if (DBG) {
5416 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5417 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5418 }
5419
5420 IccIoResult response =
5421 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5422 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5423 subId);
5424
5425 if (DBG) {
5426 log("Exchange SIM_IO [R]" + response);
5427 }
5428
5429 byte[] result = null;
5430 int length = 2;
5431 if (response.payload != null) {
5432 length = 2 + response.payload.length;
5433 result = new byte[length];
5434 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5435 } else {
5436 result = new byte[length];
5437 }
5438
5439 result[length - 1] = (byte) response.sw2;
5440 result[length - 2] = (byte) response.sw1;
5441 return result;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 }
5446
Nathan Haroldb3014052017-01-25 15:57:32 -08005447 /**
5448 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5449 * on a particular subscription
5450 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005451 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5452 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005454 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005455 return null;
5456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457
5458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 if (appType != TelephonyManager.APPTYPE_USIM
5461 && appType != TelephonyManager.APPTYPE_SIM) {
5462 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5463 return null;
5464 }
5465 Object response = sendRequest(
5466 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5467 if (response instanceof String[]) {
5468 return (String[]) response;
5469 }
yincheng zhao2737e882019-09-06 17:06:54 -07005470 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005472 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 } finally {
5474 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005475 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005476 }
5477
yincheng zhao2737e882019-09-06 17:06:54 -07005478 /**
5479 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5480 * subscription.
5481 *
5482 * @param subId the id of the subscription.
5483 * @param appType the uicc app type, must be USIM or SIM.
5484 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5485 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005487 * @return number of fplmns that is successfully written to the SIM.
5488 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5490 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5492 mApp, subId, "setForbiddenPlmns");
5493
yincheng zhao2737e882019-09-06 17:06:54 -07005494 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5495 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5496 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5497 }
5498 if (fplmns == null) {
5499 throw new IllegalArgumentException("Fplmn List provided is null");
5500 }
5501 for (String fplmn : fplmns) {
5502 if (!CellIdentity.isValidPlmn(fplmn)) {
5503 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5504 }
5505 }
5506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 Object response = sendRequest(
5509 CMD_SET_FORBIDDEN_PLMNS,
5510 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5511 subId);
5512 return (int) response;
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
5516 }
5517
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005518 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005519 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5526 if (response.payload == null) {
5527 return "";
5528 }
Evan Charltonc66da362014-05-16 14:06:40 -07005529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 // Append the returned status code to the end of the response payload.
5531 String s = Integer.toHexString(
5532 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5533 s = IccUtils.bytesToHexString(response.payload) + s;
5534 return s;
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
Evan Charltonc66da362014-05-16 14:06:40 -07005538 }
5539
Jake Hambye994d462014-02-03 13:10:13 -08005540 /**
5541 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5542 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5543 *
5544 * @param itemID the ID of the item to read
5545 * @return the NV item as a String, or null on error.
5546 */
5547 @Override
5548 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005549 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5551 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005556 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5558 return value;
5559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
Jake Hambye994d462014-02-03 13:10:13 -08005562 }
5563
5564 /**
5565 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5566 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5567 *
5568 * @param itemID the ID of the item to read
5569 * @param itemValue the value to write, as a String
5570 * @return true on success; false on any failure
5571 */
5572 @Override
5573 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5576 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
5578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5581 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005582 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5584 return success;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Jake Hambye994d462014-02-03 13:10:13 -08005588 }
5589
5590 /**
5591 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5592 * Used for device configuration by some CDMA operators.
5593 *
5594 * @param preferredRoamingList byte array containing the new PRL
5595 * @return true on success; false on any failure
5596 */
5597 @Override
5598 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5600 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5605 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5606 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5607 return success;
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Jake Hambye994d462014-02-03 13:10:13 -08005611 }
5612
5613 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005614 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005615 * Used for device configuration by some CDMA operators.
5616 *
chen xu6dac5ab2018-10-26 17:39:23 -07005617 * @param slotIndex - device slot.
5618 *
Jake Hambye994d462014-02-03 13:10:13 -08005619 * @return true on success; false on any failure
5620 */
5621 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005622 public boolean resetModemConfig(int slotIndex) {
5623 Phone phone = PhoneFactory.getPhone(slotIndex);
5624 if (phone != null) {
5625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
chen xu6dac5ab2018-10-26 17:39:23 -07005628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5631 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5632 return success;
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 }
chen xu6dac5ab2018-10-26 17:39:23 -07005637 return false;
5638 }
5639
5640 /**
5641 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5642 *
5643 * @param slotIndex - device slot.
5644 *
5645 * @return true on success; false on any failure
5646 */
5647 @Override
5648 public boolean rebootModem(int slotIndex) {
5649 Phone phone = PhoneFactory.getPhone(slotIndex);
5650 if (phone != null) {
5651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, phone.getSubId(), "rebootModem");
5653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5657 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5658 return success;
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005664 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005665
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005666 public String[] getPcscfAddress(String apnType, String callingPackage,
5667 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005668 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5670 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005671 return new String[0];
5672 }
5673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 final long identity = Binder.clearCallingIdentity();
5675 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005676 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Wink Saville36469e72014-06-11 15:17:00 -07005680 }
5681
Brad Ebinger51f743a2017-01-23 13:50:20 -08005682 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005683 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5684 * {@link #disableIms(int)}.
5685 * @param slotIndex device slot.
5686 */
5687 public void resetIms(int slotIndex) {
5688 enforceModifyPermission();
5689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 if (mImsResolver == null) {
5693 // may happen if the does not support IMS.
5694 return;
5695 }
5696 mImsResolver.disableIms(slotIndex);
5697 mImsResolver.enableIms(slotIndex);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
5703 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005704 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5705 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005706 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005707 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005713 // may happen if the device does not support IMS.
5714 return;
5715 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005720 }
5721
5722 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005723 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5724 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005725 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005726 public void disableIms(int slotId) {
5727 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005731 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005732 // may happen if the device does not support IMS.
5733 return;
5734 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 }
5740
5741 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005742 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5743 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005744 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005745 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005746 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005752 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5753 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005754 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005755 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005759 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005760 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005761 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5762 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005763 @Override
5764 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005765 enforceModifyPermission();
5766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005770 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
5774 }
5775
5776 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005777 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005778 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005779 */
5780 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782
5783 final long identity = Binder.clearCallingIdentity();
5784 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005786 // may happen if the device does not support IMS.
5787 return null;
5788 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005793 }
5794
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005795 /**
5796 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005797 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 */
5799 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005804 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005805 // may happen if the device does not support IMS.
5806 return null;
5807 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005808 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005812 }
5813
Brad Ebinger884c07b2018-02-15 16:17:40 -08005814 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005815 * Sets the ImsService Package Name that Telephony will bind to.
5816 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 * @param slotIndex the slot ID that the ImsService should bind for.
5818 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005819 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 * @param featureTypes An integer array of feature types associated with a packageName.
5821 * @param packageName The name of the package that the current configuration will be replaced
5822 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005823 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005824 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5826 int[] featureTypes, String packageName) {
5827 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5830 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 // may happen if the device does not support IMS.
5837 return false;
5838 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 Map<Integer, String> featureConfig = new HashMap<>();
5840 for (int featureType : featureTypes) {
5841 featureConfig.put(featureType, packageName);
5842 }
5843 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5844 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005848 }
5849
5850 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005851 * Clears any carrier ImsService overrides for the slot index specified that were previously
5852 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5853 *
5854 * This should only be used for testing.
5855 *
5856 * @param slotIndex the slot ID that the ImsService should bind for.
5857 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5858 */
5859 @Override
5860 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5861 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5863 "clearCarrierImsServiceOverride");
5864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5865 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5866 "clearCarrierImsServiceOverride");
5867
5868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 if (mImsResolver == null) {
5871 // may happen if the device does not support IMS.
5872 return false;
5873 }
5874 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
5878 }
5879
5880 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005882 *
5883 * @param slotId The slot that the ImsService is associated with.
5884 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5885 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005887 * @return the package name of the ImsService configuration.
5888 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5890 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005891 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005892 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005893 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5895 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005900 // may happen if the device does not support IMS.
5901 return "";
5902 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005903 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5905 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005909 }
5910
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005911 /**
5912 * Get the MmTelFeature state associated with the requested subscription id.
5913 * @param subId The subscription that the MmTelFeature is associated with.
5914 * @param callback A callback with an integer containing the
5915 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5916 */
5917 @Override
5918 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5919 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5920 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5921 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5922 "IMS not available on device.");
5923 }
5924 final long token = Binder.clearCallingIdentity();
5925 try {
5926 int slotId = getSlotIndex(subId);
5927 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5928 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5929 + subId + "'");
5930 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5931 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005932 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005933 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5934 try {
5935 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5936 } catch (RemoteException e) {
5937 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5938 + "Ignore");
5939 }
5940 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005941 } catch (ImsException e) {
5942 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005943 } finally {
5944 Binder.restoreCallingIdentity(token);
5945 }
5946 }
5947
Daniel Brightbb5840b2021-01-12 15:48:18 -08005948 /**
5949 * Sets the ims registration state on all valid {@link Phone}s.
5950 */
5951 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005952 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005956 // NOTE: Before S, this method only set the default phone.
5957 for (final Phone phone : PhoneFactory.getPhones()) {
5958 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5959 phone.setImsRegistrationState(registered);
5960 }
5961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Wink Saville36469e72014-06-11 15:17:00 -07005965 }
5966
5967 /**
Stuart Scott54788802015-03-30 13:18:01 -07005968 * Set the network selection mode to automatic.
5969 *
5970 */
5971 @Override
5972 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5974 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975
5976 final long identity = Binder.clearCallingIdentity();
5977 try {
shilufc958392020-01-20 11:36:01 -08005978 if (!isActiveSubscription(subId)) {
5979 return;
5980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005982 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5983 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Stuart Scott54788802015-03-30 13:18:01 -07005987 }
5988
Jack Yud10cdd42020-09-28 20:28:01 -07005989 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005990 * Ask the radio to connect to the input network and change selection mode to manual.
5991 *
5992 * @param subId the id of the subscription.
5993 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5994 * the operator to attach to.
5995 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5996 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5997 * normal network selection next time.
5998 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005999 */
6000 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006001 public boolean setNetworkSelectionModeManual(
6002 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006005
6006 if (!isActiveSubscription(subId)) {
6007 return false;
6008 }
6009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 final long identity = Binder.clearCallingIdentity();
6011 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006012 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006014 if (DBG) {
6015 log("setNetworkSelectionModeManual: subId: " + subId
6016 + " operator: " + operatorInfo);
6017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006022 }
shilu84f6e8b2019-12-19 13:58:01 -08006023 /**
6024 * Get the manual network selection
6025 *
6026 * @param subId the id of the subscription.
6027 *
6028 * @return the previously saved user selected PLMN
6029 */
6030 @Override
6031 public String getManualNetworkSelectionPlmn(int subId) {
6032 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006033 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006034 mApp, subId, "getManualNetworkSelectionPlmn");
6035
6036 final long identity = Binder.clearCallingIdentity();
6037 try {
6038 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006039 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006040 }
6041
6042 final Phone phone = getPhone(subId);
6043 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006044 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006045 }
6046 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6047 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6048 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006053
6054 /**
6055 * Scans for available networks.
6056 */
6057 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006058 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6059 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6061 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006062 LocationAccessPolicy.LocationPermissionResult locationResult =
6063 LocationAccessPolicy.checkLocationPermission(mApp,
6064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6065 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006066 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006067 .setCallingPid(Binder.getCallingPid())
6068 .setCallingUid(Binder.getCallingUid())
6069 .setMethod("getCellNetworkScanResults")
6070 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006071 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6072 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 .build());
6074 switch (locationResult) {
6075 case DENIED_HARD:
6076 throw new SecurityException("Not allowed to access scan results -- location");
6077 case DENIED_SOFT:
6078 return null;
6079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080
Pengquan Menga1bb6272018-09-06 09:59:22 -07006081 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 try {
6083 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006084 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006089 }
6090
6091 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006092 * Get the call forwarding info, given the call forwarding reason.
6093 */
6094 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006095 public void getCallForwarding(int subId, int callForwardingReason,
6096 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006097 enforceReadPrivilegedPermission("getCallForwarding");
6098 long identity = Binder.clearCallingIdentity();
6099 try {
6100 if (DBG) {
6101 log("getCallForwarding: subId " + subId
6102 + " callForwardingReason" + callForwardingReason);
6103 }
Hall Liu27d24262020-09-18 19:04:59 -07006104
6105 Phone phone = getPhone(subId);
6106 if (phone == null) {
6107 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006108 callback.onError(
6109 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006110 } catch (RemoteException e) {
6111 // ignore
6112 }
6113 return;
6114 }
6115
6116 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6117 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6118 @Override
6119 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6120 try {
6121 callback.onCallForwardingInfoAvailable(info);
6122 } catch (RemoteException e) {
6123 // ignore
6124 }
6125 }
6126
6127 @Override
6128 public void onError(int error) {
6129 try {
6130 callback.onError(error);
6131 } catch (RemoteException e) {
6132 // ignore
6133 }
6134 }
6135 });
6136 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
6140 }
6141
6142 /**
6143 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6144 * reason, the number to forward, and the timeout before the forwarding is attempted.
6145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6148 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006149 enforceModifyPermission();
6150 long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (DBG) {
6153 log("setCallForwarding: subId " + subId
6154 + " callForwardingInfo" + callForwardingInfo);
6155 }
Hall Liu27d24262020-09-18 19:04:59 -07006156
6157 Phone phone = getPhone(subId);
6158 if (phone == null) {
6159 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006160 callback.accept(
6161 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 return;
6166 }
6167
6168 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6169 FunctionalUtils.ignoreRemoteException(callback::accept));
6170
6171 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
Hall Liu27d24262020-09-18 19:04:59 -07006178 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006179 */
6180 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006181 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006182 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006183 long identity = Binder.clearCallingIdentity();
6184 try {
Hall Liu27d24262020-09-18 19:04:59 -07006185 Phone phone = getPhone(subId);
6186 if (phone == null) {
6187 try {
6188 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6189 } catch (RemoteException e) {
6190 // ignore
6191 }
6192 return;
6193 }
SongFerngWang0e767992021-03-31 22:08:45 +08006194 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6195 PersistableBundle c = configManager.getConfigForSubId(subId);
6196 boolean requireUssd = c.getBoolean(
6197 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006198
Shuo Qian4a594052020-01-23 11:59:30 -08006199 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006200 if (requireUssd) {
6201 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6202 getSubscriptionCarrierId(subId));
6203 String newUssdCommand = "";
6204 try {
6205 newUssdCommand = carrierXmlParser.getFeature(
6206 CarrierXmlParser.FEATURE_CALL_WAITING)
6207 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6208 } catch (NullPointerException e) {
6209 loge("Failed to generate USSD number" + e);
6210 }
6211 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6212 mMainThreadHandler, callback, carrierXmlParser,
6213 CarrierXmlParser.SsEntry.SSAction.QUERY);
6214 final String ussdCommand = newUssdCommand;
6215 Executors.newSingleThreadExecutor().execute(() -> {
6216 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6217 });
6218 } else {
6219 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6220 callback::accept);
6221 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6222 }
Shuo Qian4a594052020-01-23 11:59:30 -08006223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
6228 /**
Hall Liu27d24262020-09-18 19:04:59 -07006229 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006230 */
6231 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006232 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006233 enforceModifyPermission();
6234 long identity = Binder.clearCallingIdentity();
6235 try {
Hall Liu27d24262020-09-18 19:04:59 -07006236 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6237
6238 Phone phone = getPhone(subId);
6239 if (phone == null) {
6240 try {
6241 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6242 } catch (RemoteException e) {
6243 // ignore
6244 }
6245 return;
6246 }
6247
SongFerngWang0e767992021-03-31 22:08:45 +08006248 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6249 PersistableBundle c = configManager.getConfigForSubId(subId);
6250 boolean requireUssd = c.getBoolean(
6251 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006252
SongFerngWang0e767992021-03-31 22:08:45 +08006253 if (DBG) log("getCallWaitingStatus: subId " + subId);
6254 if (requireUssd) {
6255 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6256 getSubscriptionCarrierId(subId));
6257 CarrierXmlParser.SsEntry.SSAction ssAction =
6258 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6259 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6260 String newUssdCommand = "";
6261 try {
6262 newUssdCommand = carrierXmlParser.getFeature(
6263 CarrierXmlParser.FEATURE_CALL_WAITING)
6264 .makeCommand(ssAction, null);
6265 } catch (NullPointerException e) {
6266 loge("Failed to generate USSD number" + e);
6267 }
6268 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6269 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6270 final String ussdCommand = newUssdCommand;
6271 Executors.newSingleThreadExecutor().execute(() -> {
6272 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6273 });
6274 } else {
6275 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6276 FunctionalUtils.ignoreRemoteException(callback::accept));
6277
6278 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6279 }
Shuo Qian4a594052020-01-23 11:59:30 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
6283 }
6284
6285 /**
yinxub1bed742017-04-17 11:45:04 -07006286 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006287 *
yinxub1bed742017-04-17 11:45:04 -07006288 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006289 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6290 * location related information which will be sent if the caller already possess
6291 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006292 * @param request contains the radio access networks with bands/channels to scan
6293 * @param messenger callback messenger for scan results or errors
6294 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006295 * @return the id of the requested scan which can be used to stop the scan.
6296 */
6297 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006298 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6299 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006300 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6302 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006303 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006304 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6305 if (!renounceFineLocationAccess) {
6306 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6307 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6308 .setCallingPackage(callingPackage)
6309 .setCallingFeatureId(callingFeatureId)
6310 .setCallingPid(Binder.getCallingPid())
6311 .setCallingUid(Binder.getCallingUid())
6312 .setMethod("requestNetworkScan")
6313 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6314 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6315 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6316 .build());
6317 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006318 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006319 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6320 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 if (e != null) {
6322 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6323 throw e;
6324 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006325 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006326 return TelephonyScanManager.INVALID_SCAN_ID;
6327 }
6328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 }
Hall Liu912dfd32019-04-25 14:02:26 -07006330 int callingUid = Binder.getCallingUid();
6331 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006335 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006336 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
yinxu504e1392017-04-12 16:03:22 -07006340 }
6341
Hall Liub2ac8ef2019-02-28 15:56:23 -08006342 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006343 NetworkScanRequest request, int subId, String callingPackage) {
6344 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006345 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6346 boolean hasNetworkScanPermission =
6347 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6348 == PERMISSION_GRANTED;
6349
6350 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6351 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6352 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 }
6354
6355 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6356 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006357 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6358 return new SecurityException("Specific channels must not be"
6359 + " scanned without location access.");
6360 }
6361 }
6362 }
6363
Hall Liub2ac8ef2019-02-28 15:56:23 -08006364 return null;
6365 }
6366
yinxu504e1392017-04-12 16:03:22 -07006367 /**
6368 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006369 *
6370 * @param subId id of the subscription
6371 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006372 */
6373 @Override
6374 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6376 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
Hall Liu912dfd32019-04-25 14:02:26 -07006378 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 final long identity = Binder.clearCallingIdentity();
6380 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006381 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
yinxu504e1392017-04-12 16:03:22 -07006385 }
6386
6387 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006388 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006389 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006390 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006391 */
6392 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006393 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006400 if (DBG) log("getAllowedNetworkTypesBitmask");
6401 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6402 int networkTypesBitmask = (result != null ? result[0] : -1);
6403 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6404 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006408 }
6409
6410 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006411 * Get the allowed network types for certain reason.
6412 *
6413 * @param subId the id of the subscription.
6414 * @param reason the reason the allowed network type change is taking place
6415 * @return the allowed network types.
6416 */
6417 @Override
6418 public long getAllowedNetworkTypesForReason(int subId,
6419 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006420 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006421 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
6430 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006431 * Enable/Disable E-UTRA-NR Dual Connectivity
6432 * @param subId subscription id of the sim card
6433 * @param nrDualConnectivityState expected NR dual connectivity state
6434 * This can be passed following states
6435 * <ol>
6436 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6437 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6438 * <li>Disable NR dual connectivity and force secondary cell to be released
6439 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6440 * </ol>
6441 * @return operation result.
6442 */
6443 @Override
6444 public int setNrDualConnectivityState(int subId,
6445 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6447 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006448 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006449 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6450 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6451 }
6452
Sooraj Sasindran37444802020-08-11 10:40:43 -07006453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6457 nrDualConnectivityState, subId,
6458 workSource);
6459 if (DBG) log("enableNRDualConnectivity result: " + result);
6460 return result;
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
6464 }
6465
6466 /**
6467 * Is E-UTRA-NR Dual Connectivity enabled
6468 * @return true if dual connectivity is enabled else false
6469 */
6470 @Override
6471 public boolean isNrDualConnectivityEnabled(int subId) {
6472 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006473 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006474 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006475 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006476 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6477 return false;
6478 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6483 null, subId, workSource);
6484 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6485 return isEnabled;
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006492 * Set the allowed network types of the device and
6493 * provide the reason triggering the allowed network change.
6494 *
6495 * @param subId the id of the subscription.
6496 * @param reason the reason the allowed network type change is taking place
6497 * @param allowedNetworkTypes the allowed network types.
6498 * @return true on success; false on any failure.
6499 */
6500 @Override
6501 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006502 @TelephonyManager.AllowedNetworkTypesReason int reason,
6503 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6505 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006507 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6508 return false;
6509 }
6510 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6511 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 return false;
6513 }
6514
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006515 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6516 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6517
6518
6519 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6520 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6521 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006522 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006523
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006524 final long identity = Binder.clearCallingIdentity();
6525 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006526 Boolean success = (Boolean) sendRequest(
6527 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6528 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6529
6530 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6531 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
6537 /**
Miaoa84611c2019-03-15 09:21:10 +08006538 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006539 *
Miaoa84611c2019-03-15 09:21:10 +08006540 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006541 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006542 * @hide
6543 */
6544 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006545 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006546 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 try {
Miaoa84611c2019-03-15 09:21:10 +08006550 if (phone != null) {
6551 return phone.hasMatchedTetherApnSetting();
6552 } else {
6553 return false;
6554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 } finally {
6556 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006557 }
Junda Liu475951f2014-11-07 16:45:03 -08006558 }
6559
6560 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006561 * Get the user enabled state of Mobile Data.
6562 *
6563 * TODO: remove and use isUserDataEnabled.
6564 * This can't be removed now because some vendor codes
6565 * calls through ITelephony directly while they should
6566 * use TelephonyManager.
6567 *
6568 * @return true on enabled
6569 */
6570 @Override
6571 public boolean getDataEnabled(int subId) {
6572 return isUserDataEnabled(subId);
6573 }
6574
6575 /**
6576 * Get whether mobile data is enabled per user setting.
6577 *
6578 * There are other factors deciding whether mobile data is actually enabled, but they are
6579 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006580 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006581 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6582 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006583 *
6584 * @return {@code true} if data is enabled else {@code false}
6585 */
6586 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006587 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006588 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006589 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006590 try {
6591 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6592 functionName);
6593 } catch (Exception e) {
6594 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6595 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006596 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006598 mApp, subId, functionName);
6599
Robert Greenwalt646120a2014-05-23 11:54:03 -07006600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 int phoneId = mSubscriptionController.getPhoneId(subId);
6605 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6606 Phone phone = PhoneFactory.getPhone(phoneId);
6607 if (phone != null) {
6608 boolean retVal = phone.isUserDataEnabled();
6609 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6610 return retVal;
6611 } else {
6612 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6613 return false;
6614 }
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006617 }
6618 }
6619
6620 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006621 * Checks if the device is capable of mobile data by considering whether whether the
6622 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6623 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006624 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006625 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006626 */
6627 @Override
6628 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006629 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006630 try {
6631 try {
6632 mApp.enforceCallingOrSelfPermission(
6633 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006634 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006635 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 try {
6637 mApp.enforceCallingOrSelfPermission(
6638 android.Manifest.permission.READ_PHONE_STATE,
6639 functionName);
6640 } catch (Exception e2) {
6641 mApp.enforceCallingOrSelfPermission(
6642 permission.READ_BASIC_PHONE_STATE, functionName);
6643 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 }
6645 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 Phone phone = PhoneFactory.getPhone(phoneId);
6653 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006654 boolean retVal;
6655 if (phone.isUsingNewDataStack()) {
Sarah Chin8619e162022-03-09 13:57:52 -08006656 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006657 } else {
6658 retVal = phone.getDataEnabledSettings().isDataEnabled();
6659 }
6660 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 return retVal;
6662 } else {
6663 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6664 return false;
6665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006668 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006669 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006670
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006671 /**
6672 * Check if data is enabled for a specific reason
6673 * @param subId Subscription index
6674 * @param reason the reason the data enable change is taking place
6675 * @return {@code true} if the overall data is enabled; {@code false} if not.
6676 */
6677 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006678 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006679 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006680 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006681 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006682 try {
6683 mApp.enforceCallingOrSelfPermission(
6684 android.Manifest.permission.ACCESS_NETWORK_STATE,
6685 functionName);
6686 } catch (Exception e) {
6687 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6688 functionName);
6689 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006691 try {
6692 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006693 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006694 } catch (Exception e2) {
6695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006696 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006697 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006698 }
6699
6700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 int phoneId = mSubscriptionController.getPhoneId(subId);
6704 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006705 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 + " reason=" + reason);
6707 }
6708 Phone phone = PhoneFactory.getPhone(phoneId);
6709 if (phone != null) {
6710 boolean retVal;
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006711 if (phone.isUsingNewDataStack()) {
6712 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006713 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006714 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6715 retVal = phone.isUserDataEnabled();
6716 } else {
6717 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6718 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006720 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 return retVal;
6722 } else {
6723 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006724 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006725 + subId + " retVal=false");
6726 }
6727 return false;
6728 }
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
6732 }
6733
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006734 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006735 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006736 if (uid == Process.PHONE_UID) {
6737 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6738 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6740 }
6741
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006742 //load access rules from carrier configs, and check those as well: b/139133814
6743 SubscriptionController subController = SubscriptionController.getInstance();
6744 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6745 || subController == null) return privilegeFromSim;
6746
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006747 PackageManager pkgMgr = phone.getContext().getPackageManager();
6748 String[] packages = pkgMgr.getPackagesForUid(uid);
6749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006752 int subId = phone.getSubId();
6753 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6754 // A test override is in place for the privileges for this subId, so don't try to
6755 // read the subscription privileges.
6756 return privilegeFromSim;
6757 }
6758 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 SubscriptionManager subManager = (SubscriptionManager)
6760 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6761 for (String pkg : packages) {
6762 if (subManager.canManageSubscription(subInfo, pkg)) {
6763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6764 }
6765 }
6766 return privilegeFromSim;
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
6769 }
6770 }
6771
6772 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6773 String pkgName) {
6774 //load access rules from carrier configs, and check those as well: b/139133814
6775 SubscriptionController subController = SubscriptionController.getInstance();
6776 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6777 || subController == null) return privilegeFromSim;
6778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006781 int subId = phone.getSubId();
6782 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6783 // A test override is in place for the privileges for this subId, so don't try to
6784 // read the subscription privileges.
6785 return privilegeFromSim;
6786 }
6787 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006788 SubscriptionManager subManager = (SubscriptionManager)
6789 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6790 return subManager.canManageSubscription(subInfo, pkgName)
6791 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
6795 }
6796
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006797 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006798 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006799 // No permission needed; this only lets the caller inspect their own status.
6800 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006801 }
Junda Liu29340342014-07-10 15:23:27 -07006802
6803 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006804 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006805 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006806 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6807 }
6808
6809 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6810 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006811 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006812 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6814 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006815 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6816 if (cpt == null) {
6817 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006818 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6819 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006820 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 }
6822
6823 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006824 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006825 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006826 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006828 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006829 Phone phone = getPhone(subId);
6830 if (phone == null) {
6831 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6833 }
6834 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6835 if (cpt == null) {
6836 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006837 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6838 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006839 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006840 }
6841
6842 @Override
6843 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006844 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6845 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006847 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006848 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006849 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6850 Phone phone = PhoneFactory.getPhone(phoneId);
6851 if (phone == null) {
6852 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006853 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006854 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6855 if (cpt == null) {
6856 continue;
6857 }
6858 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006859 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6860 break;
6861 }
6862 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006863 return result;
Junda Liu29340342014-07-10 15:23:27 -07006864 }
Derek Tan89e89d42014-07-08 17:00:10 -07006865
6866 @Override
Junda Liue64de782015-04-16 17:19:16 -07006867 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006868 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006869 Phone phone = PhoneFactory.getPhone(phoneId);
6870 if (phone == null) {
6871 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006872 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006873 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6874 if (cpt == null) {
6875 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006876 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006877 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006878 }
6879
Amith Yamasani6e118872016-02-19 12:53:51 -08006880 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006881 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006882 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006883 Phone phone = PhoneFactory.getPhone(phoneId);
6884 if (phone == null) {
6885 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006886 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006887 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6888 if (cpt == null) {
6889 return Collections.emptyList();
6890 }
6891 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006892 }
6893
chen xuf7e9fe82019-05-09 19:31:02 -07006894 @Override
6895 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006896 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006897 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006898 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006899 try {
6900 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6901 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6902 }
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006905 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006906 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006907 }
6908
Wink Savilleb564aae2014-10-23 10:18:09 -07006909 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006910 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006911 UiccPort port = phone == null ? null : phone.getUiccPort();
6912 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006913 return null;
6914 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006915 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006916 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006917 return null;
6918 }
6919 return iccId;
6920 }
6921
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006922 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006923 public void setCallComposerStatus(int subId, int status) {
6924 enforceModifyPermission();
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 Phone phone = getPhone(subId);
6929 if (phone != null) {
6930 Phone defaultPhone = phone.getImsPhone();
6931 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6932 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6933 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006934 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6935 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006936 }
6937 }
Shuo Qian284ae752020-12-22 19:10:14 -08006938 } catch (ImsException e) {
6939 throw new ServiceSpecificException(e.getCode());
6940 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006941 Binder.restoreCallingIdentity(identity);
6942 }
6943 }
6944
6945 @Override
6946 public int getCallComposerStatus(int subId) {
6947 enforceReadPrivilegedPermission("getCallComposerStatus");
6948
6949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 Phone phone = getPhone(subId);
6952 if (phone != null) {
6953 Phone defaultPhone = phone.getImsPhone();
6954 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6955 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6956 return imsPhone.getCallComposerStatus();
6957 }
6958 }
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
6962 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6963 }
6964
6965 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006966 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6967 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006968 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006969 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 final String iccId = getIccId(subId);
6974 final Phone phone = getPhone(subId);
6975 if (phone == null) {
6976 return false;
6977 }
6978 final String subscriberId = phone.getSubscriberId();
6979
6980 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006981 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 + subscriberId + " to " + number);
6983 }
6984
6985 if (TextUtils.isEmpty(iccId)) {
6986 return false;
6987 }
6988
6989 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6990
6991 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6992 if (alphaTag == null) {
6993 editor.remove(alphaTagPrefKey);
6994 } else {
6995 editor.putString(alphaTagPrefKey, alphaTag);
6996 }
6997
6998 // Record both the line number and IMSI for this ICCID, since we need to
6999 // track all merged IMSIs based on line number
7000 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7001 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7002 if (number == null) {
7003 editor.remove(numberPrefKey);
7004 editor.remove(subscriberPrefKey);
7005 } else {
7006 editor.putString(numberPrefKey, number);
7007 editor.putString(subscriberPrefKey, subscriberId);
7008 }
7009
7010 editor.commit();
7011 return true;
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007014 }
Derek Tan7226c842014-07-02 17:42:23 -07007015 }
7016
7017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007018 public String getLine1NumberForDisplay(int subId, String callingPackage,
7019 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007020 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007022 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007023 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007024 return null;
7025 }
Derek Tan97ebb422014-09-05 16:55:38 -07007026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 String iccId = getIccId(subId);
7030 if (iccId != null) {
7031 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7032 if (DBG_MERGE) {
7033 log("getLine1NumberForDisplay returning "
7034 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7035 }
7036 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7039 return null;
7040 } finally {
7041 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007042 }
Derek Tan7226c842014-07-02 17:42:23 -07007043 }
7044
7045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007046 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7047 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007049 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007050 return null;
7051 }
Derek Tan97ebb422014-09-05 16:55:38 -07007052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 String iccId = getIccId(subId);
7056 if (iccId != null) {
7057 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7058 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7059 }
7060 return null;
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007063 }
Derek Tan7226c842014-07-02 17:42:23 -07007064 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007065
7066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7068 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007069 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7070 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007072 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007073 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007074 return null;
7075 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007076
Jordan Liub49b04b2019-05-06 14:45:15 -07007077 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7078 // the process, where TelephonyManager was instantiated.
7079 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007080 final long identity = Binder.clearCallingIdentity();
7081 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 final TelephonyManager tele = TelephonyManager.from(context);
7084 final SubscriptionManager sub = SubscriptionManager.from(context);
7085
7086 // Figure out what subscribers are currently active
7087 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088
Jordan Liub49b04b2019-05-06 14:45:15 -07007089 // Only consider subs which match the current subId
7090 // This logic can be simplified. See b/131189269 for progress.
7091 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007092 activeSubscriberIds.add(tele.getSubscriberId(subId));
7093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094
7095 // First pass, find a number override for an active subscriber
7096 String mergeNumber = null;
7097 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7098 for (String key : prefs.keySet()) {
7099 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7100 final String subscriberId = (String) prefs.get(key);
7101 if (activeSubscriberIds.contains(subscriberId)) {
7102 final String iccId = key.substring(
7103 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7104 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7105 mergeNumber = (String) prefs.get(numberKey);
7106 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007107 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 + " for active subscriber " + subscriberId);
7109 }
7110 if (!TextUtils.isEmpty(mergeNumber)) {
7111 break;
7112 }
7113 }
7114 }
7115 }
7116
7117 // Shortcut when no active merged subscribers
7118 if (TextUtils.isEmpty(mergeNumber)) {
7119 return null;
7120 }
7121
7122 // Second pass, find all subscribers under that line override
7123 final ArraySet<String> result = new ArraySet<>();
7124 for (String key : prefs.keySet()) {
7125 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7126 final String number = (String) prefs.get(key);
7127 if (mergeNumber.equals(number)) {
7128 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7129 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7130 final String subscriberId = (String) prefs.get(subscriberKey);
7131 if (!TextUtils.isEmpty(subscriberId)) {
7132 result.add(subscriberId);
7133 }
7134 }
7135 }
7136 }
7137
7138 final String[] resultArray = result.toArray(new String[result.size()]);
7139 Arrays.sort(resultArray);
7140 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007141 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7143 }
7144 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007145 } finally {
7146 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007147 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007148 }
7149
7150 @Override
zoey chen38003472019-12-13 17:16:31 +08007151 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7152 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 final TelephonyManager telephonyManager = mApp.getSystemService(
7157 TelephonyManager.class);
7158 String subscriberId = telephonyManager.getSubscriberId(subId);
7159 if (subscriberId == null) {
7160 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007161 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007162 + subId);
7163 }
7164 return null;
7165 }
7166
7167 final SubscriptionInfo info = SubscriptionController.getInstance()
7168 .getSubscriptionInfo(subId);
7169 final ParcelUuid groupUuid = info.getGroupUuid();
7170 // If it doesn't belong to any group, return just subscriberId of itself.
7171 if (groupUuid == null) {
7172 return new String[]{subscriberId};
7173 }
7174
7175 // Get all subscriberIds from the group.
7176 final List<String> mergedSubscriberIds = new ArrayList<>();
7177 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007179 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007180 for (SubscriptionInfo subInfo : groupInfos) {
7181 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7182 if (subscriberId != null) {
7183 mergedSubscriberIds.add(subscriberId);
7184 }
7185 }
7186
7187 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190
7191 }
7192 }
7193
7194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007195 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007196 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007197 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 final Phone phone = getPhone(subId);
7202 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7203 } finally {
7204 Binder.restoreCallingIdentity(identity);
7205 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007206 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007207
7208 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007209 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007210 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7211 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007212 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7213 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 final Phone phone = getPhone(subId);
7218 if (phone == null) {
7219 return false;
7220 }
7221 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7222 cdmaNonRoamingList);
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007225 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007226 }
7227
7228 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007229 @Deprecated
7230 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7231 enforceModifyPermission();
7232
7233 int returnValue = 0;
7234 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007235 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007236 if(result.exception == null) {
7237 if (result.result != null) {
7238 byte[] responseData = (byte[])(result.result);
7239 if(responseData.length > oemResp.length) {
7240 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7241 responseData.length + "bytes. Buffer Size is " +
7242 oemResp.length + "bytes.");
7243 }
7244 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7245 returnValue = responseData.length;
7246 }
7247 } else {
7248 CommandException ex = (CommandException) result.exception;
7249 returnValue = ex.getCommandError().ordinal();
7250 if(returnValue > 0) returnValue *= -1;
7251 }
7252 } catch (RuntimeException e) {
7253 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7254 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7255 if(returnValue > 0) returnValue *= -1;
7256 }
7257
7258 return returnValue;
7259 }
7260
7261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007262 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007263 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007264 try {
7265 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007266 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007267 mApp, phone.getSubId(), "getRadioAccessFamily");
7268 } catch (SecurityException e) {
7269 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7270 throw e;
7271 }
chen xub97461a2018-10-26 14:17:57 -07007272 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007273 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007274 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276 final long identity = Binder.clearCallingIdentity();
7277 try {
chen xub97461a2018-10-26 14:17:57 -07007278 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007279 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007280 mApp, phone.getSubId(), "getRadioAccessFamily");
7281 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
chen xub97461a2018-10-26 14:17:57 -07007285 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007286 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007287
7288 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007289 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007290 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007291 try {
7292 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7293 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007294 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007295 }
7296 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007297 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007298 }
7299 RoleManager rm = mApp.getSystemService(RoleManager.class);
7300 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7301 if (!dialerRoleHolders.contains(callingPackage)) {
7302 throw new SecurityException("App must be the dialer role holder to"
7303 + " upload a call composer pic");
7304 }
7305
7306 Executors.newSingleThreadExecutor().execute(() -> {
7307 ByteArrayOutputStream output = new ByteArrayOutputStream(
7308 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7309 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7310 boolean readUntilEnd = false;
7311 int totalBytesRead = 0;
7312 byte[] buffer = new byte[16 * 1024];
7313 while (true) {
7314 int numRead;
7315 try {
7316 numRead = input.read(buffer);
7317 } catch (IOException e) {
7318 try {
7319 fd.checkError();
7320 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7321 null);
7322 } catch (IOException e1) {
7323 // This means that the other side closed explicitly with an error. If this
7324 // happens, log and ignore.
7325 loge("Remote end of call composer picture pipe closed: " + e1);
7326 }
7327 break;
7328 }
7329 if (numRead == -1) {
7330 readUntilEnd = true;
7331 break;
7332 }
7333 totalBytesRead += numRead;
7334 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7335 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7336 try {
7337 input.close();
7338 } catch (IOException e) {
7339 // ignore
7340 }
7341 break;
7342 }
7343 output.write(buffer, 0, numRead);
7344 }
7345 // Generally, the remote end will close the file descriptors. The only case where we
7346 // close is above, where the picture size is too big.
7347
7348 try {
7349 fd.checkError();
7350 } catch (IOException e) {
7351 loge("Remote end for call composer closed with an error: " + e);
7352 return;
7353 }
7354
Hall Liuaa4211e2021-01-20 15:43:39 -08007355 if (!readUntilEnd) {
7356 loge("Did not finish reading entire image; aborting");
7357 return;
7358 }
Hall Liu82694d52020-12-11 18:22:04 -08007359
Hall Liuaa4211e2021-01-20 15:43:39 -08007360 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7361 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7362 new CallComposerPictureTransfer.Factory() {},
7363 imageData,
7364 (result) -> {
7365 if (result.first != null) {
7366 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7367 Bundle outputResult = new Bundle();
7368 outputResult.putParcelable(
7369 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7370 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7371 outputResult);
7372 } else {
7373 callback.send(result.second, null);
7374 }
7375 }
7376 );
Hall Liu82694d52020-12-11 18:22:04 -08007377 });
7378 }
7379
7380 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007381 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007382 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007383 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007387 ImsManager.getInstance(defaultPhone.getContext(),
7388 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007392 }
7393
7394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007395 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007396 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7398 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007399 return false;
7400 }
Svet Ganovb320e182015-04-16 12:30:10 -07007401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 final long identity = Binder.clearCallingIdentity();
7403 try {
7404 // Check the user preference and the system-level IMS setting. Even if the user has
7405 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7406 // In the long run, we may instead need to check if there exists a connection service
7407 // which can support video calling.
7408 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007409 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 return imsManager.isVtEnabledByPlatform()
7411 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7412 && imsManager.isVtEnabledByUser();
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007416 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007417
Andrew Leea1239f22015-03-02 17:44:07 -08007418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007419 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7420 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007422 mApp, subId, callingPackage, callingFeatureId,
7423 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 return false;
7425 }
7426
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
7429 CarrierConfigManager configManager =
7430 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7433 } finally {
7434 Binder.restoreCallingIdentity(identity);
7435 }
Andrew Leea1239f22015-03-02 17:44:07 -08007436 }
7437
7438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007441 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 return false;
7443 }
7444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 CarrierConfigManager configManager =
7448 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
Andrew Leea1239f22015-03-02 17:44:07 -08007454 }
7455
Andrew Lee9431b832015-03-09 18:46:45 -07007456 @Override
7457 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007458 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007459 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007460 }
7461
7462 @Override
7463 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 final long identity = Binder.clearCallingIdentity();
7465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007466 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Andrew Lee9431b832015-03-09 18:46:45 -07007470 }
7471
Hall Liuf6668912018-10-31 17:05:23 -07007472 /**
7473 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7474 * support for the feature and device firmware support.
7475 *
7476 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7477 */
7478 @Override
7479 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007481 final Phone phone = getPhone(subscriptionId);
7482 if (phone == null) {
7483 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7484 return false;
7485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7489 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 return isCarrierSupported && isDeviceSupported;
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Hall Liu98187582018-01-22 19:15:32 -08007495 }
7496
Hall Liuf6668912018-10-31 17:05:23 -07007497 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007498 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7499 * RTT setting, will return true if the device and carrier both support RTT.
7500 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007501 */
7502 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007505 boolean isRttSupported = isRttSupported(subscriptionId);
7506 boolean isUserRttSettingOn = Settings.Secure.getInt(
7507 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7508 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7509 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7510 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 } finally {
7512 Binder.restoreCallingIdentity(identity);
7513 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007514 }
7515
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 @Deprecated
7517 @Override
7518 public String getDeviceId(String callingPackage) {
7519 return getDeviceIdWithFeature(callingPackage, null);
7520 }
7521
Sanket Padawe7310cc72015-01-14 09:53:20 -08007522 /**
7523 * Returns the unique device ID of phone, for example, the IMEI for
7524 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7525 *
7526 * <p>Requires Permission:
7527 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7528 */
7529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007531 try {
7532 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7533 } catch (SecurityException se) {
7534 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7535 throw new SecurityException("Package " + callingPackage + " does not belong to "
7536 + Binder.getCallingUid());
7537 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007538 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007539 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007540 return null;
7541 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007542 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007543 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007544 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007545 return null;
7546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547
7548 final long identity = Binder.clearCallingIdentity();
7549 try {
7550 return phone.getDeviceId();
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007554 }
7555
Ping Sunc67b7c22016-03-02 19:16:45 +08007556 /**
7557 * {@hide}
7558 * Returns the IMS Registration Status on a particular subid
7559 *
7560 * @param subId
7561 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007562 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007563 Phone phone = getPhone(subId);
7564 if (phone != null) {
7565 return phone.isImsRegistered();
7566 } else {
7567 return false;
7568 }
7569 }
7570
Santos Cordon7a1885b2015-02-03 11:15:19 -08007571 @Override
7572 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 final long identity = Binder.clearCallingIdentity();
7574 try {
7575 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007579 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007580
Tyler Gunnf70ed162019-04-03 15:28:53 -07007581 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007582 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007583 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007585 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007586 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7587 }
7588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
7594 }
7595
7596 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007597 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007598 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007599 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007600 mApp,
7601 subscriptionId,
7602 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 Phone phone = getPhone(subscriptionId);
7606 if (phone == null) {
7607 return null;
7608 }
7609 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
7613 }
7614
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007615 /**
7616 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007617 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007618 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 final long identity = Binder.clearCallingIdentity();
7620 try {
7621 Phone phone = getPhone(subId);
7622 if (phone != null) {
7623 return phone.isWifiCallingEnabled();
7624 } else {
7625 return false;
7626 }
7627 } finally {
7628 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007629 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007630 }
7631
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007632 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007633 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007634 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007635 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 Phone phone = getPhone(subId);
7639 if (phone != null) {
7640 return phone.isVideoEnabled();
7641 } else {
7642 return false;
7643 }
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007646 }
7647 }
7648
7649 /**
7650 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7651 * defined in {@link ImsRegistrationImplBase}.
7652 */
7653 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 final long identity = Binder.clearCallingIdentity();
7655 try {
7656 Phone phone = getPhone(subId);
7657 if (phone != null) {
7658 return phone.getImsRegistrationTech();
7659 } else {
7660 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7661 }
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007664 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007665 }
7666
Stuart Scott8eef64f2015-04-08 15:13:54 -07007667 @Override
7668 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007669 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007670 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7671 return;
7672 }
Kai Shif70f46f2021-03-03 13:59:46 -08007673 Phone defaultPhone = getDefaultPhone();
7674 if (defaultPhone != null) {
7675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7676 mApp, getDefaultPhone().getSubId(), "factoryReset");
7677 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007678 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679
Svet Ganovcc087f82015-05-12 20:35:54 -07007680 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007681 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7682 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007683 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007684 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007685 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007686 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007687 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007688 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007689 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007690 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007691 // There has been issues when Sms raw table somehow stores orphan
7692 // fragments. They lead to garbled message when new fragments come
7693 // in and combined with those stale ones. In case this happens again,
7694 // user can reset all network settings which will clean up this table.
7695 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007696 // Clean up IMS settings as well here.
7697 int slotId = getSlotIndex(subId);
7698 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7699 ImsManager.getInstance(mApp, slotId).factoryReset();
7700 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007701
Kai Shif70f46f2021-03-03 13:59:46 -08007702 if (defaultPhone == null) {
7703 return;
7704 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007705 // Erase modem config if erase modem on network setting is enabled.
7706 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7707 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7708 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007709 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007710 }
Kai Shif70f46f2021-03-03 13:59:46 -08007711
7712 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007713 } finally {
7714 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007715 }
7716 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007717
SongFerngWangfd89b102021-05-27 22:44:54 +08007718 @VisibleForTesting
7719 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7720 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7721 return;
7722 }
7723 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7724 RILConstants.PREFERRED_NETWORK_MODE);
7725 SubscriptionManager.setSubscriptionProperty(subId,
7726 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7727 "user=" + defaultNetworkType);
7728 phone.loadAllowedNetworksFromSubscriptionDatabase();
7729 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7730 defaultNetworkType, null);
7731 }
7732
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007733 private void cleanUpSmsRawTable(Context context) {
7734 ContentResolver resolver = context.getContentResolver();
7735 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7736 resolver.delete(uri, null, null);
7737 }
7738
Narayan Kamath1c496c22015-04-16 14:40:19 +01007739 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007740 public String getSimLocaleForSubscriber(int subId) {
7741 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7742 final Phone phone = getPhone(subId);
7743 if (phone == null) {
7744 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007745 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 final long identity = Binder.clearCallingIdentity();
7748 try {
chen xu5d3637b2019-01-21 23:31:38 -08007749 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007750 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007751 if (info == null) {
7752 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7753 return null;
7754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 // Try and fetch the locale from the carrier properties or from the SIM language
7756 // preferences (EF-PL and EF-LI)...
7757 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007759 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7760 if (localeFromDefaultSim != null) {
7761 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7762 if (DBG) log("Using locale from subId: " + subId + " locale: "
7763 + localeFromDefaultSim);
7764 return localeFromDefaultSim.toLanguageTag();
7765 } else {
7766 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007767 }
7768 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 // The SIM language preferences only store a language (e.g. fr = French), not an
7771 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7772 // the SIM and carrier preferences does not include a country we add the country
7773 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007774 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007776 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 return mccLocale.toLanguageTag();
7778 }
7779
7780 if (DBG) log("No locale found - returning null");
7781 return null;
7782 } finally {
7783 Binder.restoreCallingIdentity(identity);
7784 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007785 }
7786
7787 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007788 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007789 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007790 }
7791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 /**
7793 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7794 */
7795 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007796 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007797 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007798 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007799
Chenjie Yu1ba97252018-01-11 18:16:20 -08007800 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007801 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007802
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007803 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007804 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7805 * representing the state of the modem.
7806 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007807 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7808 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007809 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007810 */
7811 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007812 public void requestModemActivityInfo(ResultReceiver result) {
7813 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815
7816 final long identity = Binder.clearCallingIdentity();
7817 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007818 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 } finally {
7820 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007821 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007822 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007823
Siddharth Rayb8114062018-06-17 15:02:38 -07007824 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7825 // less than total activity duration.
7826 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7827 if (info == null) {
7828 return false;
7829 }
7830 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007831 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7832 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7833
Siddharth Rayb8114062018-06-17 15:02:38 -07007834 return (info.isValid()
7835 && (info.getSleepTimeMillis() <= activityDurationMs)
7836 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007837 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007838 && (totalTxTimeMs <= activityDurationMs));
7839 }
7840
Jack Yu85bd38a2015-11-09 11:34:32 -08007841 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007842 * Returns the service state information on specified subscription.
7843 */
7844 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007845 public ServiceState getServiceStateForSubscriber(int subId,
7846 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7847 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007849 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007850 return null;
7851 }
7852
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007853 boolean hasFinePermission = false;
7854 boolean hasCoarsePermission = false;
7855 if (!renounceFineLocationAccess) {
7856 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7857 LocationAccessPolicy.checkLocationPermission(mApp,
7858 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7859 .setCallingPackage(callingPackage)
7860 .setCallingFeatureId(callingFeatureId)
7861 .setCallingPid(Binder.getCallingPid())
7862 .setCallingUid(Binder.getCallingUid())
7863 .setMethod("getServiceStateForSubscriber")
7864 .setLogAsInfo(true)
7865 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7866 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7867 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7868 .build());
7869 hasFinePermission =
7870 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7871 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007872
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007873 if (!renounceCoarseLocationAccess) {
7874 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7875 LocationAccessPolicy.checkLocationPermission(mApp,
7876 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7877 .setCallingPackage(callingPackage)
7878 .setCallingFeatureId(callingFeatureId)
7879 .setCallingPid(Binder.getCallingPid())
7880 .setCallingUid(Binder.getCallingUid())
7881 .setMethod("getServiceStateForSubscriber")
7882 .setLogAsInfo(true)
7883 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7884 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7885 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7886 .build());
7887 hasCoarsePermission =
7888 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7889 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007890
Jack Yu479f40e2020-10-27 21:29:25 -07007891 final Phone phone = getPhone(subId);
7892 if (phone == null) {
7893 return null;
7894 }
7895
Jordan Liu0f2bc442020-11-18 16:47:37 -08007896 final long identity = Binder.clearCallingIdentity();
7897
Jack Yu479f40e2020-10-27 21:29:25 -07007898 boolean isCallingPackageDataService = phone.getDataServicePackages()
7899 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007901 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7902 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7903 Rlog.d(LOG_TAG,
7904 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7905 return null;
7906 }
7907
Hall Liuf19c44f2018-11-27 14:38:17 -08007908 ServiceState ss = phone.getServiceState();
7909
7910 // Scrub out the location info in ServiceState depending on what level of access
7911 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007912 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007913 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7914 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007918 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007919
7920 /**
7921 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7922 *
7923 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7924 * voicemail ringtone.
7925 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7926 * PhoneAccount.
7927 */
7928 @Override
7929 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 final long identity = Binder.clearCallingIdentity();
7931 try {
7932 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7933 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007941 }
7942
7943 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007944 * Sets the per-account voicemail ringtone.
7945 *
7946 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7947 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7948 *
7949 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7950 * voicemail ringtone.
7951 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7952 * PhoneAccount.
7953 */
7954 @Override
7955 public void setVoicemailRingtoneUri(String callingPackage,
7956 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007957 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007958 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007959 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7960 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7962 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7963 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965
7966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7969 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007970 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 }
7972 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7973 } finally {
7974 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007975 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 }
7977
7978 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979 * Returns whether vibration is set for voicemail notification in Phone settings.
7980 *
7981 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7982 * voicemail vibration setting.
7983 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7984 */
7985 @Override
7986 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7990 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007998 }
7999
Youhan Wange64578a2016-05-02 15:32:42 -07008000 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 * Sets the per-account voicemail vibration.
8002 *
8003 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8004 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8005 *
8006 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8007 * voicemail vibration setting.
8008 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8009 * specific PhoneAccount.
8010 */
8011 @Override
8012 public void setVoicemailVibrationEnabled(String callingPackage,
8013 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008014 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008016 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8017 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8019 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8020 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008021 }
8022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8026 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008027 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 }
8029 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8030 } finally {
8031 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008032 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 }
8034
8035 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008036 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8037 *
8038 * @throws SecurityException if the caller does not have the required permission
8039 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008040 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008041 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008042 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008043 }
8044
8045 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008046 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8047 * permission.
8048 *
8049 * @throws SecurityException if the caller does not have the required permission
8050 */
8051 private void enforceSendSmsPermission() {
8052 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8053 }
8054
8055 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008056 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008057 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008058 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008059 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008060 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008064 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 if (componentName == null) {
8066 throw new SecurityException(
8067 "Caller not current active visual voicemail package[null]");
8068 }
8069 String vvmPackage = componentName.getPackageName();
8070 if (!callingPackage.equals(vvmPackage)) {
8071 throw new SecurityException("Caller not current active visual voicemail package["
8072 + vvmPackage + "]");
8073 }
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008076 }
8077 }
8078
8079 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008080 * Return the application ID for the app type.
8081 *
8082 * @param subId the subscription ID that this request applies to.
8083 * @param appType the uicc app type.
8084 * @return Application ID for specificied app type, or null if no uicc.
8085 */
8086 @Override
8087 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008088 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008089 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090
8091 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008092 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 if (phone == null) {
8094 return null;
8095 }
8096 String aid = null;
8097 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008098 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 .getApplicationByType(appType).getAid();
8100 } catch (Exception e) {
8101 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8102 }
8103 return aid;
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008106 }
Youhan Wange64578a2016-05-02 15:32:42 -07008107 }
8108
Youhan Wang4001d252016-05-11 10:29:41 -07008109 /**
8110 * Return the Electronic Serial Number.
8111 *
8112 * @param subId the subscription ID that this request applies to.
8113 * @return ESN or null if error.
8114 */
8115 @Override
8116 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008117 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008118 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119
8120 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008121 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122 if (phone == null) {
8123 return null;
8124 }
8125 String esn = null;
8126 try {
8127 esn = phone.getEsn();
8128 } catch (Exception e) {
8129 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8130 }
8131 return esn;
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008134 }
Youhan Wang4001d252016-05-11 10:29:41 -07008135 }
8136
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008137 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008138 * Return the Preferred Roaming List Version.
8139 *
8140 * @param subId the subscription ID that this request applies to.
8141 * @return PRLVersion or null if error.
8142 */
8143 @Override
8144 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008145 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008146 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147
8148 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008149 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 if (phone == null) {
8151 return null;
8152 }
8153 String cdmaPrlVersion = null;
8154 try {
8155 cdmaPrlVersion = phone.getCdmaPrlVersion();
8156 } catch (Exception e) {
8157 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8158 }
8159 return cdmaPrlVersion;
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008162 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008163 }
8164
8165 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008166 * Get snapshot of Telephony histograms
8167 * @return List of Telephony histograms
8168 * @hide
8169 */
8170 @Override
8171 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8173 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174
8175 final long identity = Binder.clearCallingIdentity();
8176 try {
8177 return RIL.getTelephonyRILTimingHistograms();
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
8180 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008181 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008182
8183 /**
8184 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008185 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8186 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008187 * Require system privileges. In the future we may add this to carrier APIs.
8188 *
Michele Berionne482f8202018-11-27 18:57:59 -08008189 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008190 */
8191 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008192 @TelephonyManager.SetCarrierRestrictionResult
8193 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008194 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008196
Michele Berionne482f8202018-11-27 18:57:59 -08008197 if (carrierRestrictionRules == null) {
8198 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008199 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 final long identity = Binder.clearCallingIdentity();
8202 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008203 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008204 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208 }
8209
8210 /**
8211 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008212 * Get the allowed carrier list and the excluded carrier list, including the priority between
8213 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008214 * Require system privileges. In the future we may add this to carrier APIs.
8215 *
Michele Berionne482f8202018-11-27 18:57:59 -08008216 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008217 */
8218 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008219 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008220 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008221 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222
8223 final long identity = Binder.clearCallingIdentity();
8224 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008225 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8226 if (response instanceof CarrierRestrictionRules) {
8227 return (CarrierRestrictionRules) response;
8228 }
8229 // Response is an Exception of some kind,
8230 // which is signalled to the user as a NULL retval
8231 return null;
8232 } catch (Exception e) {
8233 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8234 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 } finally {
8236 Binder.restoreCallingIdentity(identity);
8237 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008238 }
8239
fionaxu59545b42016-05-25 15:53:37 -07008240 /**
fionaxu59545b42016-05-25 15:53:37 -07008241 * Action set from carrier signalling broadcast receivers to enable/disable radio
8242 * @param subId the subscription ID that this action applies to.
8243 * @param enabled control enable or disable radio.
8244 * {@hide}
8245 */
8246 @Override
8247 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8248 enforceModifyPermission();
8249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250
8251 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008252 if (phone == null) {
8253 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8254 return;
8255 }
8256 try {
8257 phone.carrierActionSetRadioEnabled(enabled);
8258 } catch (Exception e) {
8259 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 } finally {
8261 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008262 }
8263 }
8264
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008265 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008266 * Enable or disable Voice over NR (VoNR)
8267 * @param subId the subscription ID that this action applies to.
8268 * @param enabled enable or disable VoNR.
8269 * @return operation result.
8270 */
8271 @Override
8272 public int setVoNrEnabled(int subId, boolean enabled) {
8273 enforceModifyPermission();
8274 final Phone phone = getPhone(subId);
8275
8276 final long identity = Binder.clearCallingIdentity();
8277 if (phone == null) {
8278 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8279 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8280 }
8281
8282 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8283 try {
8284 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8285 workSource);
8286 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008287
8288 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8289 if (DBG) {
8290 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8291 }
8292 SubscriptionManager.setSubscriptionProperty(
8293 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8294 (enabled ? "1" : "0"));
8295 }
8296
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008297 return result;
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
8301 }
8302
8303 /**
8304 * Is voice over NR enabled
8305 * @return true if VoNR is enabled else false
8306 */
8307 @Override
8308 public boolean isVoNrEnabled(int subId) {
8309 enforceReadPrivilegedPermission("isVoNrEnabled");
8310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8314 null, subId, workSource);
8315 if (DBG) log("isVoNrEnabled: " + isEnabled);
8316 return isEnabled;
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
8321
8322 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008323 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8324 * network status based on which carrier apps could apply actions accordingly,
8325 * enable/disable default url handler for example.
8326 *
8327 * @param subId the subscription ID that this action applies to.
8328 * @param report control start/stop reporting the default network status.
8329 * {@hide}
8330 */
8331 @Override
8332 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8333 enforceModifyPermission();
8334 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335
8336 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008337 if (phone == null) {
8338 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8339 return;
8340 }
8341 try {
8342 phone.carrierActionReportDefaultNetworkStatus(report);
8343 } catch (Exception e) {
8344 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 } finally {
8346 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008347 }
8348 }
8349
8350 /**
fionaxud9622282017-07-17 17:51:30 -07008351 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8352 * @param subId the subscription ID that this action applies to.
8353 * {@hide}
8354 */
8355 @Override
8356 public void carrierActionResetAll(int subId) {
8357 enforceModifyPermission();
8358 final Phone phone = getPhone(subId);
8359 if (phone == null) {
8360 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8361 return;
8362 }
8363 try {
8364 phone.carrierActionResetAll();
8365 } catch (Exception e) {
8366 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8367 }
8368 }
8369
8370 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008371 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8372 * bug report is being generated.
8373 */
8374 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008375 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008376 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8377 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008378 writer.println("Permission Denial: can't dump Phone from pid="
8379 + Binder.getCallingPid()
8380 + ", uid=" + Binder.getCallingUid()
8381 + "without permission "
8382 + android.Manifest.permission.DUMP);
8383 return;
8384 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008386 }
Jack Yueb89b242016-06-22 13:27:47 -07008387
Brad Ebingerdac2f002018-04-03 15:17:52 -07008388 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008389 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8390 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8391 @NonNull String[] args) {
8392 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8393 this, in.getFileDescriptor(), out.getFileDescriptor(),
8394 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008395 }
8396
Jack Yueb89b242016-06-22 13:27:47 -07008397 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008398 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008399 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008400 * @param reason the reason the data enable change is taking place
8401 * @param enabled True if enabling the data, otherwise disabling.
8402 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008403 */
8404 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008405 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008406 boolean enabled) {
8407 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8408 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8409 try {
8410 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008411 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008412 } catch (SecurityException se) {
8413 enforceModifyPermission();
8414 }
8415 } else {
8416 enforceModifyPermission();
8417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008418
8419 final long identity = Binder.clearCallingIdentity();
8420 try {
8421 Phone phone = getPhone(subId);
8422 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008423 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8424 phone.carrierActionSetMeteredApnsEnabled(enabled);
8425 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008426 if (phone.isUsingNewDataStack()) {
8427 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8428 } else {
8429 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8430 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 }
8433 } finally {
8434 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008435 }
8436 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008437
8438 /**
8439 * Get Client request stats
8440 * @return List of Client Request Stats
8441 * @hide
8442 */
8443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008444 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8445 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008447 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008448 return null;
8449 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008450 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 if (phone != null) {
8455 return phone.getClientRequestStats();
8456 }
8457
8458 return null;
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
8461 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008462 }
8463
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008464 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008465 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008466 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008467 }
Jack Yueb4124c2017-02-16 15:32:43 -08008468
8469 /**
Grace Chen70990072017-03-24 17:21:30 -07008470 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008471 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008472 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008473 * @param state State of SIM (power down, power up, pass through)
8474 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8475 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008477 *
8478 **/
8479 @Override
Grace Chen70990072017-03-24 17:21:30 -07008480 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008481 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008482 Phone phone = PhoneFactory.getPhone(slotIndex);
8483
vagdeviaf9a5b92018-08-15 16:01:53 -07008484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008489 phone.setSimPowerState(state, null, workSource);
8490 }
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
8496 /**
8497 * Set SIM card power state.
8498 *
8499 * @param slotIndex SIM slot id.
8500 * @param state State of SIM (power down, power up, pass through)
8501 * @param callback callback to trigger after success or failure
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8503 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8504 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8505 *
8506 **/
8507 @Override
8508 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8509 IIntegerConsumer callback) {
8510 enforceModifyPermission();
8511 Phone phone = PhoneFactory.getPhone(slotIndex);
8512
8513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8514
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 if (phone != null) {
8518 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8519 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 }
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008523 }
8524 }
Shuo Qiandd210312017-04-12 22:11:33 +00008525
Tyler Gunn65d45c22017-06-05 11:22:26 -07008526 private boolean isUssdApiAllowed(int subId) {
8527 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008528 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008529 if (configManager == null) {
8530 return false;
8531 }
8532 PersistableBundle pb = configManager.getConfigForSubId(subId);
8533 if (pb == null) {
8534 return false;
8535 }
8536 return pb.getBoolean(
8537 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8538 }
8539
Shuo Qiandd210312017-04-12 22:11:33 +00008540 /**
8541 * Check if phone is in emergency callback mode
8542 * @return true if phone is in emergency callback mode
8543 * @param subId sub id
8544 */
goneil9c5f4872017-12-05 14:07:56 -08008545 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008546 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008547 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008549
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
8552 if (phone != null) {
8553 return phone.isInEcm();
8554 } else {
8555 return false;
8556 }
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008559 }
8560 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008561
8562 /**
8563 * Get the current signal strength information for the given subscription.
8564 * Because this information is not updated when the device is in a low power state
8565 * it should not be relied-upon to be current.
8566 * @param subId Subscription index
8567 * @return the most recent cached signal strength info from the modem
8568 */
8569 @Override
8570 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 Phone p = getPhone(subId);
8574 if (p == null) {
8575 return null;
8576 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 return p.getSignalStrength();
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008582 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008583
Pengquan Meng77b7f132018-08-22 14:49:57 -07008584 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008585 * Get the current modem radio state for the given slot.
8586 * @param slotIndex slot index.
8587 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008588 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008589 * @return the current radio power state from the modem
8590 */
8591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008592 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008593 Phone phone = PhoneFactory.getPhone(slotIndex);
8594 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8596 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008597 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8598 }
8599
8600 final long identity = Binder.clearCallingIdentity();
8601 try {
8602 return phone.getRadioPowerState();
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
8606 }
8607 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8608 }
8609
8610 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008611 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8612 *
8613 * <p>Requires one of the following permissions:
8614 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008615 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008616 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8617 * privileges.
8618 *
8619 * @param subId subscription id
8620 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8621 * {@code false}.
8622 */
8623 @Override
8624 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008625 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008626 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008627 try {
8628 mApp.enforceCallingOrSelfPermission(
8629 android.Manifest.permission.ACCESS_NETWORK_STATE,
8630 functionName);
8631 } catch (Exception e) {
8632 mApp.enforceCallingOrSelfPermission(
8633 permission.READ_BASIC_PHONE_STATE, functionName);
8634 }
Shuo Qian093013d2020-08-13 15:42:55 -07008635 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008636 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008637 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008638 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008639
Pengquan Menga1bb6272018-09-06 09:59:22 -07008640 boolean isEnabled = false;
8641 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008642 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008643 Phone phone = getPhone(subId);
8644 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008645 } finally {
8646 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008648 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008649 }
8650
8651
8652 /**
8653 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8654 *
8655 * <p> Requires permission:
8656 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8657 * privileges.
8658 *
8659 * @param subId subscription id
8660 * @param isEnabled {@code true} means enable, {@code false} means disable.
8661 */
8662 @Override
8663 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8665 mApp, subId, "setDataRoamingEnabled");
8666
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 final long identity = Binder.clearCallingIdentity();
8668 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008669 Phone phone = getPhone(subId);
8670 if (phone != null) {
8671 phone.setDataRoamingEnabled(isEnabled);
8672 }
8673 } finally {
8674 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008675 }
8676 }
8677
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008678 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008679 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008680 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008681 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008682 mApp, subId, "isManualNetworkSelectionAllowed");
8683
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008684 boolean isAllowed = true;
8685 final long identity = Binder.clearCallingIdentity();
8686 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008687 Phone phone = getPhone(subId);
8688 if (phone != null) {
8689 isAllowed = phone.isCspPlmnEnabled();
8690 }
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
8694 return isAllowed;
8695 }
8696
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008697 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8698 UiccProfile profile = port.getUiccProfile();
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008699 if (profile == null) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008700 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008701 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008702 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8703 if (phone == null) {
8704 return false;
8705 }
8706 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8707 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8708 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008709 }
8710
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008711 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008712 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008713 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008714 mApp.getSystemService(AppOpsManager.class)
8715 .checkPackage(Binder.getCallingUid(), callingPackage);
8716
Jordan Liu1e142fc2019-04-22 15:10:43 -07008717 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008718 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008719 try {
8720 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008722 } catch (SecurityException e) {
8723 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8724 // has carrier privileges on an active UICC
8725 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8726 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008727 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008728 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008729 }
sandeepjs0a502c42021-09-27 15:34:44 +00008730 // checking compatibility, if calling app's target SDK is T and beyond.
8731 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8732 Binder.getCallingUid())) {
8733 isIccIdAccessRestricted = true;
8734 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008735 final long identity = Binder.clearCallingIdentity();
8736 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008737 UiccController uiccController = UiccController.getInstance();
8738 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008739 if (hasReadPermission) {
8740 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008741 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008742
8743 // Remove private info if the caller doesn't have access
8744 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8745 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008746 //setting the value after compatibility check
8747 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8749 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008750 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008751 if (card == null) {
8752 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008753 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 continue;
8755 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008756 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8757 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008758 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008759 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008760 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008761 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8762 for (UiccPortInfo portInfo : portInfos) {
8763 UiccPort port = uiccController.getUiccPortForSlot(
8764 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8765 if (port == null) {
8766 // assume no access if port is null
8767 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8768 continue;
8769 }
8770 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8771 uiccPortInfos.add(portInfo);
8772 } else {
8773 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8774 }
8775 }
8776 filteredInfos.add(new UiccCardInfo(
8777 cardInfo.isEuicc(),
8778 cardInfo.getCardId(),
8779 null,
8780 cardInfo.getPhysicalSlotIndex(),
8781 cardInfo.isRemovable(),
8782 cardInfo.isMultipleEnabledProfilesSupported(),
8783 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008784 }
8785 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008786 } finally {
8787 Binder.restoreCallingIdentity(identity);
8788 }
8789 }
8790
sandeepjs0a502c42021-09-27 15:34:44 +00008791 /**
8792 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8793 * generally private and require carrier privileges to view.
8794 *
8795 * @hide
8796 */
8797 @NonNull
8798 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8799 List<UiccPortInfo> portinfo = new ArrayList<>();
8800 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8801 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8802 }
8803 return new UiccCardInfo(
8804 cardInfo.isEuicc(),
8805 cardInfo.getCardId(),
8806 null,
8807 cardInfo.getPhysicalSlotIndex(),
8808 cardInfo.isRemovable(),
8809 cardInfo.isMultipleEnabledProfilesSupported(),
8810 portinfo
8811 );
8812 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008813
sandeepjs0a502c42021-09-27 15:34:44 +00008814 /**
8815 * @hide
8816 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8817 * These values are generally private and require carrier privileges to view.
8818 */
8819 @NonNull
8820 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8821 return new UiccPortInfo(
8822 UiccPortInfo.ICCID_REDACTED,
8823 portInfo.getPortIndex(),
8824 portInfo.getLogicalSlotIndex(),
8825 portInfo.isActive()
8826 );
8827 }
8828 @Override
8829 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008830 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008831 mApp.getSystemService(AppOpsManager.class)
8832 .checkPackage(Binder.getCallingUid(), callingPackage);
8833
8834 boolean hasReadPermission = false;
8835 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008836
8837 try {
8838 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8839 hasReadPermission = true;
8840 } catch (SecurityException e) {
8841 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8842 // has carrier privileges on an active UICC
8843 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8844 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8845 hasReadPermission = true;
8846 }
8847 }
8848
8849 // checking compatibility, if calling app's target SDK is T and beyond.
8850 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8851 Binder.getCallingUid())) {
8852 isLogicalSlotAccessRestricted = true;
8853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8857 if (slots == null) {
8858 Rlog.i(LOG_TAG, "slots is null.");
8859 return null;
8860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8862 for (int i = 0; i < slots.length; i++) {
8863 UiccSlot slot = slots[i];
8864 if (slot == null) {
8865 continue;
8866 }
8867
Jordan Liu7be7e652019-05-06 18:55:02 +00008868 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008869 UiccCard card = slot.getUiccCard();
8870 if (card != null) {
8871 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008872 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008873 cardId = slot.getEid();
8874 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008875 // If cardId is null, use iccId of default port as cardId. Check if has
8876 // read permission otherwise set to null.(card is null which means no
8877 // carrier permission)
8878 cardId = hasReadPermission ? slot.getIccId(
8879 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 }
8882
Jordan Liu857451f2019-05-09 16:35:35 -07008883 if (cardId != null) {
8884 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8885 // if cardId is an EID, it's all digits so this is fine
8886 cardId = IccUtils.stripTrailingFs(cardId);
8887 }
8888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 int cardState = 0;
8890 switch (slot.getCardState()) {
8891 case CARDSTATE_ABSENT:
8892 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8893 break;
8894 case CARDSTATE_PRESENT:
8895 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8896 break;
8897 case CARDSTATE_ERROR:
8898 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8899 break;
8900 case CARDSTATE_RESTRICTED:
8901 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8902 break;
8903 default:
8904 break;
8905
8906 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008907 List<UiccPortInfo> portInfos = new ArrayList<>();
8908 int[] portIndexes = slot.getPortList();
8909 for (int portIdx : portIndexes) {
8910 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8911 callingPackage, hasReadPermission));
8912 if (slot.isPortActive(portIdx)) {
8913 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8914 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8915 port.getPhoneId(), true));
8916 } else {
8917 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8918 }
8919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921 slot.isEuicc(),
8922 cardId,
8923 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008924 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008925 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008926 //setting the value after compatibility check
8927 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008928 }
8929 return infos;
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008932 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008933 }
8934
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008935 /* Returns null if doesn't have read permission or carrier privilege access. */
8936 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8937 boolean hasReadPermission) {
8938 String iccId = slot.getIccId(portIndex);
8939 if (hasReadPermission) { // if has read permission
8940 return iccId;
8941 } else {
8942 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8943 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8944 // if no read permission, checking carrier privilege access
8945 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8946 return iccId;
8947 }
8948 }
8949 }
8950 // No read permission or carrier privilege access.
8951 return UiccPortInfo.ICCID_REDACTED;
8952 }
8953
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008954 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008955 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008956 public boolean switchSlots(int[] physicalSlots) {
8957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958
8959 final long identity = Binder.clearCallingIdentity();
8960 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008961 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8962 for (int i = 0; i < physicalSlots.length; i++) {
8963 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8964 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8965 physicalSlots[i], i));
8966 }
8967 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968 } finally {
8969 Binder.restoreCallingIdentity(identity);
8970 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008971 }
Jack Yu4c988042018-02-27 15:30:01 -08008972
8973 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008974 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8975 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8976 enforceModifyPermission();
8977
8978 final long identity = Binder.clearCallingIdentity();
8979 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008980 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
8986 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008987 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 return UiccController.getInstance().getCardIdForDefaultEuicc();
8991 } finally {
8992 Binder.restoreCallingIdentity(identity);
8993 }
8994 }
8995
Pengquan Meng85728fb2018-03-12 16:31:21 -07008996 /**
goneil47ffb6e2018-04-06 15:40:58 -07008997 * A test API to reload the UICC profile.
8998 *
8999 * <p>Requires that the calling app has permission
9000 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9001 * @hide
9002 */
9003 @Override
9004 public void refreshUiccProfile(int subId) {
9005 enforceModifyPermission();
9006
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 Phone phone = getPhone(subId);
9010 if (phone == null) {
9011 return;
9012 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009013 UiccPort uiccPort = phone.getUiccPort();
9014 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009015 return;
9016 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009017 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009018 if (uiccProfile == null) {
9019 return;
9020 }
9021 uiccProfile.refresh();
9022 } finally {
9023 Binder.restoreCallingIdentity(identity);
9024 }
9025 }
9026
9027 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009028 * Returns false if the mobile data is disabled by default, otherwise return true.
9029 */
9030 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009031 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009032 }
9033
9034 /**
9035 * Returns true if the data roaming is enabled by default, i.e the system property
9036 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9037 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9038 */
9039 private boolean getDefaultDataRoamingEnabled(int subId) {
9040 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009041 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009042 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009043 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9044 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9045 return isDataRoamingEnabled;
9046 }
9047
9048 /**
9049 * Returns the default network type for the given {@code subId}, if the default network type is
9050 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9051 */
9052 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009053 List<Integer> list = TelephonyProperties.default_network();
9054 int phoneId = mSubscriptionController.getPhoneId(subId);
9055 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9056 return list.get(phoneId);
9057 }
9058 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009059 }
fionaxua13278b2018-03-21 00:08:13 -07009060
9061 @Override
9062 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009063 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 final Phone phone = getPhone(subId);
9069 if (phone == null) {
9070 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9071 return;
9072 }
Rambo Wanga7436882022-01-13 21:51:44 -08009073 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9074 if (cpt != null) {
9075 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9076 }
9077 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009078 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9079 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009080 if (carrierPrivilegeRules == null) {
9081 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9082 } else {
9083 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009085 } finally {
9086 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009087 }
fionaxua13278b2018-03-21 00:08:13 -07009088 }
9089
9090 @Override
9091 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009092 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009093
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
9096 final Phone phone = getPhone(subId);
9097 if (phone == null) {
9098 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9099 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9100 }
9101 return phone.getCarrierIdListVersion();
9102 } finally {
9103 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009104 }
fionaxua13278b2018-03-21 00:08:13 -07009105 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009106
9107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009108 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9109 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009111 mApp, subId, callingPackage, callingFeatureId,
9112 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009113 return -1;
9114 }
9115
9116 final long identity = Binder.clearCallingIdentity();
9117 try {
9118 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
9121 }
9122 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009123
9124 @Override
9125 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009126 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009127 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009128 mApp, subId, "getCdmaRoamingMode");
9129
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
9132 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
9137
9138 @Override
9139 public boolean setCdmaRoamingMode(int subId, int mode) {
9140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9141 mApp, subId, "setCdmaRoamingMode");
9142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
9151 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009152 public int getCdmaSubscriptionMode(int subId) {
9153 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009154 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009155 mApp, subId, "getCdmaSubscriptionMode");
9156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
9165 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009166 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9168 mApp, subId, "setCdmaSubscriptionMode");
9169
9170 final long identity = Binder.clearCallingIdentity();
9171 try {
9172 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9173 } finally {
9174 Binder.restoreCallingIdentity(identity);
9175 }
9176 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009177
sqianc5eccab2018-10-19 18:46:41 -07009178 @Override
sqian8c685422019-02-22 15:55:18 -08009179 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009180 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009182 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9183 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009184 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9185 }
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
sqian854d44b2018-12-12 16:48:18 -08009188 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9189 for (Phone phone: PhoneFactory.getPhones()) {
9190 if (phone.getEmergencyNumberTracker() != null
9191 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9192 emergencyNumberListInternal.put(
9193 phone.getSubId(),
9194 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9195 }
sqian11b7a0e2018-12-05 18:48:28 -08009196 }
sqian854d44b2018-12-12 16:48:18 -08009197 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
sqianc5eccab2018-10-19 18:46:41 -07009201 }
9202
9203 @Override
sqian8c685422019-02-22 15:55:18 -08009204 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009205 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009206 if (!exactMatch) {
9207 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009208 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009209 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009210 }
9211 final long identity = Binder.clearCallingIdentity();
9212 try {
sqian854d44b2018-12-12 16:48:18 -08009213 for (Phone phone: PhoneFactory.getPhones()) {
9214 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009215 && phone.getEmergencyNumberTracker()
9216 .isEmergencyNumber(number, exactMatch)) {
9217 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009218 }
sqian11b7a0e2018-12-05 18:48:28 -08009219 }
9220 return false;
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
sqianf4ca7ed2019-01-15 18:32:07 -08009226 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009227 * Start emergency callback mode for GsmCdmaPhone for testing.
9228 */
9229 @Override
9230 public void startEmergencyCallbackMode() {
9231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9232 "startEmergencyCallbackMode");
9233 enforceModifyPermission();
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 for (Phone phone : PhoneFactory.getPhones()) {
9237 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9238 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9239 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9240 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9241 gsmCdmaPhone.obtainMessage(
9242 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9243 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9244 }
9245 }
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
9249 }
9250
9251 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009252 * Update emergency number list for test mode.
9253 */
9254 @Override
9255 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9257 "updateEmergencyNumberListTestMode");
9258
9259 final long identity = Binder.clearCallingIdentity();
9260 try {
9261 for (Phone phone: PhoneFactory.getPhones()) {
9262 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9263 if (tracker != null) {
9264 tracker.executeEmergencyNumberTestModeCommand(action, num);
9265 }
9266 }
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
9272 /**
9273 * Get the full emergency number list for test mode.
9274 */
9275 @Override
9276 public List<String> getEmergencyNumberListTestMode() {
9277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9278 "getEmergencyNumberListTestMode");
9279
9280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 Set<String> emergencyNumbers = new HashSet<>();
9283 for (Phone phone: PhoneFactory.getPhones()) {
9284 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9285 if (tracker != null) {
9286 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9287 emergencyNumbers.add(num.getNumber());
9288 }
9289 }
9290 }
9291 return new ArrayList<>(emergencyNumbers);
9292 } finally {
9293 Binder.restoreCallingIdentity(identity);
9294 }
9295 }
9296
chen xud6b45bd2018-10-30 22:27:10 -07009297 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009298 public int getEmergencyNumberDbVersion(int subId) {
9299 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 final Phone phone = getPhone(subId);
9304 if (phone == null) {
9305 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9306 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9307 }
9308 return phone.getEmergencyNumberDbVersion();
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 @Override
9315 public void notifyOtaEmergencyNumberDbInstalled() {
9316 enforceModifyPermission();
9317
9318 final long identity = Binder.clearCallingIdentity();
9319 try {
9320 for (Phone phone: PhoneFactory.getPhones()) {
9321 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9322 if (tracker != null) {
9323 tracker.updateOtaEmergencyNumberDatabase();
9324 }
9325 }
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
9330
9331 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009332 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009333 enforceActiveEmergencySessionPermission();
9334
9335 final long identity = Binder.clearCallingIdentity();
9336 try {
9337 for (Phone phone: PhoneFactory.getPhones()) {
9338 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9339 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009340 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9341 }
9342 }
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
9348 @Override
9349 public void resetOtaEmergencyNumberDbFilePath() {
9350 enforceActiveEmergencySessionPermission();
9351
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 for (Phone phone: PhoneFactory.getPhones()) {
9355 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9356 if (tracker != null) {
9357 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009358 }
9359 }
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 }
9364
9365 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009366 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9367 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9368 Phone phone = getPhone(subId);
9369 if (phone == null) {
9370 return null;
9371 }
9372 final long identity = Binder.clearCallingIdentity();
9373 try {
9374 UiccProfile profile = UiccController.getInstance()
9375 .getUiccProfileForPhone(phone.getPhoneId());
9376 if (profile != null) {
9377 return profile.getCertsFromCarrierPrivilegeAccessRules();
9378 }
9379 } finally {
9380 Binder.restoreCallingIdentity(identity);
9381 }
9382 return null;
9383 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009384
9385 /**
9386 * Enable or disable a modem stack.
9387 */
9388 @Override
9389 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9390 enforceModifyPermission();
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 Phone phone = PhoneFactory.getPhone(slotIndex);
9395 if (phone == null) {
9396 return false;
9397 } else {
9398 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9399 }
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 }
Michelecea4cf22018-12-21 15:00:11 -08009404
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009405 /**
9406 * Whether a modem stack is enabled or not.
9407 */
9408 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009409 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9410 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009411 Phone phone = PhoneFactory.getPhone(slotIndex);
9412 if (phone == null) return false;
9413
9414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009415 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9416 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009417 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9418 }
9419
9420 final long identity = Binder.clearCallingIdentity();
9421 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009422 try {
9423 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9424 } catch (NoSuchElementException ex) {
9425 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9426 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009427 } finally {
9428 Binder.restoreCallingIdentity(identity);
9429 }
9430 }
9431
Michelecea4cf22018-12-21 15:00:11 -08009432 @Override
Michele0ea7d782019-03-19 14:58:42 -07009433 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009434 enforceModifyPermission();
9435
9436 final long identity = Binder.clearCallingIdentity();
9437 try {
9438 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009439 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009440 .commit();
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 }
9445
9446 @Override
Michele0ea7d782019-03-19 14:58:42 -07009447 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009448 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009450 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9451 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009452 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009453 }
Michelecea4cf22018-12-21 15:00:11 -08009454
9455 final long identity = Binder.clearCallingIdentity();
9456 try {
Michele0ea7d782019-03-19 14:58:42 -07009457 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009458 } finally {
9459 Binder.restoreCallingIdentity(identity);
9460 }
9461 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009462
Michele0ea7d782019-03-19 14:58:42 -07009463 @TelephonyManager.IsMultiSimSupportedResult
9464 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009465 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9466 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9467 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009468 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9469 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009470 }
9471 // Check if the hardware supports multisim functionality. If usage of multisim is not
9472 // supported by the modem, indicate that it is restricted.
9473 PhoneCapability staticCapability =
9474 mPhoneConfigurationManager.getStaticPhoneCapability();
9475 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009476 loge("isMultiSimSupportedInternal: no static configuration available");
9477 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009478 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009479 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009480 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9481 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009482 }
9483 // Check if support of multiple SIMs is restricted by carrier
9484 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009485 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009486 }
9487
Michele0ea7d782019-03-19 14:58:42 -07009488 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009489 }
9490
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009491 /**
9492 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009493 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9494 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9495 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009496 * @param numOfSims number of active sims we want to switch to
9497 */
9498 @Override
9499 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009500 if (numOfSims == 1) {
9501 enforceModifyPermission();
9502 } else {
9503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9504 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9505 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009506 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009507
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009508 try {
Michele30b57b22019-03-01 12:01:14 -08009509 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009510 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009511 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9512 return;
9513 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009514 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9515 } finally {
9516 Binder.restoreCallingIdentity(identity);
9517 }
9518 }
9519
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009520 @Override
9521 public boolean isApplicationOnUicc(int subId, int appType) {
9522 enforceReadPrivilegedPermission("isApplicationOnUicc");
9523 Phone phone = getPhone(subId);
9524 if (phone == null) {
9525 return false;
9526 }
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009529 UiccPort uiccPort = phone.getUiccPort();
9530 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009531 return false;
9532 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009533 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009534 if (uiccProfile == null) {
9535 return false;
9536 }
9537 if (TelephonyManager.APPTYPE_SIM <= appType
9538 && appType <= TelephonyManager.APPTYPE_ISIM) {
9539 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9540 }
9541 return false;
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009547 /**
chen xub4baa772019-04-03 10:23:41 -07009548 * Get whether making changes to modem configurations will trigger reboot.
9549 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009550 */
9551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009552 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9553 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009555 mApp, subId, callingPackage, callingFeatureId,
9556 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009557 return false;
9558 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009559 final long identity = Binder.clearCallingIdentity();
9560 try {
9561 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
9564 }
9565 }
9566
Nathan Harold29f5f052019-02-15 13:41:57 -08009567 private void updateModemStateMetrics() {
9568 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9569 // TODO: check the state for each modem if the api is ready.
9570 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9571 }
9572
Pengquan Meng3889a572019-01-23 11:16:29 -08009573 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009574 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009575 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009576 // Verify that the callingPackage belongs to the calling UID
9577 mApp.getSystemService(AppOpsManager.class)
9578 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009579 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009580 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009581 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009582 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9583 if (slotInfos != null) {
9584 for (int i = 0; i < slotInfos.length; i++) {
9585 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9586 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9587 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9588 portInfo.getLogicalSlotIndex()));
9589 }
9590 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009591 }
9592 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009593 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009594 } finally {
9595 Binder.restoreCallingIdentity(identity);
9596 }
9597 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009598
9599 /**
9600 * Get the IRadio HAL Version
9601 */
9602 @Override
9603 public int getRadioHalVersion() {
9604 Phone phone = getDefaultPhone();
9605 if (phone == null) return -1;
9606 HalVersion hv = phone.getHalVersion();
9607 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9608 return hv.major * 100 + hv.minor;
9609 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009610
9611 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009612 * Get the current calling package name.
9613 * @return the current calling package name
9614 */
9615 @Override
9616 public String getCurrentPackageName() {
9617 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9618 }
9619
9620 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009621 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9622 * corresponding network requests on a subId.
9623 *
9624 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009625 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009626 * 2) APN is un-metered for this subscription, or
9627 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009628 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009629 *
9630 * @return whether data is allowed for a apn type.
9631 *
9632 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009633 */
9634 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009635 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009636 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9637 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009638
9639 // Now that all security checks passes, perform the operation as ourselves.
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
9642 Phone phone = getPhone(subId);
9643 if (phone == null) return false;
9644
Jack Yu41407ee2019-05-13 16:54:09 -07009645 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009646 boolean isDataEnabled;
9647 if (phone.isUsingNewDataStack()) {
9648 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9649 } else {
9650 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9651 }
9652 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009653 } finally {
9654 Binder.restoreCallingIdentity(identity);
9655 }
9656 }
9657
9658 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009659 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009660 enforceReadPrivilegedPermission("isApnMetered");
9661
9662 // Now that all security checks passes, perform the operation as ourselves.
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
9665 Phone phone = getPhone(subId);
9666 if (phone == null) return true; // By default return true.
9667
Jack Yu41407ee2019-05-13 16:54:09 -07009668 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
9672 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009673
9674 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009675 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9676 int subscriptionId, IBooleanConsumer resultCallback) {
9677 enforceModifyPermission();
9678 long token = Binder.clearCallingIdentity();
9679 try {
9680 Phone phone = getPhone(subscriptionId);
9681 if (phone == null) {
9682 try {
9683 if (resultCallback != null) {
9684 resultCallback.accept(false);
9685 }
9686 } catch (RemoteException e) {
9687 // ignore
9688 }
9689 return;
9690 }
9691 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9692 Pair.create(specifiers, (x) -> {
9693 try {
9694 if (resultCallback != null) {
9695 resultCallback.accept(x);
9696 }
9697 } catch (RemoteException e) {
9698 // ignore
9699 }
9700 });
9701 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9702 } finally {
9703 Binder.restoreCallingIdentity(token);
9704 }
9705 }
9706
9707 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009708 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9709 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009710 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009711 mApp, subId, "getSystemSelectionChannels");
9712 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009715 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9716 if (result instanceof IllegalStateException) {
9717 throw (IllegalStateException) result;
9718 }
9719 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009720 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9721 return specifiers;
9722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
9726
9727 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009728 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009729 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009730 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9731 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9732 if (iccRecords == null) {
9733 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9734 return false;
9735 }
9736 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9737 }
9738
9739 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009740 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9741 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009742 if (callingPackage == null) {
9743 callingPackage = getCurrentPackageName();
9744 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009745 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9746 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009747 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9748 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009749 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9750 }
9751 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9752 Intent intent = new Intent();
9753 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9754 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9755 // Bring up choose default SMS subscription dialog right now
9756 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9757 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9758 mApp.startActivity(intent);
9759 }
chen xud5ca2d52019-05-28 15:20:57 -07009760
9761 @Override
9762 public String getMmsUAProfUrl(int subId) {
9763 //TODO investigate if this API should require proper permission check in R b/133791609
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009766 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9767 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9768 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9769 return carrierUAProfUrl;
9770 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009771 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9772 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
9778 @Override
9779 public String getMmsUserAgent(int subId) {
9780 //TODO investigate if this API should require proper permission check in R b/133791609
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009783 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9784 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9785 if (!TextUtils.isEmpty(carrierUserAgent)) {
9786 return carrierUserAgent;
9787 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009788 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9789 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
Jack Yub07d4972019-05-28 16:12:25 -07009794
9795 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009796 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9797 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009798
Jack Yub07d4972019-05-28 16:12:25 -07009799 final long identity = Binder.clearCallingIdentity();
9800 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009801 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009802 if (phone == null) return false;
9803
Hall Liua62f5da2020-09-25 10:42:19 -07009804 switch (policy) {
9805 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009806 if (phone.isUsingNewDataStack()) {
9807 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9808 } else {
9809 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9810 }
Hall Liua62f5da2020-09-25 10:42:19 -07009811 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009812 if (phone.isUsingNewDataStack()) {
9813 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9814 } else {
9815 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9816 }
Hall Liua62f5da2020-09-25 10:42:19 -07009817 default:
9818 throw new IllegalArgumentException(policy + " is not a valid policy");
9819 }
Jack Yub07d4972019-05-28 16:12:25 -07009820 } finally {
9821 Binder.restoreCallingIdentity(identity);
9822 }
9823 }
9824
9825 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009826 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009827 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009828 enforceModifyPermission();
9829
changbettyd5c246e2019-12-24 15:40:37 +08009830 final long identity = Binder.clearCallingIdentity();
9831 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009832 Phone phone = getPhone(subscriptionId);
9833 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009834
Hall Liua62f5da2020-09-25 10:42:19 -07009835 switch (policy) {
9836 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009837 if (phone.isUsingNewDataStack()) {
9838 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9839 } else {
9840 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9841 }
Hall Liua62f5da2020-09-25 10:42:19 -07009842 break;
9843 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009844 if (phone.isUsingNewDataStack()) {
9845 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9846 } else {
9847 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9848 }
Hall Liua62f5da2020-09-25 10:42:19 -07009849 break;
9850 default:
9851 throw new IllegalArgumentException(policy + " is not a valid policy");
9852 }
changbettyd5c246e2019-12-24 15:40:37 +08009853 } finally {
9854 Binder.restoreCallingIdentity(identity);
9855 }
9856 }
9857
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009858 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009859 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009860 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9861 * otherwise.
9862 */
9863 @Override
9864 public void setCepEnabled(boolean isCepEnabled) {
9865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9866
9867 final long identity = Binder.clearCallingIdentity();
9868 try {
9869 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9870 for (Phone phone : PhoneFactory.getPhones()) {
9871 Phone defaultPhone = phone.getImsPhone();
9872 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9873 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9874 ImsPhoneCallTracker imsPhoneCallTracker =
9875 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9876 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9877 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9878 + imsPhone.getMsisdn());
9879 }
9880 }
9881 } finally {
9882 Binder.restoreCallingIdentity(identity);
9883 }
9884 }
allenwtsu46dcc572020-01-08 18:24:03 +08009885
9886 /**
9887 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9888 *
9889 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9890 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9891 * before being read.
9892 */
9893 @Override
9894 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9895 isCompressed) {
9896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9897 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009898 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9899 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9900 }
9901 if (!isImsAvailableOnDevice()) {
9902 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9903 "IMS not available on device.");
9904 }
9905
9906 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009907 try {
Hui Wang761a6682020-10-31 05:12:53 +00009908 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9909 } finally {
9910 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009911 }
9912 }
zoey chene02881a2019-12-30 16:11:23 +08009913
9914 @Override
9915 public boolean isIccLockEnabled(int subId) {
9916 enforceReadPrivilegedPermission("isIccLockEnabled");
9917
9918 // Now that all security checks passes, perform the operation as ourselves.
9919 final long identity = Binder.clearCallingIdentity();
9920 try {
9921 Phone phone = getPhone(subId);
9922 if (phone != null && phone.getIccCard() != null) {
9923 return phone.getIccCard().getIccLockEnabled();
9924 } else {
9925 return false;
9926 }
9927 } finally {
9928 Binder.restoreCallingIdentity(identity);
9929 }
9930 }
9931
9932 /**
9933 * Set the ICC pin lock enabled or disabled.
9934 *
9935 * @return an integer representing the status of IccLock enabled or disabled in the following
9936 * three cases:
9937 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9938 * successfully.
9939 * - Positive number and zero for remaining password attempts.
9940 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9941 *
9942 */
9943 @Override
9944 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9945 enforceModifyPermission();
9946
9947 Phone phone = getPhone(subId);
9948 if (phone == null) {
9949 return 0;
9950 }
9951 // Now that all security checks passes, perform the operation as ourselves.
9952 final long identity = Binder.clearCallingIdentity();
9953 try {
9954 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9955 new Pair<Boolean, String>(enabled, password), phone, null);
9956 return attemptsRemaining;
9957
9958 } catch (Exception e) {
9959 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 return 0;
9964 }
9965
9966 /**
9967 * Change the ICC password used in ICC pin lock.
9968 *
9969 * @return an integer representing the status of IccLock changed in the following three cases:
9970 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9971 * - Positive number and zero for remaining password attempts.
9972 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9973 *
9974 */
9975 @Override
9976 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9977 enforceModifyPermission();
9978
9979 Phone phone = getPhone(subId);
9980 if (phone == null) {
9981 return 0;
9982 }
9983 // Now that all security checks passes, perform the operation as ourselves.
9984 final long identity = Binder.clearCallingIdentity();
9985 try {
9986 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9987 new Pair<String, String>(oldPassword, newPassword), phone, null);
9988 return attemptsRemaining;
9989
9990 } catch (Exception e) {
9991 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9992 } finally {
9993 Binder.restoreCallingIdentity(identity);
9994 }
9995 return 0;
9996 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009997
9998 /**
9999 * Request for receiving user activity notification
10000 */
10001 @Override
10002 public void requestUserActivityNotification() {
10003 if (!mNotifyUserActivity.get()
10004 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10005 mNotifyUserActivity.set(true);
10006 }
10007 }
10008
10009 /**
10010 * Called when userActivity is signalled in the power manager.
10011 * This is safe to call from any thread, with any window manager locks held or not.
10012 */
10013 @Override
10014 public void userActivity() {
10015 // ***************************************
10016 // * Inherited from PhoneWindowManager *
10017 // ***************************************
10018 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10019 // WITH ITS LOCKS HELD.
10020 //
10021 // This code must be VERY careful about the locks
10022 // it acquires.
10023 // In fact, the current code acquires way too many,
10024 // and probably has lurking deadlocks.
10025
10026 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10027 throw new SecurityException("Only the OS may call notifyUserActivity()");
10028 }
10029
10030 if (mNotifyUserActivity.getAndSet(false)) {
10031 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10032 USER_ACTIVITY_NOTIFICATION_DELAY);
10033 }
10034 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010035
10036 @Override
10037 public boolean canConnectTo5GInDsdsMode() {
10038 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10039 }
Jack Yud10cdd42020-09-28 20:28:01 -070010040
10041 @Override
10042 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10043 String callingFeatureId) {
10044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10045 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10046 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10047 }
10048
10049 Phone phone = getPhone(subId);
10050 if (phone == null) {
10051 throw new RuntimeException("phone is not available");
10052 }
10053 // Now that all security checks passes, perform the operation as ourselves.
10054 final long identity = Binder.clearCallingIdentity();
10055 try {
10056 return phone.getEquivalentHomePlmns();
10057 } finally {
10058 Binder.restoreCallingIdentity(identity);
10059 }
10060 }
Daniel Bright59e67312020-11-13 11:49:37 -080010061
10062 @Override
10063 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010064 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10065 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010066 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010067 if (radioInterfaceCapabilities == null) {
10068 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010069 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010070 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010071 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010072
Hui Wang641e81c2020-10-12 12:14:23 -070010073 @Override
10074 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10075 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010076 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10077 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10078 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10079 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10080 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010081 if (DBG) {
10082 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10083 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10084 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10085 }
10086
10087 if (!SubscriptionManager.isValidSubscriptionId(subId)
10088 || appType < TelephonyManager.APPTYPE_UNKNOWN
10089 || appType > TelephonyManager.APPTYPE_ISIM
10090 || nafUrl == null || securityProtocol == null || callback == null) {
10091 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10092 if (callback != null) {
10093 try {
10094 callback.onAuthenticationFailure(
10095 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10096 } catch (RemoteException exception) {
10097 log("Fail to notify onAuthenticationFailure due to " + exception);
10098 }
10099 return;
10100 }
10101 }
10102
10103 final long token = Binder.clearCallingIdentity();
10104 try {
10105 getGbaManager(subId).bootstrapAuthenticationRequest(
10106 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10107 forceBootStrapping, callback));
10108 } finally {
10109 Binder.restoreCallingIdentity(token);
10110 }
10111 }
10112
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010113 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010114 * Attempts to set the radio power state for all phones for thermal reason.
10115 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010116 * requested radio power state will actually be set. See {@link
10117 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10118 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 * @param enable {@code true} if trying to turn radio on.
10120 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10121 * false}.
10122 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010123 private boolean setRadioPowerForThermal(boolean enable) {
10124 boolean isPhoneAvailable = false;
10125 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10126 Phone phone = PhoneFactory.getPhone(i);
10127 if (phone != null) {
10128 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10129 isPhoneAvailable = true;
10130 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010132
10133 // return true if successfully informed the phone object about the thermal radio power
10134 // request.
10135 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010136 }
10137
10138 private int handleDataThrottlingRequest(int subId,
10139 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010140 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10141 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10142 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10143 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10144 throw new IllegalArgumentException("modem does not support data throttling");
10145 }
10146
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10148 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010149 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010150 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10151 }
10152
10153 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10154
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010155 if (isDataThrottlingSupported) {
10156 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010157 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010158 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10159 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10160 } else if (thermalMitigationResult
10161 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010162 log("Modem likely does not support data throttling on secondary carrier. Data " +
10163 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10164 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010165 }
10166 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010167 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010168
10169 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010170 }
10171
Jack Nudelman644b91a2021-03-12 14:09:48 -080010172 private static List<String> getThermalMitigationAllowlist(Context context) {
10173 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10174 for (String pckg : context.getResources()
10175 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10176 sThermalMitigationAllowlistedPackages.add(pckg);
10177 }
10178 }
10179
10180 return sThermalMitigationAllowlistedPackages;
10181 }
10182
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010183 private boolean isAnyPhoneInEmergencyState() {
10184 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10185 if (tm.isInEmergencyCall()) {
10186 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10187 return true;
10188 }
10189 for (Phone phone : PhoneFactory.getPhones()) {
10190 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10191 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10192 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10193 + phone.isInEcm());
10194 return true;
10195 }
10196 }
10197
10198 return false;
10199 }
10200
Jack Nudelman644b91a2021-03-12 14:09:48 -080010201 /**
10202 * Used by shell commands to add an authorized package name for thermal mitigation.
10203 * @param packageName name of package to be allowlisted
10204 * @param context
10205 */
10206 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10207 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10208 sThermalMitigationAllowlistedPackages.add(packageName);
10209 }
10210
10211 /**
10212 * Used by shell commands to remove an authorized package name for thermal mitigation.
10213 * @param packageName name of package to remove from allowlist
10214 * @param context
10215 */
10216 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10217 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10218 sThermalMitigationAllowlistedPackages.remove(packageName);
10219 }
10220
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010221 /**
10222 * Thermal mitigation request to control functionalities at modem.
10223 *
10224 * @param subId the id of the subscription.
10225 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010226 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010227 *
10228 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10229 */
10230 @Override
10231 @ThermalMitigationResult
10232 public int sendThermalMitigationRequest(
10233 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010234 ThermalMitigationRequest thermalMitigationRequest,
10235 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010236 enforceModifyPermission();
10237
Jack Nudelman644b91a2021-03-12 14:09:48 -080010238 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10239 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10240 .contains(callingPackage)) {
10241 throw new SecurityException("Calling package must be configured in the device config. "
10242 + "calling package: " + callingPackage);
10243 }
10244
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010245 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10246 final long identity = Binder.clearCallingIdentity();
10247
10248 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10249 try {
10250 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10251 switch (thermalMitigationAction) {
10252 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10253 thermalMitigationResult =
10254 handleDataThrottlingRequest(subId,
10255 thermalMitigationRequest.getDataThrottlingRequest());
10256 break;
10257 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10258 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10259 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10260 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10261 }
10262
10263 // Ensure that radio is on. If not able to power on due to phone being
10264 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010265 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 thermalMitigationResult =
10267 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10268 break;
10269 }
10270
10271 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10272 false);
10273 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10274 break;
10275 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10276 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10277 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10278 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10279 }
10280
10281 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10282 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010283 Phone phone = getPhone(subId);
10284 if (phone == null) {
10285 thermalMitigationResult =
10286 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10287 break;
10288 }
10289
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010290 TelephonyConnectionService service =
10291 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010292 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010293 Log.e(LOG_TAG, "An emergency call is pending");
10294 thermalMitigationResult =
10295 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10296 break;
10297 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010298 thermalMitigationResult =
10299 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10300 break;
10301 }
10302 } else {
10303 thermalMitigationResult =
10304 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10305 break;
10306 }
10307
10308 // Turn radio off. If not able to power off due to phone being unavailable,
10309 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010310 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311 thermalMitigationResult =
10312 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10313 break;
10314 }
10315 thermalMitigationResult =
10316 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10317 break;
10318 default:
10319 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10320 + "not exist. Requested action: " + thermalMitigationAction);
10321 }
10322 } catch (IllegalArgumentException e) {
10323 throw e;
10324 } catch (Exception e) {
10325 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10326 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10327 } finally {
10328 Binder.restoreCallingIdentity(identity);
10329 }
10330
10331 if (DBG) {
10332 log("thermalMitigationRequest returning with thermalMitigationResult: "
10333 + thermalMitigationResult);
10334 }
10335
10336 return thermalMitigationResult;
10337 }
Hui Wang641e81c2020-10-12 12:14:23 -070010338
10339 /**
10340 * Set the GbaService Package Name that Telephony will bind to.
10341 *
10342 * @param subId The sim that the GbaService is associated with.
10343 * @param packageName The name of the package to be replaced with.
10344 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10345 */
10346 @Override
10347 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10348 enforceModifyPermission();
10349
10350 final long identity = Binder.clearCallingIdentity();
10351 try {
10352 return getGbaManager(subId).overrideServicePackage(packageName);
10353 } finally {
10354 Binder.restoreCallingIdentity(identity);
10355 }
10356 }
10357
10358 /**
10359 * Return the package name of the currently bound GbaService.
10360 *
10361 * @param subId The sim that the GbaService is associated with.
10362 * @return the package name of the GbaService configuration, null if GBA is not supported.
10363 */
10364 @Override
10365 public String getBoundGbaService(int subId) {
10366 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 return getGbaManager(subId).getServicePackage();
10371 } finally {
10372 Binder.restoreCallingIdentity(identity);
10373 }
10374 }
10375
10376 /**
10377 * Set the release time for telephony to unbind GbaService.
10378 *
10379 * @param subId The sim that the GbaService is associated with.
10380 * @param interval The release time to unbind GbaService by millisecond.
10381 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10382 */
10383 @Override
10384 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10385 enforceModifyPermission();
10386
10387 final long identity = Binder.clearCallingIdentity();
10388 try {
10389 return getGbaManager(subId).overrideReleaseTime(interval);
10390 } finally {
10391 Binder.restoreCallingIdentity(identity);
10392 }
10393 }
10394
10395 /**
10396 * Return the release time for telephony to unbind GbaService.
10397 *
10398 * @param subId The sim that the GbaService is associated with.
10399 * @return The release time to unbind GbaService by millisecond.
10400 */
10401 @Override
10402 public int getGbaReleaseTime(int subId) {
10403 enforceReadPrivilegedPermission("getGbaReleaseTime");
10404
10405 final long identity = Binder.clearCallingIdentity();
10406 try {
10407 return getGbaManager(subId).getReleaseTime();
10408 } finally {
10409 Binder.restoreCallingIdentity(identity);
10410 }
10411 }
10412
10413 private GbaManager getGbaManager(int subId) {
10414 GbaManager instance = GbaManager.getInstance(subId);
10415 if (instance == null) {
10416 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10417 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10418 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10419 }
10420 return instance;
10421 }
Hui Wang761a6682020-10-31 05:12:53 +000010422
10423 /**
10424 * indicate whether the device and the carrier can support
10425 * RCS VoLTE single registration.
10426 */
10427 @Override
10428 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010429 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10430 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10431 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10432 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010433
10434 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10435 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10436 }
10437
10438 final long identity = Binder.clearCallingIdentity();
10439 try {
10440 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10441 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010442 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10443 if (isCapable != null) {
10444 return isCapable;
10445 }
Hui Wang761a6682020-10-31 05:12:53 +000010446 }
Hui Wang67af90e2021-06-04 16:57:15 -070010447 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10448 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
10454 /**
10455 * Register RCS provisioning callback.
10456 */
10457 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010458 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010459 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010460 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010461 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010462 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10463 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10466 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10467 }
10468 if (!isImsAvailableOnDevice()) {
10469 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10470 "IMS not available on device.");
10471 }
10472
10473 final long identity = Binder.clearCallingIdentity();
10474 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010475 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010476 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010477 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10478 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010479 }
Hui Wang761a6682020-10-31 05:12:53 +000010480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 /**
10486 * Unregister RCS provisioning callback.
10487 */
10488 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010489 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010490 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010491 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010492 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010493 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10494 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010495
10496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10497 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10498 }
10499 if (!isImsAvailableOnDevice()) {
10500 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10501 "IMS not available on device.");
10502 }
10503
10504 final long identity = Binder.clearCallingIdentity();
10505 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010506 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010507 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
10513 /**
10514 * trigger RCS reconfiguration.
10515 */
10516 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010517 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10518 "triggerRcsReconfiguration",
10519 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010520
10521 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10522 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10523 }
10524 if (!isImsAvailableOnDevice()) {
10525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10526 "IMS not available on device.");
10527 }
10528
10529 final long identity = Binder.clearCallingIdentity();
10530 try {
10531 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 /**
10538 * Provide the client configuration parameters of the RCS application.
10539 */
10540 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010541 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10542 "setRcsClientConfiguration",
10543 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010544
10545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10546 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10547 }
10548 if (!isImsAvailableOnDevice()) {
10549 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10550 "IMS not available on device.");
10551 }
10552
10553 final long identity = Binder.clearCallingIdentity();
10554
10555 try {
10556 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10557 if (configBinder == null) {
10558 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010559 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10560 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010561 } else {
10562 configBinder.setRcsClientConfiguration(rcc);
10563 }
joonhunshinfa314642021-09-17 06:33:39 +000010564
10565 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10566 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010567 } catch (RemoteException e) {
10568 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010569 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10570 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010571 } finally {
10572 Binder.restoreCallingIdentity(identity);
10573 }
10574 }
10575
10576 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010577 * Enables or disables the test mode for RCS VoLTE single registration.
10578 */
10579 @Override
10580 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10582 "setRcsSingleRegistrationTestModeEnabled");
10583
10584 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10585 }
10586
10587 /**
10588 * Gets the test mode for RCS VoLTE single registration.
10589 */
10590 @Override
10591 public boolean getRcsSingleRegistrationTestModeEnabled() {
10592 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10593 "getRcsSingleRegistrationTestModeEnabled");
10594
10595 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10596 }
10597
10598 /**
Hui Wang761a6682020-10-31 05:12:53 +000010599 * Overrides the config of RCS VoLTE single registration enabled for the device.
10600 */
10601 @Override
10602 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10603 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10604 "setDeviceSingleRegistrationEnabledOverride");
10605 enforceModifyPermission();
10606
10607 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10608 : Boolean.parseBoolean(enabledStr);
10609 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010610 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010611 }
10612
10613 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010614 * Sends a device to device communication message. Only usable via shell.
10615 * @param message message to send.
10616 * @param value message value.
10617 */
10618 @Override
10619 public void sendDeviceToDeviceMessage(int message, int value) {
10620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010621 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010622 enforceModifyPermission();
10623
10624 final long identity = Binder.clearCallingIdentity();
10625 try {
10626 TelephonyConnectionService service =
10627 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10628 if (service == null) {
10629 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10630 return;
10631 }
10632 service.sendTestDeviceToDeviceMessage(message, value);
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
10637
Tyler Gunnbabbda02021-02-10 11:05:02 -080010638 /**
10639 * Sets the specified device to device transport active.
10640 * @param transport The transport to set active.
10641 */
10642 @Override
10643 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10644 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10645 "setActiveDeviceToDeviceTransport");
10646 enforceModifyPermission();
10647
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 TelephonyConnectionService service =
10651 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10652 if (service == null) {
10653 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10654 return;
10655 }
10656 service.setActiveDeviceToDeviceTransport(transport);
10657 } finally {
10658 Binder.restoreCallingIdentity(identity);
10659 }
10660 }
Tyler Gunn92479152021-01-20 16:30:10 -080010661
Tyler Gunnd4575212021-05-03 14:46:49 -070010662 @Override
10663 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10664 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10665 "setDeviceToDeviceForceEnabled");
10666
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
10669 Arrays.stream(PhoneFactory.getPhones()).forEach(
10670 p -> {
10671 Phone thePhone = p.getImsPhone();
10672 if (thePhone != null && thePhone instanceof ImsPhone) {
10673 ImsPhone imsPhone = (ImsPhone) thePhone;
10674 CallTracker tracker = imsPhone.getCallTracker();
10675 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10676 ImsPhoneCallTracker imsPhoneCallTracker =
10677 (ImsPhoneCallTracker) tracker;
10678 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10679 }
10680 }
10681 }
10682 );
10683 } finally {
10684 Binder.restoreCallingIdentity(identity);
10685 }
10686 }
10687
Tyler Gunn92479152021-01-20 16:30:10 -080010688 /**
Hui Wang761a6682020-10-31 05:12:53 +000010689 * Gets the config of RCS VoLTE single registration enabled for the device.
10690 */
10691 @Override
10692 public boolean getDeviceSingleRegistrationEnabled() {
10693 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10694 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10695 }
10696
10697 /**
10698 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10699 */
10700 @Override
10701 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10703 "setCarrierSingleRegistrationEnabledOverride");
10704 enforceModifyPermission();
10705
10706 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10707 : Boolean.parseBoolean(enabledStr);
10708 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10709 subId, enabled);
10710 }
10711
10712 /**
10713 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10714 */
10715 @Override
10716 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10717 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10718 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10719 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010720
10721 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010722 * Overrides the ims feature validation result
10723 */
10724 @Override
10725 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10727 "setImsFeatureValidationOverride");
10728
10729 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10730 : Boolean.parseBoolean(enabledStr);
10731 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10732 subId, enabled);
10733 }
10734
10735 /**
10736 * Gets the ims feature validation override value
10737 */
10738 @Override
10739 public boolean getImsFeatureValidationOverride(int subId) {
10740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10741 "getImsFeatureValidationOverride");
10742 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10743 }
10744
10745 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010746 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10747 * their mobile plan.
10748 */
10749 @Override
10750 public String getMobileProvisioningUrl() {
10751 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10752 final long identity = Binder.clearCallingIdentity();
10753 try {
10754 return getDefaultPhone().getMobileProvisioningUrl();
10755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010759
James.cf Linbcdf8b32021-01-14 16:44:13 +080010760 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010761 * Get the EAB contact from the EAB database.
10762 */
10763 @Override
10764 public String getContactFromEab(String contact) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10766 enforceModifyPermission();
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
10775 /**
Calvin Pana1434322021-07-01 19:27:01 +080010776 * Get the EAB capability from the EAB database.
10777 */
10778 @Override
10779 public String getCapabilityFromEab(String contact) {
10780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10781 enforceModifyPermission();
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
10784 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
10789
10790 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010791 * Remove the EAB contacts from the EAB database.
10792 */
10793 @Override
10794 public int removeContactFromEab(int subId, String contacts) {
10795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10796 enforceModifyPermission();
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010805 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010806 public boolean getDeviceUceEnabled() {
10807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10808 final long identity = Binder.clearCallingIdentity();
10809 try {
10810 return mApp.getDeviceUceEnabled();
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
10815
10816 @Override
10817 public void setDeviceUceEnabled(boolean isEnabled) {
10818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 mApp.setDeviceUceEnabled(isEnabled);
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
Brad Ebinger14d467f2021-02-12 06:18:28 +000010827 /**
10828 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10829 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10830 */
10831 // Used for SHELL command only right now.
10832 @Override
10833 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10834 List<String> featureTags) {
10835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10836 "addUceRegistrationOverrideShell");
10837 final long identity = Binder.clearCallingIdentity();
10838 try {
10839 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10840 new ArraySet<>(featureTags));
10841 } catch (ImsException e) {
10842 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10843 } finally {
10844 Binder.restoreCallingIdentity(identity);
10845 }
10846 }
10847
10848 /**
10849 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10850 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10851 */
10852 // Used for SHELL command only right now.
10853 @Override
10854 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10855 List<String> featureTags) {
10856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10857 "removeUceRegistrationOverrideShell");
10858 final long identity = Binder.clearCallingIdentity();
10859 try {
10860 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10861 new ArraySet<>(featureTags));
10862 } catch (ImsException e) {
10863 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 }
10868
10869 /**
10870 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10871 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10872 */
10873 // Used for SHELL command only right now.
10874 @Override
10875 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10877 "clearUceRegistrationOverrideShell");
10878 final long identity = Binder.clearCallingIdentity();
10879 try {
10880 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10881 } catch (ImsException e) {
10882 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10883 } finally {
10884 Binder.restoreCallingIdentity(identity);
10885 }
10886 }
10887
10888 /**
10889 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10890 */
10891 // Used for SHELL command only right now.
10892 @Override
10893 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10895 "getLatestRcsContactUceCapabilityShell");
10896 final long identity = Binder.clearCallingIdentity();
10897 try {
10898 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10899 } catch (ImsException e) {
10900 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10901 } finally {
10902 Binder.restoreCallingIdentity(identity);
10903 }
10904 }
10905
10906 /**
10907 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10908 * device does not have an active PUBLISH.
10909 */
10910 // Used for SHELL command only right now.
10911 @Override
10912 public String getLastUcePidfXmlShell(int subId) {
10913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10914 final long identity = Binder.clearCallingIdentity();
10915 try {
10916 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10917 } catch (ImsException e) {
10918 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
10923
James.cf Line8713a42021-04-29 16:04:26 +080010924 /**
10925 * Remove UCE requests cannot be sent to the network status.
10926 */
10927 // Used for SHELL command only right now.
10928 @Override
10929 public boolean removeUceRequestDisallowedStatus(int subId) {
10930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10931 final long identity = Binder.clearCallingIdentity();
10932 try {
10933 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10934 } catch (ImsException e) {
10935 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10936 } finally {
10937 Binder.restoreCallingIdentity(identity);
10938 }
10939 }
10940
James.cf Lin0fc71b02021-05-25 01:37:38 +080010941 /**
10942 * Remove UCE requests cannot be sent to the network status.
10943 */
10944 // Used for SHELL command only.
10945 @Override
10946 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10947 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10948 final long identity = Binder.clearCallingIdentity();
10949 try {
10950 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10951 } catch (ImsException e) {
10952 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10953 } finally {
10954 Binder.restoreCallingIdentity(identity);
10955 }
10956 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010957
James.cf Lin4b784aa2021-01-31 03:25:15 +080010958 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010959 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10960 String callingPackage) {
10961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10962 mApp, subId, "setSignalStrengthUpdateRequest");
10963
10964 final int callingUid = Binder.getCallingUid();
10965 // Verify that tha callingPackage belongs to the calling UID
10966 mApp.getSystemService(AppOpsManager.class)
10967 .checkPackage(callingUid, callingPackage);
10968
Rambo Wang3607f502021-02-01 21:51:40 -080010969 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010970
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
10973 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10974 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10975
10976 if (result instanceof IllegalStateException) {
10977 throw (IllegalStateException) result;
10978 }
10979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
10983
10984 @Override
10985 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10986 String callingPackage) {
10987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10988 mApp, subId, "clearSignalStrengthUpdateRequest");
10989
10990 final int callingUid = Binder.getCallingUid();
10991 // Verify that tha callingPackage belongs to the calling UID
10992 mApp.getSystemService(AppOpsManager.class)
10993 .checkPackage(callingUid, callingPackage);
10994
10995 final long identity = Binder.clearCallingIdentity();
10996 try {
10997 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10998 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10999
11000 if (result instanceof IllegalStateException) {
11001 throw (IllegalStateException) result;
11002 }
11003 } finally {
11004 Binder.restoreCallingIdentity(identity);
11005 }
11006 }
11007
Rambo Wang3607f502021-02-01 21:51:40 -080011008 private static void validateSignalStrengthUpdateRequest(Context context,
11009 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011010 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11011 // phone/system process do not have further restriction on request
11012 return;
11013 }
11014
11015 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011016 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011017 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011018 context.enforceCallingOrSelfPermission(
11019 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11020 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011021 }
11022
11023 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11024 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11025 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11026 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11027 || info.isEnabled()) {
11028 throw new IllegalArgumentException(
11029 "Only system can set hide fields in SignalThresholdInfo");
11030 }
11031
11032 // Thresholds length for each RAN need in range. This has been validated in
11033 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11034 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11035 final int[] thresholds = info.getThresholds();
11036 Objects.requireNonNull(thresholds);
11037 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11038 || thresholds.length
11039 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11040 throw new IllegalArgumentException(
11041 "thresholds length is out of range: " + thresholds.length);
11042 }
11043 }
11044 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011045
11046 /**
11047 * Gets the current phone capability.
11048 *
11049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11050 * @return the PhoneCapability which describes the data connection capability of modem.
11051 * It's used to evaluate possible phone config change, for example from single
11052 * SIM device to multi-SIM device.
11053 */
11054 @Override
11055 public PhoneCapability getPhoneCapability() {
11056 enforceReadPrivilegedPermission("getPhoneCapability");
11057 final long identity = Binder.clearCallingIdentity();
11058 try {
11059 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
Michele Berionne5e411512020-11-13 02:36:59 +000011064
11065 /**
11066 * Prepare TelephonyManager for an unattended reboot. The reboot is
11067 * required to be done shortly after the API is invoked.
11068 */
11069 @Override
11070 @TelephonyManager.PrepareUnattendedRebootResult
11071 public int prepareForUnattendedReboot() {
11072 enforceRebootPermission();
11073
11074 final long identity = Binder.clearCallingIdentity();
11075 try {
11076 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11077 } finally {
11078 Binder.restoreCallingIdentity(identity);
11079 }
11080 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011081
11082 /**
11083 * Request to get the current slicing configuration including URSP rules and
11084 * NSSAIs (configured, allowed and rejected).
11085 *
11086 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11087 */
11088 @Override
11089 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011090 TelephonyPermissions
11091 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11092 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011093
11094 final long identity = Binder.clearCallingIdentity();
11095 try {
11096 Phone phone = getDefaultPhone();
11097 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
11100 }
11101 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011102
11103 /**
11104 * Register an IMS connection state callback
11105 */
11106 @Override
11107 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11108 String callingPackage) {
11109 if (feature == ImsFeature.FEATURE_MMTEL) {
11110 // ImsMmTelManager
11111 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11112 TelephonyPermissions
11113 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11114 mApp, subId, "registerImsStateCallback");
11115 } else if (feature == ImsFeature.FEATURE_RCS) {
11116 // ImsRcsManager or SipDelegateManager
11117 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11118 Binder.getCallingUid(), "registerImsStateCallback",
11119 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11120 Manifest.permission.READ_PRECISE_PHONE_STATE,
11121 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11122 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11123 }
11124
11125 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11126 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11127 "IMS not available on device.");
11128 }
11129
11130 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11131 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11132 }
11133
11134 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11135 if (controller == null) {
11136 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11137 "IMS not available on device.");
11138 }
11139
11140 if (callingPackage == null) {
11141 callingPackage = getCurrentPackageName();
11142 }
11143
11144 final long token = Binder.clearCallingIdentity();
11145 try {
11146 int slotId = getSlotIndexOrException(subId);
11147 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11148 } catch (ImsException e) {
11149 throw new ServiceSpecificException(e.getCode());
11150 } finally {
11151 Binder.restoreCallingIdentity(token);
11152 }
11153 }
11154
11155 /**
11156 * Unregister an IMS connection state callback
11157 */
11158 @Override
11159 public void unregisterImsStateCallback(IImsStateCallback cb) {
11160 final long token = Binder.clearCallingIdentity();
11161 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11162 if (controller == null) {
11163 return;
11164 }
11165 try {
11166 controller.unregisterImsStateCallback(cb);
11167 } finally {
11168 Binder.restoreCallingIdentity(token);
11169 }
11170 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011171
11172 /**
11173 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11174 *
11175 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11176 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11177 * SecurityException.
11178 * If there is current registered network this value will be same as the registered cell
11179 * identity. If the device goes out of service the previous cell identity is cached and
11180 * will be returned. If the cache age of the Cell identity is more than 24 hours
11181 * it will be cleared and null will be returned.
11182 *
11183 */
11184 @Override
11185 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11186 String callingFeatureId) {
11187 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11188 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11189 LocationAccessPolicy.checkLocationPermission(mApp,
11190 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11191 .setCallingPackage(callingPackage)
11192 .setCallingFeatureId(callingFeatureId)
11193 .setCallingPid(Binder.getCallingPid())
11194 .setCallingUid(Binder.getCallingUid())
11195 .setMethod("getLastKnownCellIdentity")
11196 .setLogAsInfo(true)
11197 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11198 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11199 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11200 .build());
11201
11202 boolean hasFinePermission =
11203 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11204 if (!hasFinePermission
11205 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11206 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11207 + "and BIND_CONNECTION_SERVICE permission.");
11208 }
11209
11210 final long identity = Binder.clearCallingIdentity();
11211 try {
11212 Phone phone = getPhone(subId);
11213 if (phone == null) return null;
11214 ServiceStateTracker sst = phone.getServiceStateTracker();
11215 if (sst == null) return null;
11216 return sst.getLastKnownCellIdentity();
11217 } finally {
11218 Binder.restoreCallingIdentity(identity);
11219 }
11220 }
jimsun38340bf2021-10-26 15:01:23 +080011221
11222 /**
11223 * Sets the modem service class Name that Telephony will bind to.
11224 *
11225 * @param serviceName The class name of the modem service.
11226 * @return true if the operation is succeed, otherwise false.
11227 */
11228 public boolean setModemService(String serviceName) {
11229 Log.d(LOG_TAG, "setModemService - " + serviceName);
11230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11232 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11233 "setModemService");
11234 return mPhoneConfigurationManager.setModemService(serviceName);
11235 }
11236
11237 /**
11238 * Return the class name of the currently bounded modem service.
11239 *
11240 * @return the class name of the modem service.
11241 */
11242 public String getModemService() {
11243 String result;
11244 Log.d(LOG_TAG, "getModemService");
11245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11246 TelephonyPermissions
11247 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11248 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11249 "getModemService");
11250 result = mPhoneConfigurationManager.getModemService();
11251 Log.d(LOG_TAG, "result = " + result);
11252 return result;
11253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011254}