blob: 2e4c99b6beecff8e83a7b0c76acb3f651c81985f [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;
joonhunshin35f64142021-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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080032import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000033import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080034import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070035import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070036import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.content.Context;
38import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070039import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070040import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080041import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070042import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.net.Uri;
44import android.os.AsyncResult;
45import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080046import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.Bundle;
48import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070049import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Looper;
51import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080053import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070054import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070055import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080056import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080057import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070058import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070059import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080060import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070062import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070063import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070064import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070065import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080066import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070067import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090068import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080069import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080070import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070071import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070072import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080073import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080074import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070075import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080076import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070077import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080078import android.telephony.CellIdentityCdma;
79import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070081import android.telephony.CellInfoGsm;
82import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070083import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080084import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070085import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070086import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070087import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080088import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070089import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080090import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070091import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080092import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080093import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070094import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080097import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080098import android.telephony.SignalStrengthUpdateRequest;
99import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800100import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800102import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700103import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700104import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800105import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800106import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800107import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000108import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700109import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800111import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800112import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800113import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700114import android.telephony.gba.GbaAuthRequest;
115import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700116import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800117import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000118import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000119import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700120import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700121import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800122import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700123import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800124import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700125import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700127import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800128import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800129import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800130import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800131import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800133import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700134import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800136import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137
Andrew Lee312e8172014-10-23 17:01:36 -0700138import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800139import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800140import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800141import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800142import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700144import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700145import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800146import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700147import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700151import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800152import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800153import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800154import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700155import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000156import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700157import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800158import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800160import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700161import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700162import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700163import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700165import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800166import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700167import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700168import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700169import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700170import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800171import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800172import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700173import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700174import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800176import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800177import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800178import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700179import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700181import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800182import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700183import com.android.internal.telephony.imsphone.ImsPhone;
184import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin35f64142021-09-17 06:33:39 +0000185import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800186import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700187import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800189import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700192import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800193import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000195import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800196import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000197import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800198import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700199import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700200import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800202import com.android.phone.callcomposer.CallComposerPictureManager;
203import com.android.phone.callcomposer.CallComposerPictureTransfer;
204import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700205import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700206import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800207import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700208import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700209import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800210import com.android.services.telephony.TelecomAccountRegistry;
211import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800212import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800213
Hall Liu82694d52020-12-11 18:22:04 -0800214import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700215import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800216import java.io.IOException;
217import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700218import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800221import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800222import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800223import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100224import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800225import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700226import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800228import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800229import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800230import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800231import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
233/**
234 * Implementation of the ITelephony interface.
235 */
Santos Cordon117fee72014-05-16 17:56:12 -0700236public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237 private static final String LOG_TAG = "PhoneInterfaceManager";
238 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
239 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800240 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242 // Message codes used with mMainThreadHandler
243 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700244 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
245 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700246 private static final int CMD_OPEN_CHANNEL = 9;
247 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
248 private static final int CMD_CLOSE_CHANNEL = 11;
249 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800250 private static final int CMD_NV_READ_ITEM = 13;
251 private static final int EVENT_NV_READ_ITEM_DONE = 14;
252 private static final int CMD_NV_WRITE_ITEM = 15;
253 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
254 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
255 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_RESET_MODEM_CONFIG = 19;
257 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800258 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
259 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800260 private static final int CMD_SEND_ENVELOPE = 25;
261 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000262 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
263 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700264 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
265 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
266 private static final int CMD_EXCHANGE_SIM_IO = 31;
267 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800268 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
269 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700270 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
271 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700272 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
273 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700274 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
275 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
276 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
277 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700278 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
279 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
280 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
281 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700282 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800283 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
284 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000285 private static final int CMD_SWITCH_SLOTS = 50;
286 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700287 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
288 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
289 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
290 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
291 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
292 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
293 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
294 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700295 private static final int CMD_GET_ALL_CELL_INFO = 60;
296 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
297 private static final int CMD_GET_CELL_LOCATION = 62;
298 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700299 private static final int CMD_MODEM_REBOOT = 64;
300 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700301 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
302 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800303 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
304 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700305 private static final int CMD_GET_MODEM_STATUS = 70;
306 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700307 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
308 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700309 private static final int CMD_ERASE_MODEM_CONFIG = 74;
310 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800311 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
312 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
313 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
314 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800315 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
316 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800317 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800318 private static final int CMD_GET_CALL_FORWARDING = 83;
319 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
320 private static final int CMD_SET_CALL_FORWARDING = 85;
321 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
322 private static final int CMD_GET_CALL_WAITING = 87;
323 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
324 private static final int CMD_SET_CALL_WAITING = 89;
325 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700326 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
327 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
328 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
329 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700330 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
331 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800332 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
333 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800334 private static final int CMD_SET_DATA_THROTTLING = 99;
335 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800336 private static final int CMD_SET_SIM_POWER = 101;
337 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800338 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
339 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
340 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
341 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800342 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
343 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000344 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800345 private static final int CMD_GET_SLICING_CONFIG = 110;
346 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800347 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700348 private static final int CMD_ENABLE_VONR = 113;
349 private static final int EVENT_ENABLE_VONR_DONE = 114;
350 private static final int CMD_IS_VONR_ENABLED = 115;
351 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800353 // Parameters of select command.
354 private static final int SELECT_COMMAND = 0xA4;
355 private static final int SELECT_P1 = 0x04;
356 private static final int SELECT_P2 = 0;
357 private static final int SELECT_P3 = 0x10;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 /** The singleton instance. */
360 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800361 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800364 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800365 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700366 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700368 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800370 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700372 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800373 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Peter Wangdafb9ac2020-01-15 14:13:38 -0800375 /** User Activity */
376 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800377 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
378
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700379 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
380
Derek Tan97ebb422014-09-05 16:55:38 -0700381 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
382 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800383 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800384 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700385
Michelecea4cf22018-12-21 15:00:11 -0800386 // String to store multi SIM allowed
387 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
388
Derek Tan740e1672017-06-27 14:56:27 -0700389 // The AID of ISD-R.
390 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
391
yinxub1bed742017-04-17 11:45:04 -0700392 private NetworkScanRequestTracker mNetworkScanRequestTracker;
393
David Kelly5e06a7f2018-03-12 14:10:59 +0000394 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
395 private static final int MANUFACTURER_CODE_LENGTH = 8;
396
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800397 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800398 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800399
Derek Tan89e89d42014-07-08 17:00:10 -0700400 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700401 * Experiment flag to enable erase modem config on reset network, default value is false
402 */
403 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
404 "reset_network_erase_modem_config_enabled";
405
Rambo Wang0f050d82021-02-12 11:43:36 -0800406 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
407
Naina Nallurid63128d2019-09-17 14:10:30 -0700408 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700409 * A request object to use for transmitting data to an ICC.
410 */
411 private static final class IccAPDUArgument {
412 public int channel, cla, command, p1, p2, p3;
413 public String data;
414
415 public IccAPDUArgument(int channel, int cla, int command,
416 int p1, int p2, int p3, String data) {
417 this.channel = channel;
418 this.cla = cla;
419 this.command = command;
420 this.p1 = p1;
421 this.p2 = p2;
422 this.p3 = p3;
423 this.data = data;
424 }
425 }
426
427 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700428 * A request object to use for transmitting data to an ICC.
429 */
430 private static final class ManualNetworkSelectionArgument {
431 public OperatorInfo operatorInfo;
432 public boolean persistSelection;
433
434 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
435 this.operatorInfo = operatorInfo;
436 this.persistSelection = persistSelection;
437 }
438 }
439
440 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
442 * request after sending. The main thread will notify the request when it is complete.
443 */
444 private static final class MainThreadRequest {
445 /** The argument to use for the request */
446 public Object argument;
447 /** The result of the request that is run on the main thread */
448 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800449 // The subscriber id that this request applies to. Defaults to
450 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
451 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
Nathan Harold92bed182018-10-12 18:16:49 -0700453 // In cases where subId is unavailable, the caller needs to specify the phone.
454 public Phone phone;
455
vagdeviaf9a5b92018-08-15 16:01:53 -0700456 public WorkSource workSource;
457
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 public MainThreadRequest(Object argument) {
459 this.argument = argument;
460 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800461
Nathan Harold92bed182018-10-12 18:16:49 -0700462 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
463 this.argument = argument;
464 if (phone != null) {
465 this.phone = phone;
466 }
467 this.workSource = workSource;
468 }
469
vagdeviaf9a5b92018-08-15 16:01:53 -0700470 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800471 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800472 if (subId != null) {
473 this.subId = subId;
474 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700475 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 }
478
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800479 private static final class IncomingThirdPartyCallArgs {
480 public final ComponentName component;
481 public final String callId;
482 public final String callerDisplayName;
483
484 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
485 String callerDisplayName) {
486 this.component = component;
487 this.callId = callId;
488 this.callerDisplayName = callerDisplayName;
489 }
490 }
491
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 /**
493 * A handler that processes messages on the main thread in the phone process. Since many
494 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
495 * inbound binder threads to the main thread in the phone process. The Binder thread
496 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
497 * on, which will be notified when the operation completes and will contain the result of the
498 * request.
499 *
500 * <p>If a MainThreadRequest object is provided in the msg.obj field,
501 * note that request.result must be set to something non-null for the calling thread to
502 * unblock.
503 */
504 private final class MainThreadHandler extends Handler {
505 @Override
506 public void handleMessage(Message msg) {
507 MainThreadRequest request;
508 Message onCompleted;
509 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000510 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800512 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513
514 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 case CMD_HANDLE_USSD_REQUEST: {
516 request = (MainThreadRequest) msg.obj;
517 final Phone phone = getPhoneFromRequest(request);
518 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
519 String ussdRequest = ussdObject.first;
520 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700521
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 if (!isUssdApiAllowed(request.subId)) {
523 // Carrier does not support use of this API, return failure.
524 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
525 UssdResponse response = new UssdResponse(ussdRequest, null);
526 Bundle returnData = new Bundle();
527 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
528 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700529
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 request.result = true;
531 notifyRequester(request);
532 return;
533 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700534
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 try {
536 request.result = phone != null
537 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
538 } catch (CallStateException cse) {
539 request.result = false;
540 }
541 // Wake up the requesting thread
542 notifyRequester(request);
543 break;
pkanwar32d516d2016-10-14 19:37:38 -0700544 }
545
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700548 final Phone phone = getPhoneFromRequest(request);
549 request.result = phone != null ?
550 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
551 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000560 uiccPort = getUiccPortFromRequest(request);
561 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 loge("iccTransmitApduLogicalChannel: No UICC");
563 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
567 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000568 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 iccArgument.channel, iccArgument.cla, iccArgument.command,
570 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 break;
574
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
580 } else {
581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800584 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800586 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 } else {
588 loge("iccTransmitApduLogicalChannel: Unknown exception");
589 }
590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
596 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000597 uiccPort = getUiccPortFromRequest(request);
598 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 loge("iccTransmitApduBasicChannel: No UICC");
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
604 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000605 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
607 iccArgument.p3, iccArgument.data, onCompleted);
608 }
609 break;
610
611 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
614 if (ar.exception == null && ar.result != null) {
615 request.result = ar.result;
616 } else {
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
618 if (ar.result == null) {
619 loge("iccTransmitApduBasicChannel: Empty response");
620 } else if (ar.exception instanceof CommandException) {
621 loge("iccTransmitApduBasicChannel: CommandException: " +
622 ar.exception);
623 } else {
624 loge("iccTransmitApduBasicChannel: Unknown exception");
625 }
626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 break;
629
630 case CMD_EXCHANGE_SIM_IO:
631 request = (MainThreadRequest) msg.obj;
632 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000633 uiccPort = getUiccPortFromRequest(request);
634 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 loge("iccExchangeSimIO: No UICC");
636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
640 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000641 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
643 iccArgument.data, onCompleted);
644 }
645 break;
646
647 case EVENT_EXCHANGE_SIM_IO_DONE:
648 ar = (AsyncResult) msg.obj;
649 request = (MainThreadRequest) ar.userObj;
650 if (ar.exception == null && ar.result != null) {
651 request.result = ar.result;
652 } else {
653 request.result = new IccIoResult(0x6f, 0, (byte[])null);
654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 break;
657
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 case CMD_SEND_ENVELOPE:
659 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 loge("sendEnvelopeWithStatus: No UICC");
663 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 } else {
666 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000667 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800669 break;
670
671 case EVENT_SEND_ENVELOPE_DONE:
672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700674 if (ar.exception == null && ar.result != null) {
675 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800676 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700677 request.result = new IccIoResult(0x6F, 0, (byte[])null);
678 if (ar.result == null) {
679 loge("sendEnvelopeWithStatus: Empty response");
680 } else if (ar.exception instanceof CommandException) {
681 loge("sendEnvelopeWithStatus: CommandException: " +
682 ar.exception);
683 } else {
684 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
685 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 break;
689
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 case CMD_OPEN_CHANNEL:
691 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000692 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800693 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000694 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800696 request.result = new IccOpenLogicalChannelResponse(-1,
697 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700698 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 } else {
700 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000701 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800702 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700703 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 break;
705
706 case EVENT_OPEN_CHANNEL_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 int[] result = (int[]) ar.result;
712 int channelId = result[0];
713 byte[] selectResponse = null;
714 if (result.length > 1) {
715 selectResponse = new byte[result.length - 1];
716 for (int i = 1; i < result.length; ++i) {
717 selectResponse[i - 1] = (byte) result[i];
718 }
719 }
720 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700721 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 if (ar.result == null) {
724 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 if (ar.exception != null) {
727 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
728 }
729
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700730 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700731 if (ar.exception instanceof CommandException) {
732 CommandException.Error error =
733 ((CommandException) (ar.exception)).getCommandError();
734 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700735 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700736 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700737 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 }
739 }
740 openChannelResp = new IccOpenLogicalChannelResponse(
741 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700743 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 break;
746
747 case CMD_CLOSE_CHANNEL:
748 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000749 uiccPort = getUiccPortFromRequest(request);
750 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900752 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 } else {
755 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000756 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700757 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 break;
759
760 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800761 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
762 break;
763
764 case CMD_NV_READ_ITEM:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800767 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
768 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800769 break;
770
771 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800774 if (ar.exception == null && ar.result != null) {
775 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800777 request.result = "";
778 if (ar.result == null) {
779 loge("nvReadItem: Empty response");
780 } else if (ar.exception instanceof CommandException) {
781 loge("nvReadItem: CommandException: " +
782 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800784 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 }
786 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 break;
789
Jake Hambye994d462014-02-03 13:10:13 -0800790 case CMD_NV_WRITE_ITEM:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
793 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800794 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700795 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800796 break;
797
798 case EVENT_NV_WRITE_ITEM_DONE:
799 handleNullReturnEvent(msg, "nvWriteItem");
800 break;
801
802 case CMD_NV_WRITE_CDMA_PRL:
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800805 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800806 break;
807
808 case EVENT_NV_WRITE_CDMA_PRL_DONE:
809 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
810 break;
811
chen xu6dac5ab2018-10-26 17:39:23 -0700812 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800813 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700814 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800815 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
chen xu6dac5ab2018-10-26 17:39:23 -0700818 case EVENT_RESET_MODEM_CONFIG_DONE:
819 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800820 break;
821
Sooraj Sasindran37444802020-08-11 10:40:43 -0700822 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
823 request = (MainThreadRequest) msg.obj;
824 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
825 request);
826 Phone phone = getPhoneFromRequest(request);
827 if (phone != null) {
828 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
829 } else {
830 loge("isNRDualConnectivityEnabled: No phone object");
831 request.result = false;
832 notifyRequester(request);
833 }
834 break;
835 }
836
837 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 // request.result must be set to something non-null
844 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700845 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700846 request.result = ar.result;
847 } else {
848 request.result = false;
849 }
850 if (ar.result == null) {
851 loge("isNRDualConnectivityEnabled: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("isNRDualConnectivityEnabled: CommandException: "
854 + ar.exception);
855 } else {
856 loge("isNRDualConnectivityEnabled: Unknown exception");
857 }
858 }
859 notifyRequester(request);
860 break;
861
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700862 case CMD_IS_VONR_ENABLED: {
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
865 request);
866 Phone phone = getPhoneFromRequest(request);
867 if (phone != null) {
868 phone.isVoNrEnabled(onCompleted, request.workSource);
869 } else {
870 loge("isVoNrEnabled: No phone object");
871 request.result = false;
872 notifyRequester(request);
873 }
874 break;
875 }
876
877 case EVENT_IS_VONR_ENABLED_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
883 // request.result must be set to something non-null
884 // for the calling thread to unblock
885 if (ar.result != null) {
886 request.result = ar.result;
887 } else {
888 request.result = false;
889 }
890 if (ar.result == null) {
891 loge("isVoNrEnabled: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("isVoNrEnabled: CommandException: "
894 + ar.exception);
895 } else {
896 loge("isVoNrEnabled: Unknown exception");
897 }
898 }
899 notifyRequester(request);
900 break;
901
Sooraj Sasindran37444802020-08-11 10:40:43 -0700902 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
905 Phone phone = getPhoneFromRequest(request);
906 if (phone != null) {
907 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
908 request.workSource);
909 } else {
910 loge("enableNrDualConnectivity: No phone object");
911 request.result =
912 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
913 notifyRequester(request);
914 }
915 break;
916 }
917
918 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null) {
922 request.result =
923 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
924 } else {
925 request.result =
926 TelephonyManager
927 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
928 if (ar.exception instanceof CommandException) {
929 CommandException.Error error =
930 ((CommandException) (ar.exception)).getCommandError();
931 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
932 request.result =
933 TelephonyManager
934 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000935 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
936 request.result =
937 TelephonyManager
938 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700939 }
940 loge("enableNrDualConnectivity" + ": CommandException: "
941 + ar.exception);
942 } else {
943 loge("enableNrDualConnectivity" + ": Unknown exception");
944 }
945 }
946 notifyRequester(request);
947 break;
948 }
949
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700950 case CMD_ENABLE_VONR: {
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
953 Phone phone = getPhoneFromRequest(request);
954 if (phone != null) {
955 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
956 request.workSource);
957 } else {
958 loge("setVoNrEnabled: No phone object");
959 request.result =
960 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
961 notifyRequester(request);
962 }
963 break;
964 }
965
966 case EVENT_ENABLE_VONR_DONE: {
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception == null) {
970 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
971 } else {
972 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
977 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
978 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
979 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
980 } else {
981 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
982 }
983 loge("setVoNrEnabled" + ": CommandException: "
984 + ar.exception);
985 } else {
986 loge("setVoNrEnabled" + ": Unknown exception");
987 }
988 }
989 notifyRequester(request);
990 break;
991 }
992
SongFerngWang3ef3e072020-12-21 16:41:52 +0800993 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800994 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800995 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
996 request);
997 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800998 break;
999
SongFerngWang3ef3e072020-12-21 16:41:52 +08001000 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 if (ar.exception == null && ar.result != null) {
1004 request.result = ar.result; // Integer
1005 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301006 // request.result must be set to something non-null
1007 // for the calling thread to unblock
1008 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 loge("getAllowedNetworkTypesBitmask: CommandException: "
1013 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 }
1017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001018 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 break;
1020
SongFerngWang3ef3e072020-12-21 16:41:52 +08001021 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001022 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001023 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1024 request);
1025 Pair<Integer, Long> reasonWithNetworkTypes =
1026 (Pair<Integer, Long>) request.argument;
1027 getPhoneFromRequest(request).setAllowedNetworkTypes(
1028 reasonWithNetworkTypes.first,
1029 reasonWithNetworkTypes.second,
1030 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 break;
1032
SongFerngWang3ef3e072020-12-21 16:41:52 +08001033 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1034 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001035 break;
1036
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001037 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1038 request = (MainThreadRequest)msg.obj;
1039 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001040 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001041 break;
1042
1043 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1044 ar = (AsyncResult)msg.obj;
1045 request = (MainThreadRequest)ar.userObj;
1046 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001047 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001048 break;
1049
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001050 case CMD_SET_VOICEMAIL_NUMBER:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1053 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001054 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1055 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001056 break;
1057
1058 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1059 handleNullReturnEvent(msg, "setVoicemailNumber");
1060 break;
1061
Stuart Scott54788802015-03-30 13:18:01 -07001062 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1063 request = (MainThreadRequest) msg.obj;
1064 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1065 request);
1066 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1067 break;
1068
1069 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1070 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1071 break;
1072
Shishir Agrawal302c8692015-06-19 13:49:39 -07001073 case CMD_PERFORM_NETWORK_SCAN:
1074 request = (MainThreadRequest) msg.obj;
1075 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1076 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1077 break;
1078
Hall Liu27d24262020-09-18 19:04:59 -07001079 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001082 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1083 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1084 request.argument;
1085 int callForwardingReason = args.first;
1086 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001087 break;
Hall Liu27d24262020-09-18 19:04:59 -07001088 }
1089 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001092 TelephonyManager.CallForwardingInfoCallback callback =
1093 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1094 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001096 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001097 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1098 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1099 // Service Class is a bit mask per 3gpp 27.007. Search for
1100 // any service for voice call.
1101 if ((callForwardInfo.serviceClass
1102 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001103 callForwardingInfo = new CallForwardingInfo(
1104 callForwardInfo.status
1105 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001106 callForwardInfo.reason,
1107 callForwardInfo.number,
1108 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001109 break;
1110 }
1111 }
1112 // Didn't find a call forward info for voice call.
1113 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001114 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1115 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001116 }
Hall Liu27d24262020-09-18 19:04:59 -07001117 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001118 } else {
1119 if (ar.result == null) {
1120 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1121 }
1122 if (ar.exception != null) {
1123 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1124 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001125 int errorCode = TelephonyManager
1126 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001131 errorCode = TelephonyManager
1132 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001133 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001134 errorCode = TelephonyManager
1135 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001136 }
1137 }
Hall Liu27d24262020-09-18 19:04:59 -07001138 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001139 }
Shuo Qian4a594052020-01-23 11:59:30 -08001140 break;
Hall Liu27d24262020-09-18 19:04:59 -07001141 }
Shuo Qian4a594052020-01-23 11:59:30 -08001142
Hall Liu27d24262020-09-18 19:04:59 -07001143 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001146 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001147 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001148 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1149 request.argument).first;
1150 request.phone.setCallForwardingOption(
1151 callForwardingInfoToSet.isEnabled()
1152 ? CommandsInterface.CF_ACTION_ENABLE
1153 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001154 callForwardingInfoToSet.getReason(),
1155 callForwardingInfoToSet.getNumber(),
1156 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1157 break;
Hall Liu27d24262020-09-18 19:04:59 -07001158 }
Shuo Qian4a594052020-01-23 11:59:30 -08001159
Hall Liu27d24262020-09-18 19:04:59 -07001160 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001163 Consumer<Integer> callback =
1164 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1165 request.argument).second;
1166 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001167 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001168 int errorCode = TelephonyManager.CallForwardingInfoCallback
1169 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001170 if (ar.exception instanceof CommandException) {
1171 CommandException.Error error =
1172 ((CommandException) (ar.exception)).getCommandError();
1173 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001174 errorCode = TelephonyManager.CallForwardingInfoCallback
1175 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001176 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001177 errorCode = TelephonyManager.CallForwardingInfoCallback
1178 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001179 }
1180 }
1181 callback.accept(errorCode);
1182 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001183 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001184 }
Shuo Qian4a594052020-01-23 11:59:30 -08001185 break;
Hall Liu27d24262020-09-18 19:04:59 -07001186 }
Shuo Qian4a594052020-01-23 11:59:30 -08001187
Hall Liu27d24262020-09-18 19:04:59 -07001188 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001189 request = (MainThreadRequest) msg.obj;
1190 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1191 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1192 break;
Hall Liu27d24262020-09-18 19:04:59 -07001193 }
Shuo Qian4a594052020-01-23 11:59:30 -08001194
Hall Liu27d24262020-09-18 19:04:59 -07001195 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001198 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1200 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 // Service Class is a bit mask per 3gpp 27.007.
1203 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001204 if (callForwardResults.length > 1
1205 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001206 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001207 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001208 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1209 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001211 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 }
1213 } else {
1214 if (ar.result == null) {
1215 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1216 }
1217 if (ar.exception != null) {
1218 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1219 }
1220 if (ar.exception instanceof CommandException) {
1221 CommandException.Error error =
1222 ((CommandException) (ar.exception)).getCommandError();
1223 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1224 callForwardingStatus =
1225 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1226 }
1227 }
1228 }
Hall Liu27d24262020-09-18 19:04:59 -07001229 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 break;
Hall Liu27d24262020-09-18 19:04:59 -07001231 }
Shuo Qian4a594052020-01-23 11:59:30 -08001232
Hall Liu27d24262020-09-18 19:04:59 -07001233 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001234 request = (MainThreadRequest) msg.obj;
1235 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001236 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1237 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 break;
Hall Liu27d24262020-09-18 19:04:59 -07001239 }
Shuo Qian4a594052020-01-23 11:59:30 -08001240
Hall Liu27d24262020-09-18 19:04:59 -07001241 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 ar = (AsyncResult) msg.obj;
1243 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001244 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1245 Consumer<Integer> callback =
1246 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1247 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001248 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001249 if (ar.exception instanceof CommandException) {
1250 CommandException.Error error =
1251 ((CommandException) (ar.exception)).getCommandError();
1252 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1253 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1254 } else {
1255 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1256 }
1257 } else {
1258 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1259 }
1260 } else {
1261 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1262 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001266 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
1269 CellNetworkScanResult cellScanResult;
1270 if (ar.exception == null && ar.result != null) {
1271 cellScanResult = new CellNetworkScanResult(
1272 CellNetworkScanResult.STATUS_SUCCESS,
1273 (List<OperatorInfo>) ar.result);
1274 } else {
1275 if (ar.result == null) {
1276 loge("getCellNetworkScanResults: Empty response");
1277 }
1278 if (ar.exception != null) {
1279 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1280 }
1281 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1282 if (ar.exception instanceof CommandException) {
1283 CommandException.Error error =
1284 ((CommandException) (ar.exception)).getCommandError();
1285 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1286 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1287 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1288 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1289 }
1290 }
1291 cellScanResult = new CellNetworkScanResult(errorCode, null);
1292 }
1293 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001294 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001295 break;
1296
1297 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1298 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001299 ManualNetworkSelectionArgument selArg =
1300 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001301 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1302 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001303 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1304 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001305 break;
1306
1307 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 if (ar.exception == null) {
1311 request.result = true;
1312 } else {
1313 request.result = false;
1314 loge("setNetworkSelectionModeManual " + ar.exception);
1315 }
1316 notifyRequester(request);
1317 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001318 break;
1319
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001320 case CMD_GET_MODEM_ACTIVITY_INFO:
1321 request = (MainThreadRequest) msg.obj;
1322 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001323 if (defaultPhone != null) {
1324 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001325 } else {
1326 ResultReceiver result = (ResultReceiver) request.argument;
1327 Bundle bundle = new Bundle();
1328 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001329 new ModemActivityInfo(0, 0, 0,
1330 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001331 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001332 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001333 break;
1334
Hall Liud0f208c2020-10-14 16:54:44 -07001335 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001338 ResultReceiver result = (ResultReceiver) request.argument;
1339
Hall Liud0f208c2020-10-14 16:54:44 -07001340 ModemActivityInfo ret = null;
1341 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001342 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 // Update the last modem activity info and the result of the request.
1344 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1345 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001346 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001347 int[] txTimeMs = info.getTransmitTimeMillis();
1348 int[] lastModemTxTimeMs = mLastModemActivityInfo
1349 .getTransmitTimeMillis();
1350 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1351 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1352 }
Hall Liu49656c02020-10-09 19:00:11 -07001353 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001354 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1355 + mLastModemActivityInfo.getSleepTimeMillis());
1356 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1357 + mLastModemActivityInfo.getIdleTimeMillis());
1358 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1359 mLastModemActivityInfo.setReceiveTimeMillis(
1360 info.getReceiveTimeMillis()
1361 + mLastModemActivityInfo.getReceiveTimeMillis());
1362 }
Hall Liu49656c02020-10-09 19:00:11 -07001363 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001364 mLastModemActivityInfo.getSleepTimeMillis(),
1365 mLastModemActivityInfo.getIdleTimeMillis(),
1366 mLastModemActivityInfo.getTransmitTimeMillis(),
1367 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001368 } else {
1369 if (ar.result == null) {
1370 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001371 error = TelephonyManager.ModemActivityInfoException
1372 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001373 } else if (ar.exception instanceof CommandException) {
1374 loge("queryModemActivityInfo: CommandException: " +
1375 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001376 error = TelephonyManager.ModemActivityInfoException
1377 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001378 } else {
1379 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001380 error = TelephonyManager.ModemActivityInfoException
1381 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001382 }
1383 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001385 if (ret != null) {
1386 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1387 } else {
1388 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1389 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001390 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001393 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001394
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 case CMD_SET_ALLOWED_CARRIERS:
1396 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001397 CarrierRestrictionRules argument =
1398 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001399 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001400 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001401 break;
1402
1403 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
1406 if (ar.exception == null && ar.result != null) {
1407 request.result = ar.result;
1408 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001409 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1410 if (ar.exception instanceof CommandException) {
1411 loge("setAllowedCarriers: CommandException: " + ar.exception);
1412 CommandException.Error error =
1413 ((CommandException) (ar.exception)).getCommandError();
1414 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1415 request.result =
1416 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1417 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 } else {
1419 loge("setAllowedCarriers: Unknown exception");
1420 }
1421 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001422 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001423 break;
1424
1425 case CMD_GET_ALLOWED_CARRIERS:
1426 request = (MainThreadRequest) msg.obj;
1427 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001428 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001429 break;
1430
1431 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1432 ar = (AsyncResult) msg.obj;
1433 request = (MainThreadRequest) ar.userObj;
1434 if (ar.exception == null && ar.result != null) {
1435 request.result = ar.result;
1436 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001437 request.result = new IllegalStateException(
1438 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001439 if (ar.result == null) {
1440 loge("getAllowedCarriers: Empty response");
1441 } else if (ar.exception instanceof CommandException) {
1442 loge("getAllowedCarriers: CommandException: " +
1443 ar.exception);
1444 } else {
1445 loge("getAllowedCarriers: Unknown exception");
1446 }
1447 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001448 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001449 break;
1450
Nathan Haroldb3014052017-01-25 15:57:32 -08001451 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 if (ar.exception == null && ar.result != null) {
1455 request.result = ar.result;
1456 } else {
1457 request.result = new IllegalArgumentException(
1458 "Failed to retrieve Forbidden Plmns");
1459 if (ar.result == null) {
1460 loge("getForbiddenPlmns: Empty response");
1461 } else {
1462 loge("getForbiddenPlmns: Unknown exception");
1463 }
1464 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001466 break;
1467
1468 case CMD_GET_FORBIDDEN_PLMNS:
1469 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001470 uiccPort = getUiccPortFromRequest(request);
1471 if (uiccPort == null) {
1472 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001473 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001474 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001475 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001476 break;
1477 }
1478 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001479 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001480 if (uiccApp == null) {
1481 loge("getForbiddenPlmns() no app with specified type -- "
1482 + appType);
1483 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001484 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001485 break;
1486 } else {
1487 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1488 + " specified type -- " + appType);
1489 }
1490 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1491 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1492 onCompleted);
1493 break;
1494
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001495 case CMD_SWITCH_SLOTS:
1496 request = (MainThreadRequest) msg.obj;
1497 int[] physicalSlots = (int[]) request.argument;
1498 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1499 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1500 break;
1501
1502 case EVENT_SWITCH_SLOTS_DONE:
1503 ar = (AsyncResult) msg.obj;
1504 request = (MainThreadRequest) ar.userObj;
1505 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001506 notifyRequester(request);
1507 break;
1508 case CMD_GET_NETWORK_SELECTION_MODE:
1509 request = (MainThreadRequest) msg.obj;
1510 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1511 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1512 break;
1513
1514 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception != null) {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1519 } else {
1520 int mode = ((int[]) ar.result)[0];
1521 if (mode == 0) {
1522 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1523 } else {
1524 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1525 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001526 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001527 notifyRequester(request);
1528 break;
1529 case CMD_GET_CDMA_ROAMING_MODE:
1530 request = (MainThreadRequest) msg.obj;
1531 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1532 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1533 break;
1534 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception != null) {
1538 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1539 } else {
1540 request.result = ((int[]) ar.result)[0];
1541 }
1542 notifyRequester(request);
1543 break;
1544 case CMD_SET_CDMA_ROAMING_MODE:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1547 int mode = (int) request.argument;
1548 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1549 break;
1550 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 request.result = ar.exception == null;
1554 notifyRequester(request);
1555 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001556 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1559 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1560 break;
1561 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1562 ar = (AsyncResult) msg.obj;
1563 request = (MainThreadRequest) ar.userObj;
1564 if (ar.exception != null) {
1565 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1566 } else {
1567 request.result = ((int[]) ar.result)[0];
1568 }
1569 notifyRequester(request);
1570 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1574 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001575 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1576 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001577 break;
1578 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 request.result = ar.exception == null;
1582 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001583 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 case CMD_GET_ALL_CELL_INFO:
1585 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001586 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001587 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001588 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001589 case EVENT_GET_ALL_CELL_INFO_DONE:
1590 ar = (AsyncResult) msg.obj;
1591 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001592 // If a timeout occurs, the response will be null
1593 request.result = (ar.exception == null && ar.result != null)
1594 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001595 synchronized (request) {
1596 request.notifyAll();
1597 }
1598 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001599 case CMD_REQUEST_CELL_INFO_UPDATE:
1600 request = (MainThreadRequest) msg.obj;
1601 request.phone.requestCellInfoUpdate(request.workSource,
1602 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1603 break;
1604 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1608 try {
1609 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001611 cb.onError(
1612 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1613 ar.exception.getClass().getName(),
1614 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001615 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001616 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001617 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001618 } else {
1619 // use the result as returned
1620 cb.onCellInfo((List<CellInfo>) ar.result);
1621 }
1622 } catch (RemoteException re) {
1623 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1624 }
1625 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001626 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001627 request = (MainThreadRequest) msg.obj;
1628 WorkSource ws = (WorkSource) request.argument;
1629 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001630 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001631 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001632 }
1633 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001634 ar = (AsyncResult) msg.obj;
1635 request = (MainThreadRequest) ar.userObj;
1636 if (ar.exception == null) {
1637 request.result = ar.result;
1638 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001639 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001640 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001641 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 }
1643
1644 synchronized (request) {
1645 request.notifyAll();
1646 }
1647 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001648 }
chen xu6dac5ab2018-10-26 17:39:23 -07001649 case CMD_MODEM_REBOOT:
1650 request = (MainThreadRequest) msg.obj;
1651 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001652 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001653 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001654 case EVENT_CMD_MODEM_REBOOT_DONE:
1655 handleNullReturnEvent(msg, "rebootModem");
1656 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001657 case CMD_REQUEST_ENABLE_MODEM:
1658 request = (MainThreadRequest) msg.obj;
1659 boolean enable = (boolean) request.argument;
1660 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001661 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001662 PhoneConfigurationManager.getInstance()
1663 .enablePhone(request.phone, enable, onCompleted);
1664 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001665 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001669 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001670 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001671 if ((boolean) request.result) {
1672 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1673 updateModemStateMetrics();
1674 } else {
1675 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1676 + ar.exception);
1677 }
1678 notifyRequester(request);
1679 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001680 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001681 case CMD_GET_MODEM_STATUS:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1684 PhoneConfigurationManager.getInstance()
1685 .getPhoneStatusFromModem(request.phone, onCompleted);
1686 break;
1687 case EVENT_GET_MODEM_STATUS_DONE:
1688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 int id = request.phone.getPhoneId();
1691 if (ar.exception == null && ar.result != null) {
1692 request.result = ar.result;
1693 //update the cache as modem status has changed
1694 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1695 (boolean) request.result);
1696 } else {
1697 // Return true if modem status cannot be retrieved. For most cases,
1698 // modem status is on. And for older version modems, GET_MODEM_STATUS
1699 // and disable modem are not supported. Modem is always on.
1700 // TODO: this should be fixed in R to support a third
1701 // status UNKNOWN b/131631629
1702 request.result = true;
1703 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1704 + ar.exception);
1705 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001706 notifyRequester(request);
1707 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001708 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1711 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1712 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1713 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1714 break;
1715 }
1716 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1720 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1721 args.second.accept(ar.exception == null);
1722 notifyRequester(request);
1723 break;
1724 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001725 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1728 Phone phone = getPhoneFromRequest(request);
1729 if (phone != null) {
1730 phone.getSystemSelectionChannels(onCompleted);
1731 } else {
1732 loge("getSystemSelectionChannels: No phone object");
1733 request.result = new ArrayList<RadioAccessSpecifier>();
1734 notifyRequester(request);
1735 }
1736 break;
1737 }
1738 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1739 ar = (AsyncResult) msg.obj;
1740 request = (MainThreadRequest) ar.userObj;
1741 if (ar.exception == null && ar.result != null) {
1742 request.result = ar.result;
1743 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001744 request.result = new IllegalStateException(
1745 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001746 if (ar.result == null) {
1747 loge("getSystemSelectionChannels: Empty response");
1748 } else {
1749 loge("getSystemSelectionChannels: Unknown exception");
1750 }
1751 }
1752 notifyRequester(request);
1753 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001754 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 if (ar.exception == null && ar.result != null) {
1758 request.result = ar.result;
1759 } else {
1760 request.result = -1;
1761 loge("Failed to set Forbidden Plmns");
1762 if (ar.result == null) {
1763 loge("setForbidenPlmns: Empty response");
1764 } else if (ar.exception != null) {
1765 loge("setForbiddenPlmns: Exception: " + ar.exception);
1766 request.result = -1;
1767 } else {
1768 loge("setForbiddenPlmns: Unknown exception");
1769 }
1770 }
1771 notifyRequester(request);
1772 break;
1773 case CMD_SET_FORBIDDEN_PLMNS:
1774 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001775 uiccPort = getUiccPortFromRequest(request);
1776 if (uiccPort == null) {
1777 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001778 request.result = -1;
1779 notifyRequester(request);
1780 break;
1781 }
1782 Pair<Integer, List<String>> setFplmnsArgs =
1783 (Pair<Integer, List<String>>) request.argument;
1784 appType = setFplmnsArgs.first;
1785 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001786 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001787 if (uiccApp == null) {
1788 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1789 request.result = -1;
1790 loge("Failed to get UICC App");
1791 notifyRequester(request);
1792 } else {
1793 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1794 ((SIMRecords) uiccApp.getIccRecords())
1795 .setForbiddenPlmns(onCompleted, fplmns);
1796 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001797 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001798 case CMD_ERASE_MODEM_CONFIG:
1799 request = (MainThreadRequest) msg.obj;
1800 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1801 defaultPhone.eraseModemConfig(onCompleted);
1802 break;
1803 case EVENT_ERASE_MODEM_CONFIG_DONE:
1804 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001805 break;
zoey chene02881a2019-12-30 16:11:23 +08001806
Kai Shif70f46f2021-03-03 13:59:46 -08001807 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1808 request = (MainThreadRequest) msg.obj;
1809 request.result = defaultPhone.eraseDataInSharedPreferences();
1810 notifyRequester(request);
1811 break;
1812
zoey chene02881a2019-12-30 16:11:23 +08001813 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1816 Pair<String, String> changed = (Pair<String, String>) request.argument;
1817 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1818 changed.first, changed.second, onCompleted);
1819 break;
1820 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1821 ar = (AsyncResult) msg.obj;
1822 request = (MainThreadRequest) ar.userObj;
1823 if (ar.exception == null) {
1824 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001825 // If the operation is successful, update the PIN storage
1826 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1827 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001828 UiccController.getInstance().getPinStorage()
1829 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001830 } else {
1831 request.result = msg.arg1;
1832 }
1833 notifyRequester(request);
1834 break;
1835
Michele Berionne5e411512020-11-13 02:36:59 +00001836 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001837 request = (MainThreadRequest) msg.obj;
1838 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1839 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1840 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1841 enabled.first, enabled.second, onCompleted);
1842 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 }
zoey chene02881a2019-12-30 16:11:23 +08001844 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 if (ar.exception == null) {
1848 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001849 // If the operation is successful, update the PIN storage
1850 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1851 int phoneId = getPhoneFromRequest(request).getPhoneId();
1852 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001853 UiccController.getInstance().getPinStorage()
1854 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001855 } else {
1856 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1857 }
zoey chene02881a2019-12-30 16:11:23 +08001858 } else {
1859 request.result = msg.arg1;
1860 }
Michele Berionne5e411512020-11-13 02:36:59 +00001861
1862
zoey chene02881a2019-12-30 16:11:23 +08001863 notifyRequester(request);
1864 break;
1865
Peter Wangdafb9ac2020-01-15 14:13:38 -08001866 case MSG_NOTIFY_USER_ACTIVITY:
1867 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001868 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001869 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1870 getDefaultPhone().getContext().sendBroadcastAsUser(
1871 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1872 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001873
1874 case CMD_SET_DATA_THROTTLING: {
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1877 DataThrottlingRequest dataThrottlingRequest =
1878 (DataThrottlingRequest) request.argument;
1879 Phone phone = getPhoneFromRequest(request);
1880 if (phone != null) {
1881 phone.setDataThrottling(onCompleted,
1882 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1883 dataThrottlingRequest.getCompletionDurationMillis());
1884 } else {
1885 loge("setDataThrottling: No phone object");
1886 request.result =
1887 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1888 notifyRequester(request);
1889 }
1890
1891 break;
1892 }
1893 case EVENT_SET_DATA_THROTTLING_DONE:
1894 ar = (AsyncResult) msg.obj;
1895 request = (MainThreadRequest) ar.userObj;
1896
1897 if (ar.exception == null) {
1898 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1899 } else if (ar.exception instanceof CommandException) {
1900 loge("setDataThrottling: CommandException: " + ar.exception);
1901 CommandException.Error error =
1902 ((CommandException) (ar.exception)).getCommandError();
1903
1904 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1905 request.result = TelephonyManager
1906 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1907 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1908 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001909 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1910 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001911 } else {
1912 request.result =
1913 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1914 }
1915 } else {
1916 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1917 }
1918 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1919 notifyRequester(request);
1920 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001921
1922 case CMD_SET_SIM_POWER: {
1923 request = (MainThreadRequest) msg.obj;
1924 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1925 request = (MainThreadRequest) msg.obj;
1926 int stateToSet =
1927 ((Pair<Integer, IIntegerConsumer>)
1928 request.argument).first;
1929 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1930 break;
1931 }
1932 case EVENT_SET_SIM_POWER_DONE: {
1933 ar = (AsyncResult) msg.obj;
1934 request = (MainThreadRequest) ar.userObj;
1935 IIntegerConsumer callback =
1936 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1937 if (ar.exception != null) {
1938 loge("setSimPower exception: " + ar.exception);
1939 int errorCode = TelephonyManager.CallForwardingInfoCallback
1940 .RESULT_ERROR_UNKNOWN;
1941 if (ar.exception instanceof CommandException) {
1942 CommandException.Error error =
1943 ((CommandException) (ar.exception)).getCommandError();
1944 if (error == CommandException.Error.SIM_ERR) {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1946 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1947 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1948 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1949 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1950 } else {
1951 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1952 }
1953 }
1954 try {
1955 callback.accept(errorCode);
1956 } catch (RemoteException e) {
1957 // Ignore if the remote process is no longer available to call back.
1958 Log.w(LOG_TAG, "setSimPower: callback not available.");
1959 }
1960 } else {
1961 try {
1962 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1963 } catch (RemoteException e) {
1964 // Ignore if the remote process is no longer available to call back.
1965 Log.w(LOG_TAG, "setSimPower: callback not available.");
1966 }
1967 }
1968 break;
1969 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001970 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1971 request = (MainThreadRequest) msg.obj;
1972
1973 final Phone phone = getPhoneFromRequest(request);
1974 if (phone == null || phone.getServiceStateTracker() == null) {
1975 request.result = new IllegalStateException("Phone or SST is null");
1976 notifyRequester(request);
1977 break;
1978 }
1979
1980 Pair<Integer, SignalStrengthUpdateRequest> pair =
1981 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1982 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1983 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001984 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001985 request.subId, pair.first /*callingUid*/,
1986 pair.second /*request*/, onCompleted);
1987 break;
1988 }
1989 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1990 ar = (AsyncResult) msg.obj;
1991 request = (MainThreadRequest) ar.userObj;
1992 // request.result will be the exception of ar if present, true otherwise.
1993 // Be cautious not to leave result null which will wait() forever
1994 request.result = ar.exception != null ? ar.exception : true;
1995 notifyRequester(request);
1996 break;
1997 }
1998 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1999 request = (MainThreadRequest) msg.obj;
2000
2001 Phone phone = getPhoneFromRequest(request);
2002 if (phone == null || phone.getServiceStateTracker() == null) {
2003 request.result = new IllegalStateException("Phone or SST is null");
2004 notifyRequester(request);
2005 break;
2006 }
2007
2008 Pair<Integer, SignalStrengthUpdateRequest> pair =
2009 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2010 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2011 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002012 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002013 request.subId, pair.first /*callingUid*/,
2014 pair.second /*request*/, onCompleted);
2015 break;
2016 }
2017 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2018 ar = (AsyncResult) msg.obj;
2019 request = (MainThreadRequest) ar.userObj;
2020 request.result = ar.exception != null ? ar.exception : true;
2021 notifyRequester(request);
2022 break;
2023 }
Jordan Liu109698e2020-11-24 14:50:34 -08002024
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002025 case CMD_GET_SLICING_CONFIG: {
2026 request = (MainThreadRequest) msg.obj;
2027 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2028 request.phone.getSlicingConfig(onCompleted);
2029 break;
2030 }
2031 case EVENT_GET_SLICING_CONFIG_DONE: {
2032 ar = (AsyncResult) msg.obj;
2033 request = (MainThreadRequest) ar.userObj;
2034 ResultReceiver result = (ResultReceiver) request.argument;
2035
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002036 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002037 Bundle bundle = new Bundle();
2038 int resultCode = 0;
2039 if (ar.exception != null) {
2040 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2041 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002043 } else if (ar.result == null) {
2044 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002045 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002046 } else {
2047 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002048 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2049 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002050 }
2051
2052 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002053 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002054 }
2055 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2056 result.send(resultCode, bundle);
2057 notifyRequester(request);
2058 break;
2059 }
2060
Michele Berionne5e411512020-11-13 02:36:59 +00002061 case CMD_PREPARE_UNATTENDED_REBOOT:
2062 request = (MainThreadRequest) msg.obj;
2063 request.result =
2064 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2065 notifyRequester(request);
2066 break;
2067
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 default:
2069 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2070 break;
2071 }
2072 }
Jake Hambye994d462014-02-03 13:10:13 -08002073
Pengquan Menga1bb6272018-09-06 09:59:22 -07002074 private void notifyRequester(MainThreadRequest request) {
2075 synchronized (request) {
2076 request.notifyAll();
2077 }
2078 }
2079
Jake Hambye994d462014-02-03 13:10:13 -08002080 private void handleNullReturnEvent(Message msg, String command) {
2081 AsyncResult ar = (AsyncResult) msg.obj;
2082 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2083 if (ar.exception == null) {
2084 request.result = true;
2085 } else {
2086 request.result = false;
2087 if (ar.exception instanceof CommandException) {
2088 loge(command + ": CommandException: " + ar.exception);
2089 } else {
2090 loge(command + ": Unknown exception");
2091 }
2092 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002093 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
2097 /**
2098 * Posts the specified command to be executed on the main thread,
2099 * waits for the request to complete, and returns the result.
2100 * @see #sendRequestAsync
2101 */
2102 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002103 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2104 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002105 }
2106
2107 /**
2108 * Posts the specified command to be executed on the main thread,
2109 * waits for the request to complete, and returns the result.
2110 * @see #sendRequestAsync
2111 */
2112 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2113 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002114 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002115 }
2116
2117 /**
2118 * Posts the specified command to be executed on the main thread,
2119 * waits for the request to complete, and returns the result.
2120 * @see #sendRequestAsync
2121 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002122 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002123 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2124 }
2125
2126 /**
2127 * Posts the specified command to be executed on the main thread,
2128 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2129 * if not timeout or null otherwise.
2130 * @see #sendRequestAsync
2131 */
2132 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2133 long timeoutInMs) {
2134 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002135 }
2136
2137 /**
2138 * Posts the specified command to be executed on the main thread,
2139 * waits for the request to complete, and returns the result.
2140 * @see #sendRequestAsync
2141 */
Nathan Harold92bed182018-10-12 18:16:49 -07002142 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002143 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002144 }
2145
2146 /**
2147 * Posts the specified command to be executed on the main thread,
2148 * waits for the request to complete, and returns the result.
2149 * @see #sendRequestAsync
2150 */
2151 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002152 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2153 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002154 }
2155
2156 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002157 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2158 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2159 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002160 * @see #sendRequestAsync
2161 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002162 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2163 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2165 throw new RuntimeException("This method will deadlock if called from the main thread.");
2166 }
2167
Nathan Harold92bed182018-10-12 18:16:49 -07002168 MainThreadRequest request = null;
2169 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2170 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2171 } else if (phone != null) {
2172 request = new MainThreadRequest(argument, phone, workSource);
2173 } else {
2174 request = new MainThreadRequest(argument, subId, workSource);
2175 }
2176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 Message msg = mMainThreadHandler.obtainMessage(command, request);
2178 msg.sendToTarget();
2179
Rambo Wang0f050d82021-02-12 11:43:36 -08002180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 if (timeoutInMs >= 0) {
2183 // Wait for at least timeoutInMs before returning null request result
2184 long now = SystemClock.elapsedRealtime();
2185 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002186 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002187 try {
2188 request.wait(deadline - now);
2189 } catch (InterruptedException e) {
2190 // Do nothing, go back and check if request is completed or timeout
2191 } finally {
2192 now = SystemClock.elapsedRealtime();
2193 }
2194 }
2195 } else {
2196 // Wait for the request to complete
2197 while (request.result == null) {
2198 try {
2199 request.wait();
2200 } catch (InterruptedException e) {
2201 // Do nothing, go back and wait until the request is complete
2202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204 }
2205 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002206 if (request.result == null) {
2207 Log.wtf(LOG_TAG,
2208 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 return request.result;
2211 }
2212
2213 /**
2214 * Asynchronous ("fire and forget") version of sendRequest():
2215 * Posts the specified command to be executed on the main thread, and
2216 * returns immediately.
2217 * @see #sendRequest
2218 */
2219 private void sendRequestAsync(int command) {
2220 mMainThreadHandler.sendEmptyMessage(command);
2221 }
2222
2223 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002224 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002226 */
2227 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 sendRequestAsync(command, argument, null, null);
2229 }
2230
2231 /**
2232 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2233 * @see {@link #sendRequest(int,Object)}
2234 */
2235 private void sendRequestAsync(
2236 int command, Object argument, Phone phone, WorkSource workSource) {
2237 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002238 Message msg = mMainThreadHandler.obtainMessage(command, request);
2239 msg.sendToTarget();
2240 }
2241
2242 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 * Initialize the singleton PhoneInterfaceManager instance.
2244 * This is only done once, at startup, from PhoneApp.onCreate().
2245 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002246 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 synchronized (PhoneInterfaceManager.class) {
2248 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002249 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 } else {
2251 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2252 }
2253 return sInstance;
2254 }
2255 }
2256
2257 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002258 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002261 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002262 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002264 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002266 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002267 mTelephonySharedPreferences =
2268 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002269 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002270 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002271 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002272 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 publish();
2275 }
2276
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002277 private Phone getDefaultPhone() {
2278 Phone thePhone = getPhone(getDefaultSubscription());
2279 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2280 }
2281
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 private void publish() {
2283 if (DBG) log("publish: " + this);
2284
Peter Wangc035ce42020-01-08 21:00:22 -08002285 TelephonyFrameworkInitializer
2286 .getTelephonyServiceManager()
2287 .getTelephonyServiceRegisterer()
2288 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
Stuart Scott584921c2015-01-15 17:10:34 -08002291 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002292 if (request.phone != null) {
2293 return request.phone;
2294 } else {
2295 return getPhoneFromSubId(request.subId);
2296 }
2297 }
2298
2299 private Phone getPhoneFromSubId(int subId) {
2300 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2301 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002302 }
2303
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002304 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002305 Phone phone = getPhoneFromRequest(request);
2306 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002307 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002308 }
2309
Wink Saville36469e72014-06-11 15:17:00 -07002310 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002311 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002312 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314
Kai Shif70f46f2021-03-03 13:59:46 -08002315 private void sendEraseModemConfig(@NonNull Phone phone) {
2316 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2317 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2318 }
2319
2320 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2321 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2322 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002323 }
2324
Peter Wang44b186e2020-01-13 23:33:09 -08002325 private boolean isImsAvailableOnDevice() {
2326 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2327 if (pm == null) {
2328 // For some reason package manger is not available.. This will fail internally anyway,
2329 // so do not throw error and allow.
2330 return true;
2331 }
2332 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2333 }
2334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002336 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002337 }
2338
Wink Savilleb564aae2014-10-23 10:18:09 -07002339 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 if (DBG) log("dial: " + number);
2341 // No permission check needed here: This is just a wrapper around the
2342 // ACTION_DIAL intent, which is available to any app since it puts up
2343 // the UI before it does anything.
2344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 String url = createTelUrl(number);
2348 if (url == null) {
2349 return;
2350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352 // PENDING: should we just silently fail if phone is offhook or ringing?
2353 PhoneConstants.State state = mCM.getState(subId);
2354 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2355 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2356 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2357 mApp.startActivity(intent);
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 }
2362 }
2363
2364 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002365 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Wink Savilleb564aae2014-10-23 10:18:09 -07002368 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 if (DBG) log("call: " + number);
2370
2371 // This is just a wrapper around the ACTION_CALL intent, but we still
2372 // need to do a permission check since we're calling startActivity()
2373 // from the context of the phone app.
2374 enforceCallPermission();
2375
Jordan Liu1617b712019-07-10 15:06:26 -07002376 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 != AppOpsManager.MODE_ALLOWED) {
2378 return;
2379 }
2380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 String url = createTelUrl(number);
2384 if (url == null) {
2385 return;
2386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388 boolean isValid = false;
2389 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2390 if (slist != null) {
2391 for (SubscriptionInfo subInfoRecord : slist) {
2392 if (subInfoRecord.getSubscriptionId() == subId) {
2393 isValid = true;
2394 break;
2395 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002396 }
Wink Saville08874612014-08-31 19:19:58 -07002397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 if (!isValid) {
2399 return;
2400 }
Wink Saville08874612014-08-31 19:19:58 -07002401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002402 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2403 intent.putExtra(SUBSCRIPTION_KEY, subId);
2404 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2405 mApp.startActivity(intent);
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410
Wink Savilleb564aae2014-10-23 10:18:09 -07002411 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002412 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002413 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2414 }
2415
Wink Savilleb564aae2014-10-23 10:18:09 -07002416 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002417 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002418 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2419 }
2420
Wink Savilleb564aae2014-10-23 10:18:09 -07002421 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002426 Phone phone = getPhone(subId);
2427 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 checkSimPin.start();
2429 return checkSimPin.unlockSim(null, pin);
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 }
2434
Wink Savilleb564aae2014-10-23 10:18:09 -07002435 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002440 Phone phone = getPhone(subId);
2441 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 checkSimPuk.start();
2443 return checkSimPuk.unlockSim(puk, pin);
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 }
2448
2449 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002450 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 * a synchronous one.
2452 */
2453 private static class UnlockSim extends Thread {
2454
2455 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002456 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
2458 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002459 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2460 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461
2462 // For replies from SimCard interface
2463 private Handler mHandler;
2464
2465 // For async handler to identify request type
2466 private static final int SUPPLY_PIN_COMPLETE = 100;
2467
Michele Berionne5e411512020-11-13 02:36:59 +00002468 UnlockSim(int phoneId, IccCard simCard) {
2469 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 mSimCard = simCard;
2471 }
2472
2473 @Override
2474 public void run() {
2475 Looper.prepare();
2476 synchronized (UnlockSim.this) {
2477 mHandler = new Handler() {
2478 @Override
2479 public void handleMessage(Message msg) {
2480 AsyncResult ar = (AsyncResult) msg.obj;
2481 switch (msg.what) {
2482 case SUPPLY_PIN_COMPLETE:
2483 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2484 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002485 mRetryCount = msg.arg1;
2486 if (ar.exception != null) {
2487 if (ar.exception instanceof CommandException &&
2488 ((CommandException)(ar.exception)).getCommandError()
2489 == CommandException.Error.PASSWORD_INCORRECT) {
2490 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002491 } //When UiccCardApp dispose,handle message and return exception
2492 else if (ar.exception instanceof CommandException &&
2493 ((CommandException) (ar.exception)).getCommandError()
2494 == CommandException.Error.ABORTED) {
2495 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002496 } else {
2497 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2498 }
2499 } else {
2500 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 mDone = true;
2503 UnlockSim.this.notifyAll();
2504 }
2505 break;
2506 }
2507 }
2508 };
2509 UnlockSim.this.notifyAll();
2510 }
2511 Looper.loop();
2512 }
2513
2514 /*
2515 * Use PIN or PUK to unlock SIM card
2516 *
2517 * If PUK is null, unlock SIM card with PIN
2518 *
2519 * If PUK is not null, unlock SIM card with PUK and set PIN code
2520 */
Wink Saville9de0f752013-10-22 19:04:03 -07002521 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522
2523 while (mHandler == null) {
2524 try {
2525 wait();
2526 } catch (InterruptedException e) {
2527 Thread.currentThread().interrupt();
2528 }
2529 }
2530 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2531
2532 if (puk == null) {
2533 mSimCard.supplyPin(pin, callback);
2534 } else {
2535 mSimCard.supplyPuk(puk, pin, callback);
2536 }
2537
2538 while (!mDone) {
2539 try {
2540 Log.d(LOG_TAG, "wait for done");
2541 wait();
2542 } catch (InterruptedException e) {
2543 // Restore the interrupted status
2544 Thread.currentThread().interrupt();
2545 }
2546 }
2547 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002548 int[] resultArray = new int[2];
2549 resultArray[0] = mResult;
2550 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002551
2552 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002553 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002554 }
2555
Wink Saville9de0f752013-10-22 19:04:03 -07002556 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558 }
2559
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002560 /**
2561 * This method has been removed due to privacy and stability concerns.
2562 */
2563 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002565 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2566 return;
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
2568
Nathan Harold1f889d82020-06-04 17:05:26 -07002569 @Override
2570 public void updateServiceLocationWithPackageName(String callingPackage) {
2571 mApp.getSystemService(AppOpsManager.class)
2572 .checkPackage(Binder.getCallingUid(), callingPackage);
2573
Nathan Haroldf096d982020-11-18 17:18:06 -08002574 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002575 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2576 // Callers targeting S have no business invoking this method.
2577 return;
2578 }
2579
2580 LocationAccessPolicy.LocationPermissionResult locationResult =
2581 LocationAccessPolicy.checkLocationPermission(mApp,
2582 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2583 .setCallingPackage(callingPackage)
2584 .setCallingFeatureId(null)
2585 .setCallingPid(Binder.getCallingPid())
2586 .setCallingUid(Binder.getCallingUid())
2587 .setMethod("updateServiceLocation")
2588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2589 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2590 .build());
2591 // Apps that lack location permission have no business calling this method;
2592 // however, because no permission was declared in the public API, denials must
2593 // all be "soft".
2594 switch (locationResult) {
2595 case DENIED_HARD: /* fall through */
2596 case DENIED_SOFT:
2597 return;
2598 }
2599
2600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 final long identity = Binder.clearCallingIdentity();
2602 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002603 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002605 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002612 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002613 @Override
2614 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 return isRadioOnWithFeature(callingPackage, null);
2616 }
2617
2618
2619 @Override
2620 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2621 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2622 callingFeatureId);
2623 }
2624
2625 @Deprecated
2626 @Override
2627 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2628 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002629 }
2630
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2633 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002635 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 return false;
2637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 return isRadioOnForSubscriber(subId);
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 }
2646
2647 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone phone = getPhone(subId);
2651 if (phone != null) {
2652 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2653 } else {
2654 return false;
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
2661 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002662 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
Wink Saville36469e72014-06-11 15:17:00 -07002664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
2679 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002680 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002681 }
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = getPhone(subId);
2689 if (phone == null) {
2690 return false;
2691 }
2692 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2693 toggleRadioOnOffForSubscriber(subId);
2694 }
2695 return true;
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
Wink Saville36469e72014-06-11 15:17:00 -07002700
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002701 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002702 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002703 /*
2704 * If any of the Radios are available, it will need to be
2705 * shutdown. So return true if any Radio is available.
2706 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2710 Phone phone = PhoneFactory.getPhone(i);
2711 if (phone != null && phone.isRadioAvailable()) return true;
2712 }
2713 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2714 return false;
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 }
2719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 enforceModifyPermission();
2723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 logv("Shutting down Phone " + i);
2728 shutdownRadioUsingPhoneId(i);
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
2733 }
2734
2735 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 Phone phone = PhoneFactory.getPhone(phoneId);
2737 if (phone != null && phone.isRadioAvailable()) {
2738 phone.shutdownRadio();
2739 }
2740 }
2741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2748 if (defaultPhone != null) {
2749 defaultPhone.setRadioPower(turnOn);
2750 return true;
2751 } else {
2752 loge("There's no default phone.");
2753 return false;
2754 }
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002757 }
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone phone = getPhone(subId);
2766 if (phone != null) {
2767 phone.setRadioPower(turnOn);
2768 return true;
2769 } else {
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
2776
Wink Saville36469e72014-06-11 15:17:00 -07002777 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 public boolean enableDataConnectivity() {
2780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 int subId = mSubscriptionController.getDefaultDataSubId();
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002787 phone.getDataEnabledSettings().setDataEnabled(
2788 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 return true;
2790 } else {
2791 return false;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797
Wink Saville36469e72014-06-11 15:17:00 -07002798 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 public boolean disableDataConnectivity() {
2801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 int subId = mSubscriptionController.getDefaultDataSubId();
2806 final Phone phone = getPhone(subId);
2807 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002808 phone.getDataEnabledSettings().setDataEnabled(
2809 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 return true;
2811 } else {
2812 return false;
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002820 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002825 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
2834 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002835 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002836 }
2837
pkanwarae03a6b2016-11-06 20:37:09 -08002838 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 enforceCallPermission();
2840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2844 return;
2845 }
2846 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2847 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
pkanwar32d516d2016-10-14 19:37:38 -07002851 };
2852
Wink Savilleb564aae2014-10-23 10:18:09 -07002853 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return false;
2860 }
2861 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002867 /**
2868 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2869 * tag on getCallState Binder call.
2870 */
2871 @Deprecated
2872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002874 if (CompatChanges.isChangeEnabled(
2875 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2876 Binder.getCallingUid())) {
2877 // Do not allow this API to be called on API version 31+, it should only be
2878 // called on old apps using this Binder call directly.
2879 throw new SecurityException("This method can only be used for applications "
2880 + "targeting API version 30 or less.");
2881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002884 Phone phone = getPhone(getDefaultSubscription());
2885 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2886 PhoneConstantConversions.convertCallState(phone.getState());
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
2890 }
2891
2892 @Override
2893 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2894 if (CompatChanges.isChangeEnabled(
2895 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2896 Binder.getCallingUid())) {
2897 // Check READ_PHONE_STATE for API version 31+
2898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2899 featureId, "getCallStateForSubscription")) {
2900 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2901 + "targeting API level 31+.");
2902 }
2903 }
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2908 PhoneConstantConversions.convertCallState(phone.getState());
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Sanket Padawe356d7632015-06-22 14:03:32 -07002914 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002915 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002916 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2917 }
2918
2919 @Override
2920 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002923 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 if (phone != null) {
2925 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2926 } else {
2927 return PhoneConstantConversions.convertDataState(
2928 PhoneConstants.DataState.DISCONNECTED);
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Sanket Padawe356d7632015-06-22 14:03:32 -07002935 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002936 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002937 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2938 }
2939
2940 @Override
2941 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 final long identity = Binder.clearCallingIdentity();
2943 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002944 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 if (phone != null) {
2946 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2947 } else {
2948 return TelephonyManager.DATA_ACTIVITY_NONE;
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
2955 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002956 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002958 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002959
2960 LocationAccessPolicy.LocationPermissionResult locationResult =
2961 LocationAccessPolicy.checkLocationPermission(mApp,
2962 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2963 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002964 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002965 .setCallingPid(Binder.getCallingPid())
2966 .setCallingUid(Binder.getCallingUid())
2967 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002968 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002969 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2970 .build());
2971 switch (locationResult) {
2972 case DENIED_HARD:
2973 throw new SecurityException("Not allowed to access cell location");
2974 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002975 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2976 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002983 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002984 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Svetoslav64fad262015-04-14 14:35:21 -07002988 }
2989
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002991 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002992 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2993 // registered cell info, so return a NULL country instead.
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002996 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2997 // Get default phone in this case.
2998 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2999 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003000 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003002 if (phone == null) return "";
3003 ServiceStateTracker sst = phone.getServiceStateTracker();
3004 if (sst == null) return "";
3005 LocaleTracker lt = sst.getLocaleTracker();
3006 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003007 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003011 }
3012
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003013 /**
3014 * This method was removed due to potential issues caused by performing partial
3015 * updates of service state, and lack of a credible use case.
3016 *
3017 * This has the ability to break the telephony implementation by disabling notification of
3018 * changes in device connectivity. DO NOT USE THIS!
3019 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 public void enableLocationUpdates() {
3022 mApp.enforceCallingOrSelfPermission(
3023 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 }
3025
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003026 /**
3027 * This method was removed due to potential issues caused by performing partial
3028 * updates of service state, and lack of a credible use case.
3029 *
3030 * This has the ability to break the telephony implementation by disabling notification of
3031 * changes in device connectivity. DO NOT USE THIS!
3032 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 @Override
3034 public void disableLocationUpdates() {
3035 mApp.enforceCallingOrSelfPermission(
3036 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
3040 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3042 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08003043 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003044 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3045 throw new SecurityException(
3046 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3047 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003048
Jordan Liu1617b712019-07-10 15:06:26 -07003049 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3051 return null;
3052 }
Svetoslav64fad262015-04-14 14:35:21 -07003053
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003054 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003056 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003057 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058
Nathan Haroldf180aac2018-06-01 18:43:55 -07003059 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3060 for (CellInfo ci : info) {
3061 if (ci instanceof CellInfoGsm) {
3062 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3063 } else if (ci instanceof CellInfoWcdma) {
3064 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003067 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 }
3069
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003070 private List<CellInfo> getCachedCellInfo() {
3071 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3072 for (Phone phone : PhoneFactory.getPhones()) {
3073 List<CellInfo> info = phone.getAllCellInfo();
3074 if (info != null) cellInfos.addAll(info);
3075 }
3076 return cellInfos;
3077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078
3079 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003080 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003081 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003082 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003083
3084 LocationAccessPolicy.LocationPermissionResult locationResult =
3085 LocationAccessPolicy.checkLocationPermission(mApp,
3086 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3087 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003088 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003089 .setCallingPid(Binder.getCallingPid())
3090 .setCallingUid(Binder.getCallingUid())
3091 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003092 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003093 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3094 .build());
3095 switch (locationResult) {
3096 case DENIED_HARD:
3097 throw new SecurityException("Not allowed to access cell info");
3098 case DENIED_SOFT:
3099 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 }
3101
Nathan Haroldf096d982020-11-18 17:18:06 -08003102 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003103 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3104 return getCachedCellInfo();
3105 }
3106
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003107 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003108 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3112 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003113 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003114 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 if (info != null) cellInfos.addAll(info);
3116 }
3117 return cellInfos;
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121 }
3122
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003123 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003124 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3125 String callingFeatureId) {
3126 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3127 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003128 }
3129
3130 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003131 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3132 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003133 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003134 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003135 }
3136
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003137 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3138 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003140 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003141
3142 LocationAccessPolicy.LocationPermissionResult locationResult =
3143 LocationAccessPolicy.checkLocationPermission(mApp,
3144 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3145 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003147 .setCallingPid(Binder.getCallingPid())
3148 .setCallingUid(Binder.getCallingUid())
3149 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003150 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3151 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003152 .build());
3153 switch (locationResult) {
3154 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003155 if (TelephonyPermissions
3156 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003157 // Safetynet logging for b/154934934
3158 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3159 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003160 throw new SecurityException("Not allowed to access cell info");
3161 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003162 if (TelephonyPermissions
3163 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003164 // Safetynet logging for b/154934934
3165 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3166 }
Nathan Harold5320c422019-05-09 10:26:08 -07003167 try {
3168 cb.onCellInfo(new ArrayList<CellInfo>());
3169 } catch (RemoteException re) {
3170 // Drop without consequences
3171 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003172 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003173 }
3174
Nathan Harolda939a962019-05-09 10:13:47 -07003175
3176 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003177 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3178
3179 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3180 }
3181
3182 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003184 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186
3187 final long identity = Binder.clearCallingIdentity();
3188 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003189 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194
Shishir Agrawala9f32182016-04-12 12:00:16 -07003195 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003196 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003197 Phone phone = PhoneFactory.getPhone(slotIndex);
3198 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003199 return null;
3200 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003201 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003202 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003203 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003204 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003205 return null;
3206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 return phone.getImei();
3211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003214 }
3215
3216 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003217 public String getTypeAllocationCodeForSlot(int slotIndex) {
3218 Phone phone = PhoneFactory.getPhone(slotIndex);
3219 String tac = null;
3220 if (phone != null) {
3221 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003222 try {
3223 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3224 } catch (IndexOutOfBoundsException e) {
3225 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3226 return null;
3227 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003228 }
3229 return tac;
3230 }
3231
3232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003233 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003234 Phone phone = PhoneFactory.getPhone(slotIndex);
3235 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003236 return null;
3237 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003238
Jeff Davidson913390f2018-02-23 17:11:49 -08003239 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003240 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003241 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003242 return null;
3243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244
3245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 return phone.getMeid();
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
Jack Yu2af8d712017-03-15 17:14:14 -07003251 }
3252
3253 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003254 public String getManufacturerCodeForSlot(int slotIndex) {
3255 Phone phone = PhoneFactory.getPhone(slotIndex);
3256 String manufacturerCode = null;
3257 if (phone != null) {
3258 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003259 try {
3260 manufacturerCode =
3261 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3262 } catch (IndexOutOfBoundsException e) {
3263 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3264 return null;
3265 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003266 }
3267 return manufacturerCode;
3268 }
3269
3270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003271 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3272 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003273 Phone phone = PhoneFactory.getPhone(slotIndex);
3274 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003275 return null;
3276 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 int subId = phone.getSubId();
3278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003279 mApp, subId, callingPackage, callingFeatureId,
3280 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003281 return null;
3282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283
3284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 return phone.getDeviceSvn();
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003290 }
3291
fionaxu43304da2017-11-27 22:51:16 -08003292 @Override
3293 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 final Phone phone = getPhone(subId);
3297 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
fionaxu43304da2017-11-27 22:51:16 -08003301 }
3302
3303 @Override
3304 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 return phone == null ? null : phone.getCarrierName();
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
fionaxu43304da2017-11-27 22:51:16 -08003312 }
3313
calvinpanffe225e2018-11-01 19:43:06 +08003314 @Override
chen xu0026ca62019-03-06 15:28:50 -08003315 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 final Phone phone = getPhone(subId);
3319 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003320 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
chen xu0026ca62019-03-06 15:28:50 -08003327 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003331 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
3335 }
3336
chen xu651eec72018-11-11 19:03:44 -08003337 @Override
chen xu864e11c2018-12-06 22:10:03 -08003338 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3339 if (!isSubscriptionMccMnc) {
3340 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3341 }
chen xu651eec72018-11-11 19:03:44 -08003342 final Phone phone = PhoneFactory.getPhone(slotIndex);
3343 if (phone == null) {
3344 return TelephonyManager.UNKNOWN_CARRIER_ID;
3345 }
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
3352 }
3353
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 //
3355 // Internal helper methods.
3356 //
3357
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003358 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003359 * Make sure the caller is the calling package itself
3360 *
3361 * @throws SecurityException if the caller is not the calling package
3362 */
3363 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3364 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003365 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3366 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003367 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003368 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003369 } catch (PackageManager.NameNotFoundException e) {
3370 // packageUid is -1
3371 }
3372 if (packageUid != callingUid) {
3373 throw new SecurityException(message + ": Package " + callingPackage
3374 + " does not belong to " + callingUid);
3375 }
3376 }
3377
3378 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003379 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3380 *
3381 * @throws SecurityException if the caller does not have the required permission
3382 */
3383 private void enforceModifyPermission() {
3384 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3385 }
3386
Shuo Qian3b6ee772019-11-13 17:43:31 -08003387 private void enforceActiveEmergencySessionPermission() {
3388 mApp.enforceCallingOrSelfPermission(
3389 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3390 }
3391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 /**
3393 * Make sure the caller has the CALL_PHONE permission.
3394 *
3395 * @throws SecurityException if the caller does not have the required permission
3396 */
3397 private void enforceCallPermission() {
3398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3399 }
3400
paulhu5a773602019-08-23 19:17:33 +08003401 private void enforceSettingsPermission() {
3402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003403 }
3404
Michele Berionne5e411512020-11-13 02:36:59 +00003405 private void enforceRebootPermission() {
3406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3407 }
3408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 private String createTelUrl(String number) {
3410 if (TextUtils.isEmpty(number)) {
3411 return null;
3412 }
3413
Jake Hambye994d462014-02-03 13:10:13 -08003414 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 }
3416
Ihab Awadf9e92732013-12-05 18:02:52 -08003417 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003418 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3419 }
3420
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003421 private static void logv(String msg) {
3422 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3423 }
3424
Ihab Awadf9e92732013-12-05 18:02:52 -08003425 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003426 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3427 }
3428
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003429 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003431 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003432 }
3433
Sanket Padawe356d7632015-06-22 14:03:32 -07003434 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003435 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 final Phone phone = PhoneFactory.getPhone(slotIndex);
3439 if (phone == null) {
3440 return PhoneConstants.PHONE_TYPE_NONE;
3441 } else {
3442 return phone.getPhoneType();
3443 }
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 }
3448
3449 /**
3450 * Returns the CDMA ERI icon index to display
3451 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003453 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3454 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3455 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003456 }
3457
Sanket Padawe356d7632015-06-22 14:03:32 -07003458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003459 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3460 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003462 mApp, subId, callingPackage, callingFeatureId,
3463 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003464 return -1;
3465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 final Phone phone = getPhone(subId);
3470 if (phone != null) {
3471 return phone.getCdmaEriIconIndex();
3472 } else {
3473 return -1;
3474 }
3475 } finally {
3476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 }
3479
3480 /**
3481 * Returns the CDMA ERI icon mode,
3482 * 0 - ON
3483 * 1 - FLASHING
3484 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003486 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3487 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3488 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003489 }
3490
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003492 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3493 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 mApp, subId, callingPackage, callingFeatureId,
3496 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003497 return -1;
3498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 final Phone phone = getPhone(subId);
3503 if (phone != null) {
3504 return phone.getCdmaEriIconMode();
3505 } else {
3506 return -1;
3507 }
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 }
3512
3513 /**
3514 * Returns the CDMA ERI text,
3515 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3518 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3519 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003520 }
3521
Sanket Padawe356d7632015-06-22 14:03:32 -07003522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3524 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 mApp, subId, callingPackage, callingFeatureId,
3527 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 return null;
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 final Phone phone = getPhone(subId);
3534 if (phone != null) {
3535 return phone.getCdmaEriText();
3536 } else {
3537 return null;
3538 }
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003542 }
3543
3544 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003545 * Returns the CDMA MDN.
3546 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003548 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3550 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556 return phone.getLine1Number();
3557 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003558 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 return null;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003563 }
3564 }
3565
3566 /**
3567 * Returns the CDMA MIN.
3568 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003570 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3572 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
3577 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3578 return phone.getCdmaMin();
3579 } else {
3580 return null;
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003584 }
3585 }
3586
Hall Liud892bec2018-11-30 14:51:45 -08003587 @Override
3588 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3589 INumberVerificationCallback callback, String callingPackage) {
3590 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3591 != PERMISSION_GRANTED) {
3592 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3593 }
3594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3595
3596 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3597 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003598 throw new SecurityException("Calling package must be configured in the device config: "
3599 + "calling package: " + callingPackage
3600 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003601 }
3602
3603 if (range == null) {
3604 throw new NullPointerException("Range must be non-null");
3605 }
3606
3607 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003608 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003609
3610 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3611 }
3612
Junda Liuca05d5d2014-08-14 22:36:34 -07003613 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003614 * Returns true if CDMA provisioning needs to run.
3615 */
3616 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617 final long identity = Binder.clearCallingIdentity();
3618 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003619 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 }
3624
3625 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003626 * Sets the voice mail number of a given subId.
3627 */
3628 @Override
3629 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003630 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3631 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3636 new Pair<String, String>(alphaTag, number), new Integer(subId));
3637 return success;
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003641 }
3642
Ta-wei Yen87c49842016-05-13 21:19:52 -07003643 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003644 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003646 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3647 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003648 if (!TextUtils.equals(callingPackage, systemDialer)) {
3649 throw new SecurityException("caller must be system dialer");
3650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651
3652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3655 if (phoneAccountHandle == null) {
3656 return null;
3657 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003661 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003662 }
3663
3664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003665 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3666 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003669 mApp, subId, callingPackage, callingFeatureId,
3670 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003671 return null;
3672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003674 final long identity = Binder.clearCallingIdentity();
3675 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003680 }
3681
3682 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003683 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3684 VisualVoicemailSmsFilterSettings settings) {
3685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003694 }
3695
3696 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003697 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003707 }
3708
3709 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003710 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3711 String callingPackage, int subId) {
3712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003721 }
3722
3723 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003724 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726
3727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003730 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003734 }
3735
3736 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003737 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3738 String callingAttributionTag, int subId, String number, int port, String text,
3739 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003741 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003742 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003743 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003744 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3745 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003746 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003747
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003748 /**
fionaxu0152e512016-11-14 13:36:14 -08003749 * Sets the voice activation state of a given subId.
3750 */
3751 @Override
3752 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3754 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755
3756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 final Phone phone = getPhone(subId);
3759 if (phone != null) {
3760 phone.setVoiceActivationState(activationState);
3761 } else {
3762 loge("setVoiceActivationState fails with invalid subId: " + subId);
3763 }
3764 } finally {
3765 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003766 }
3767 }
3768
3769 /**
3770 * Sets the data activation state of a given subId.
3771 */
3772 @Override
3773 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3775 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776
3777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 final Phone phone = getPhone(subId);
3780 if (phone != null) {
3781 phone.setDataActivationState(activationState);
3782 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003783 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 }
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003787 }
3788 }
3789
3790 /**
3791 * Returns the voice activation state of a given subId.
3792 */
3793 @Override
3794 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
fionaxu0152e512016-11-14 13:36:14 -08003797 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 if (phone != null) {
3801 return phone.getVoiceActivationState();
3802 } else {
3803 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3804 }
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003807 }
3808 }
3809
3810 /**
3811 * Returns the data activation state of a given subId.
3812 */
3813 @Override
3814 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816
fionaxu0152e512016-11-14 13:36:14 -08003817 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 if (phone != null) {
3821 return phone.getDataActivationState();
3822 } else {
3823 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3824 }
3825 } finally {
3826 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003827 }
3828 }
3829
3830 /**
Wink Saville36469e72014-06-11 15:17:00 -07003831 * Returns the unread count of voicemails for a subId
3832 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003833 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003834 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3835 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003837 mApp, subId, callingPackage, callingFeatureId,
3838 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003839 return 0;
3840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 final Phone phone = getPhone(subId);
3844 if (phone != null) {
3845 return phone.getVoiceMessageCount();
3846 } else {
3847 return 0;
3848 }
3849 } finally {
3850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003852 }
3853
3854 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003855 * returns true, if the device is in a state where both voice and data
3856 * are supported simultaneously. This can change based on location or network condition.
3857 */
3858 @Override
3859 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 final Phone phone = getPhone(subId);
3863 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003867 }
3868
3869 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003870 * Send the dialer code if called from the current default dialer or the caller has
3871 * carrier privilege.
3872 * @param inputCode The dialer code to send
3873 */
3874 @Override
3875 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003876 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003878 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3879 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003880 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003881 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003882 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884
3885 final long identity = Binder.clearCallingIdentity();
3886 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003887 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 } finally {
3889 Binder.restoreCallingIdentity(identity);
3890 }
fionaxu235cc5e2017-03-06 22:25:57 -08003891 }
3892
Pengquan Menga1bb6272018-09-06 09:59:22 -07003893 @Override
3894 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003895 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003896 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003897 mApp, subId, "getNetworkSelectionMode");
3898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 if (!isActiveSubscription(subId)) {
3901 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3902 }
3903 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003907 }
3908
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003910 public boolean isInEmergencySmsMode() {
3911 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 for (Phone phone : PhoneFactory.getPhones()) {
3915 if (phone.isInEmergencySmsMode()) {
3916 return true;
3917 }
3918 }
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
3922 return false;
3923 }
3924
shilu366312e2019-12-17 09:28:10 -08003925 /**
3926 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3927 * @param subId The subscription to use to check the configuration.
3928 * @param c The callback that will be used to send the result.
3929 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003930 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003931 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3932 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003933 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003934 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003935
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003936 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3937 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3938 "IMS not available on device.");
3939 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 final long token = Binder.clearCallingIdentity();
3941 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003942 int slotId = getSlotIndexOrException(subId);
3943 verifyImsMmTelConfiguredOrThrow(slotId);
3944 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003945 } catch (ImsException e) {
3946 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003947 } finally {
3948 Binder.restoreCallingIdentity(token);
3949 }
3950 }
3951
shilu366312e2019-12-17 09:28:10 -08003952 /**
3953 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3954 * @param subId The subscription to use to check the configuration.
3955 * @param c The callback that will be used to send the result.
3956 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003958 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003959 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003960 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3963 }
Meng Wangafbc5852019-09-19 17:37:13 -07003964 final long token = Binder.clearCallingIdentity();
3965 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003966 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3967 .removeRegistrationCallbackForSubscription(c, subId);
3968 } catch (ImsException e) {
3969 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3970 + "is inactive, ignoring unregister.");
3971 // If the subscription is no longer active, just return, since the callback
3972 // will already have been removed internally.
3973 } finally {
3974 Binder.restoreCallingIdentity(token);
3975 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 }
3977
Brad Ebingera34a6c22019-10-22 17:36:18 -07003978 /**
3979 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3980 */
3981 @Override
3982 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3983 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3984 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3985 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3986 "IMS not available on device.");
3987 }
3988 final long token = Binder.clearCallingIdentity();
3989 try {
3990 Phone phone = getPhone(subId);
3991 if (phone == null) {
3992 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3993 + subId + "'");
3994 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3995 }
3996 phone.getImsRegistrationState(regState -> {
3997 try {
3998 consumer.accept((regState == null)
3999 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4000 } catch (RemoteException e) {
4001 // Ignore if the remote process is no longer available to call back.
4002 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4003 }
4004 });
4005 } finally {
4006 Binder.restoreCallingIdentity(token);
4007 }
4008 }
4009
4010 /**
4011 * Get the transport type for the IMS service registration state.
4012 */
4013 @Override
4014 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004015 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004016 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004017 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4018 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4019 "IMS not available on device.");
4020 }
4021 final long token = Binder.clearCallingIdentity();
4022 try {
4023 Phone phone = getPhone(subId);
4024 if (phone == null) {
4025 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4026 + subId + "'");
4027 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4028 }
4029 phone.getImsRegistrationTech(regTech -> {
4030 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4031 int regTechConverted = (regTech == null)
4032 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4033 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4034 regTechConverted);
4035 try {
4036 consumer.accept(regTechConverted);
4037 } catch (RemoteException e) {
4038 // Ignore if the remote process is no longer available to call back.
4039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4040 }
4041 });
4042 } finally {
4043 Binder.restoreCallingIdentity(token);
4044 }
4045 }
4046
shilu366312e2019-12-17 09:28:10 -08004047 /**
4048 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4049 * @param subId The subscription to use to check the configuration.
4050 * @param c The callback that will be used to send the result.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004053 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4054 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004055 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004056 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004057 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4059 "IMS not available on device.");
4060 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 final long token = Binder.clearCallingIdentity();
4062 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004063 int slotId = getSlotIndexOrException(subId);
4064 verifyImsMmTelConfiguredOrThrow(slotId);
4065 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004066 } catch (ImsException e) {
4067 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 } finally {
4069 Binder.restoreCallingIdentity(token);
4070 }
4071 }
4072
shilu366312e2019-12-17 09:28:10 -08004073 /**
4074 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4075 * @param subId The subscription to use to check the configuration.
4076 * @param c The callback that will be used to send the result.
4077 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004079 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004080 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004081 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4083 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4084 }
Meng Wangafbc5852019-09-19 17:37:13 -07004085
4086 final long token = Binder.clearCallingIdentity();
4087 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004089 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004090 } catch (ImsException e) {
4091 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4092 + "is inactive, ignoring unregister.");
4093 // If the subscription is no longer active, just return, since the callback
4094 // will already have been removed internally.
4095 } finally {
4096 Binder.restoreCallingIdentity(token);
4097 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 }
4099
4100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004101 public boolean isCapable(int subId, int capability, int regTech) {
4102 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 final long token = Binder.clearCallingIdentity();
4104 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004105 int slotId = getSlotIndexOrException(subId);
4106 verifyImsMmTelConfiguredOrThrow(slotId);
4107 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4110 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004111 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004112 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4113 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(token);
4116 }
4117 }
4118
4119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004120 public boolean isAvailable(int subId, int capability, int regTech) {
4121 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 final long token = Binder.clearCallingIdentity();
4123 try {
4124 Phone phone = getPhone(subId);
4125 if (phone == null) return false;
4126 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004127 } catch (com.android.ims.ImsException e) {
4128 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4129 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 } finally {
4131 Binder.restoreCallingIdentity(token);
4132 }
4133 }
4134
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004135 /**
4136 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4137 * subscription.
4138 * @param subId The subscription to use to check the configuration.
4139 * @param callback The callback that will be used to send the result.
4140 * @param capability The MmTelFeature capability that will be used to send the result.
4141 * @param transportType The transport type of the MmTelFeature capability.
4142 */
4143 @Override
4144 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4145 int transportType) {
4146 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4147 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4148 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4149 "IMS not available on device.");
4150 }
4151 final long token = Binder.clearCallingIdentity();
4152 try {
4153 int slotId = getSlotIndex(subId);
4154 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4155 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4156 + subId + "'");
4157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4158 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004159 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004160 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4161 transportType, aBoolean -> {
4162 try {
4163 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4164 } catch (RemoteException e) {
4165 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4166 + "running. Ignore");
4167 }
4168 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004169 } catch (ImsException e) {
4170 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004171 } finally {
4172 Binder.restoreCallingIdentity(token);
4173 }
4174 }
4175
shilu366312e2019-12-17 09:28:10 -08004176 /**
4177 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4178 * @param subId The subscription to use to check the configuration.
4179 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 @Override
4181 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004182 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004183 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004184
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 final long token = Binder.clearCallingIdentity();
4186 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004187 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004188 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004189 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004190 } catch (ImsException e) {
4191 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 } finally {
4193 Binder.restoreCallingIdentity(token);
4194 }
4195 }
4196
4197 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004198 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004200 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 final long identity = Binder.clearCallingIdentity();
4202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004203 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004204 // This setting doesn't require an active ImsService connection, so do not verify. The
4205 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004206 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 } catch (ImsException e) {
4208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
shilu366312e2019-12-17 09:28:10 -08004214 /**
4215 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4216 * @param subId The subscription to use to check the configuration.
4217 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004219 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004220 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004221 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 final long identity = Binder.clearCallingIdentity();
4223 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004225 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004226 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
4232 }
4233
4234 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004237 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004241 // This setting doesn't require an active ImsService connection, so do not verify. The
4242 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004243 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004244 } catch (ImsException e) {
4245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
shilu366312e2019-12-17 09:28:10 -08004251 /**
4252 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4253 * @param subId The subscription to use to check the configuration.
4254 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 @Override
4256 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004257 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004258 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 final long identity = Binder.clearCallingIdentity();
4260 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004262 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004264 } catch (ImsException e) {
4265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
4269 }
4270
4271 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004274 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004277 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004278 // This setting doesn't require an active ImsService connection, so do not verify. The
4279 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
shilu366312e2019-12-17 09:28:10 -08004288 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004289 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4291 * @param subId The subscription to use to check the configuration.
4292 */
4293 @Override
4294 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004295 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004296 mApp, subId, "isCrossSimCallingEnabledByUser");
4297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
4304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
4309 /**
4310 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4311 * Requires MODIFY_PHONE_STATE permission.
4312 * @param subId The subscription to use to check the configuration.
4313 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4314 * false otherwise
4315 */
4316 @Override
4317 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4319 "setCrossSimCallingEnabled");
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004323 // This setting doesn't require an active ImsService connection, so do not verify. The
4324 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
4328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
4333 /**
shilu366312e2019-12-17 09:28:10 -08004334 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4335 * @param subId The subscription to use to check the configuration.
4336 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004338
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004340 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004341 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 final long identity = Binder.clearCallingIdentity();
4343 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004345 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004346 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004347 } catch (ImsException e) {
4348 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
4352 }
4353
4354 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004355 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004357 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004361 // This setting doesn't require an active ImsService connection, so do not verify. The
4362 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004363 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004364 } catch (ImsException e) {
4365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
4369 }
4370
4371 @Override
4372 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4374 "setVoWiFiNonPersistent");
4375 final long identity = Binder.clearCallingIdentity();
4376 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004378 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
shilu366312e2019-12-17 09:28:10 -08004387 /**
4388 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4389 * @param subId The subscription to use to check the configuration.
4390 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 @Override
4392 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004394 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004398 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004400 } catch (ImsException e) {
4401 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
4407 @Override
4408 public void setVoWiFiModeSetting(int subId, int mode) {
4409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4410 "setVoWiFiModeSetting");
4411 final long identity = Binder.clearCallingIdentity();
4412 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004414 // This setting doesn't require an active ImsService connection, so do not verify. The
4415 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004416 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004417 } catch (ImsException e) {
4418 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423
4424 @Override
4425 public int getVoWiFiRoamingModeSetting(int subId) {
4426 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004430 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004431 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004432 } catch (ImsException e) {
4433 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
4437 }
4438
4439 @Override
4440 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4442 "setVoWiFiRoamingModeSetting");
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004446 // This setting doesn't require an active ImsService connection, so do not verify. The
4447 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004449 } catch (ImsException e) {
4450 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
4454 }
4455
4456 @Override
4457 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4459 "setRttCapabilityEnabled");
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004463 // This setting doesn't require an active ImsService connection, so do not verify. The
4464 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004465 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004466 } catch (ImsException e) {
4467 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
4471 }
4472
shilu366312e2019-12-17 09:28:10 -08004473 /**
4474 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4475 * @param subId The subscription to use to check the configuration.
4476 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 @Override
4478 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004479 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004480 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 final long identity = Binder.clearCallingIdentity();
4482 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004484 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
4491 }
4492
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004493 @Override
4494 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4495 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004498 if (!isImsAvailableOnDevice()) {
4499 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4500 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004501 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 int slotId = getSlotIndexOrException(subId);
4503 verifyImsMmTelConfiguredOrThrow(slotId);
4504 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004505 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004506 } catch (ImsException e) {
4507 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
4513 @Override
4514 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4515 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4516 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004517 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4518 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4519 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004521 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004522 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004524 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4525 + "is inactive, ignoring unregister.");
4526 // If the subscription is no longer active, just return, since the callback will already
4527 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
4531 }
4532
allenwtsu99c623b2020-01-03 18:24:23 +08004533
4534 private void checkModifyPhoneStatePermission(int subId, String message) {
4535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4536 message);
4537 }
4538
4539 private boolean isImsProvisioningRequired(int subId, int capability,
4540 boolean isMmtelCapability) {
4541 Phone phone = getPhone(subId);
4542 if (phone == null) {
4543 loge("phone instance null for subid " + subId);
4544 return false;
4545 }
4546 if (isMmtelCapability) {
4547 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4548 return false;
4549 }
4550 } else {
4551 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4552 return false;
4553 }
4554 }
4555 return true;
4556 }
4557
4558 @Override
4559 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4560 boolean isProvisioned) {
4561 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4562
4563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4566 if (!isImsProvisioningRequired(subId, capability, false)) {
4567 return;
4568 }
4569
4570 // this capability requires provisioning, route to the correct API.
4571 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4572 switch (capability) {
4573 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4574 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4575 ims.setEabProvisioned(isProvisioned);
4576 break;
4577 default: {
4578 throw new IllegalArgumentException("Tried to set provisioning for "
4579 + "rcs capability '" + capability + "', which does not require "
4580 + "provisioning.");
4581 }
4582 }
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586
4587 }
4588
4589
4590 @Override
4591 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4592 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4596 if (!isImsProvisioningRequired(subId, capability, false)) {
4597 return true;
4598 }
4599
4600 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4601 switch (capability) {
4602 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4603 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4604 return ims.isEabProvisionedOnDevice();
4605
4606 default: {
4607 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4608 + "capability '" + capability + "', which does not require "
4609 + "provisioning.");
4610 }
4611 }
4612
4613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
4616 }
4617
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004619 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4620 boolean isProvisioned) {
4621 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004622 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4623 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4624 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004625 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4626 }
allenwtsu99c623b2020-01-03 18:24:23 +08004627 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004631 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 return;
4633 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004634 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4635 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4636 loge("setImsProvisioningStatusForCapability: called for technology that does "
4637 + "not support provisioning - " + tech);
4638 return;
4639 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640
4641 // this capability requires provisioning, route to the correct API.
4642 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4643 switch (capability) {
4644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4645 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4646 ims.setVolteProvisioned(isProvisioned);
4647 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4648 ims.setWfcProvisioned(isProvisioned);
4649 }
4650 break;
4651 }
4652 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4653 // There is currently no difference in VT provisioning type.
4654 ims.setVtProvisioned(isProvisioned);
4655 break;
4656 }
4657 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4658 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4659 // change the capability of the feature instead if needed.
4660 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4661 == isProvisioned) {
4662 // No change in provisioning.
4663 return;
4664 }
4665 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4666 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004667 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004668 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4670 + ", Exception" + e.getMessage());
4671 }
4672 break;
4673 }
4674 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004675 throw new IllegalArgumentException("Tried to set provisioning for "
4676 + "MmTel capability '" + capability + "', which does not require "
4677 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 }
4679 }
4680
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
4684 }
4685
4686 @Override
4687 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4688 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004689 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4690 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4691 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004692 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4693 }
4694 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004698 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 return true;
4700 }
4701
Brad Ebinger0d79c572021-04-17 15:20:49 -07004702 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4703 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4704 loge("getImsProvisioningStatusForCapability: called for technology that does "
4705 + "not support provisioning - " + tech);
4706 return true;
4707 }
4708
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4710 switch (capability) {
4711 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4712 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4713 return ims.isVolteProvisionedOnDevice();
4714 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4715 return ims.isWfcProvisionedOnDevice();
4716 }
4717 // This should never happen, since we are checking tech above to make sure it
4718 // is either LTE or IWLAN.
4719 throw new IllegalArgumentException("Invalid radio technology for voice "
4720 + "capability.");
4721 }
4722 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4723 // There is currently no difference in VT provisioning type.
4724 return ims.isVtProvisionedOnDevice();
4725 }
4726 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4727 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4728 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4729 }
4730 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004731 throw new IllegalArgumentException(
4732 "Tried to get provisioning for MmTel capability '" + capability
4733 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 }
4735 }
4736
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
4740 }
4741
4742 @Override
4743 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4744 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4745 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4746 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4747 }
4748 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4749 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4750 return (provisionedBits & capability) > 0;
4751 }
4752
4753 @Override
4754 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4755 boolean isProvisioned) {
4756 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4757 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4758 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4759 }
4760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4761 "setProvisioningStatusForCapability");
4762 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4763 // If the current provisioning status for capability already matches isProvisioned,
4764 // do nothing.
4765 if (((provisionedBits & capability) > 0) == isProvisioned) {
4766 return;
4767 }
4768 if (isProvisioned) {
4769 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4770 } else {
4771 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4772 }
4773 }
4774
4775 /**
4776 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4777 * technology. The bitfield should mirror the bitfield defined by
4778 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4779 */
4780 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4781 String key = getMmTelProvisioningKey(subId, tech);
4782 // Default is no capabilities are provisioned.
4783 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4784 }
4785
4786 /**
4787 * Sets the MmTel capability provisioning bitfield (defined by
4788 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4789 * technology specified.
4790 *
4791 * Note: This is a synchronous command and should not be called on UI thread.
4792 */
4793 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4794 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4795 String key = getMmTelProvisioningKey(subId, tech);
4796 editor.putInt(key, newField);
4797 editor.commit();
4798 }
4799
4800 private static String getMmTelProvisioningKey(int subId, int tech) {
4801 // resulting key is provision_ims_mmtel_{subId}_{tech}
4802 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4803 }
4804
4805 /**
4806 * Query CarrierConfig to see if the specified capability requires provisioning for the
4807 * carrier associated with the subscription id.
4808 */
4809 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4810 int capability) {
4811 CarrierConfigManager configManager = new CarrierConfigManager(context);
4812 PersistableBundle c = configManager.getConfigForSubId(subId);
4813 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004814 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4816 false);
4817 boolean requireVoiceVtProvisioning = c.getBoolean(
4818 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4819
4820 // First check to make sure that the capability requires provisioning.
4821 switch (capability) {
4822 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4823 // intentional fallthrough
4824 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4825 if (requireVoiceVtProvisioning) {
4826 // Voice and Video requires provisioning
4827 return true;
4828 }
4829 break;
4830 }
4831 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4832 if (requireUtProvisioning) {
4833 // UT requires provisioning
4834 return true;
4835 }
4836 break;
4837 }
4838 }
4839 return false;
4840 }
4841
allenwtsu99c623b2020-01-03 18:24:23 +08004842 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4843 int capability) {
4844 CarrierConfigManager configManager = new CarrierConfigManager(context);
4845 PersistableBundle c = configManager.getConfigForSubId(subId);
4846
4847 boolean requireRcsProvisioning = c.getBoolean(
4848 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4849
4850 // First check to make sure that the capability requires provisioning.
4851 switch (capability) {
4852 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4853 // intentional fallthrough
4854 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4855 if (requireRcsProvisioning) {
4856 // OPTION or PRESENCE requires provisioning
4857 return true;
4858 }
4859 break;
4860 }
4861 }
4862 return false;
4863 }
4864
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4868 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4869 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004870 enforceReadPrivilegedPermission("getImsProvisioningInt");
4871 final long identity = Binder.clearCallingIdentity();
4872 try {
4873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004874 int slotId = getSlotIndex(subId);
4875 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4876 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4877 + subId + "' for key:" + key);
4878 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4879 }
calvinpanb5a34062021-02-08 19:59:36 +08004880 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004881 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4883 + subId + "' for key:" + key);
4884 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
4888 }
4889
4890 @Override
4891 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4893 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4894 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004895 enforceReadPrivilegedPermission("getImsProvisioningString");
4896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 int slotId = getSlotIndex(subId);
4900 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4901 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4902 + subId + "' for key:" + key);
4903 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4904 }
calvinpanb5a34062021-02-08 19:59:36 +08004905 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4908 + subId + "' for key:" + key);
4909 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 @Override
4916 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4918 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4919 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4921 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004925 int slotId = getSlotIndex(subId);
4926 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4927 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4928 + subId + "' for key:" + key);
4929 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4930 }
calvinpanb5a34062021-02-08 19:59:36 +08004931 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4932 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004934 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004935 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
4939 }
4940
4941 @Override
4942 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4944 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4945 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4947 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004948 final long identity = Binder.clearCallingIdentity();
4949 try {
4950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 int slotId = getSlotIndex(subId);
4952 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4953 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4954 + subId + "' for key:" + key);
4955 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4956 }
calvinpanb5a34062021-02-08 19:59:36 +08004957 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4958 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004960 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
4965 }
4966
Brad Ebinger919631e2021-06-02 17:46:35 -07004967 /**
4968 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4969 * for the given slot ID or no ImsResolver instance has been created.
4970 * @param slotId The slot ID that the IMS service is created for.
4971 * @throws ImsException If there is no ImsService configured for this slot.
4972 */
4973 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4974 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4975 ImsFeature.FEATURE_MMTEL)) {
4976 throw new ImsException("This subscription does not support MMTEL over IMS",
4977 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4978 }
4979 }
4980
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004981 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 int slotId = SubscriptionManager.getSlotIndex(subId);
4983 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004984 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4985 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 }
4987 return slotId;
4988 }
4989
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004990 private int getSlotIndex(int subId) {
4991 int slotId = SubscriptionManager.getSlotIndex(subId);
4992 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4993 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4994 }
4995 return slotId;
4996 }
4997
Wink Saville36469e72014-06-11 15:17:00 -07004998 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004999 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005000 */
5001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005002 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5003 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08005004 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005005 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005006 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005007 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005008 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005009 mApp, subId, callingPackage, callingFeatureId,
5010 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005011 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5012 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 final Phone phone = getPhone(subId);
5017 if (phone != null) {
5018 return phone.getServiceState().getDataNetworkType();
5019 } else {
5020 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5021 }
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005025 }
5026
5027 /**
5028 * Returns the data network type
5029 */
5030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005031 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005032 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5033 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005034 }
5035
5036 /**
5037 * Returns the data network type for a subId
5038 */
5039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005040 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5041 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005042 String functionName = "getDataNetworkTypeForSubscriber";
5043 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5044 mApp, functionName)) {
5045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5046 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5048 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005049 }
5050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 final Phone phone = getPhone(subId);
5054 if (phone != null) {
5055 return phone.getServiceState().getDataNetworkType();
5056 } else {
5057 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5058 }
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005062 }
5063
5064 /**
Wink Saville36469e72014-06-11 15:17:00 -07005065 * Returns the Voice network type for a subId
5066 */
5067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5069 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005070 String functionName = "getVoiceNetworkTypeForSubscriber";
5071 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5072 mApp, functionName)) {
5073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5074 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5075 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5076 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005077 }
5078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 final Phone phone = getPhone(subId);
5082 if (phone != null) {
5083 return phone.getServiceState().getVoiceNetworkType();
5084 } else {
5085 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005090 }
5091
5092 /**
5093 * @return true if a ICC card is present
5094 */
5095 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005096 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005097 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5098 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005099 }
5100
5101 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005102 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005103 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005105 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 final Phone phone = PhoneFactory.getPhone(slotIndex);
5109 if (phone != null) {
5110 return phone.getIccCard().hasIccCard();
5111 } else {
5112 return false;
5113 }
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005117 }
5118
5119 /**
5120 * Return if the current radio is LTE on CDMA. This
5121 * is a tri-state return value as for a period of time
5122 * the mode may be unknown.
5123 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005124 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005125 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005126 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005127 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005129 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5130 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5131 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005132 }
5133
Sanket Padawe356d7632015-06-22 14:03:32 -07005134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005135 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5136 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005137 try {
5138 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5139 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005140 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5141 }
5142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 final Phone phone = getPhone(subId);
5146 if (phone == null) {
5147 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5148 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005149 return TelephonyProperties.lte_on_cdma_device()
5150 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 }
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005154 }
Wink Saville36469e72014-06-11 15:17:00 -07005155 }
5156
Wink Saville36469e72014-06-11 15:17:00 -07005157 /**
5158 * {@hide}
5159 * Returns Default subId, 0 in the case of single standby.
5160 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005161 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005162 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005163 }
5164
Shishir Agrawala9f32182016-04-12 12:00:16 -07005165 private int getSlotForDefaultSubscription() {
5166 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5167 }
5168
Wink Savilleb564aae2014-10-23 10:18:09 -07005169 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005170 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005171 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005172
Pengquan Menge92a50d2018-09-21 15:54:48 -07005173 private boolean isActiveSubscription(int subId) {
5174 return mSubscriptionController.isActiveSubId(subId);
5175 }
5176
Ihab Awadf2177b72013-11-25 13:33:23 -08005177 /**
5178 * @see android.telephony.TelephonyManager.WifiCallingChoices
5179 */
5180 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005183 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5185 getWhenToMakeWifiCallsDefaultPreference());
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005189 }
5190
5191 /**
5192 * @see android.telephony.TelephonyManager.WifiCallingChoices
5193 */
5194 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005198 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005203 }
5204
Sailesh Nepald1e68152013-12-12 19:08:02 -08005205 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005206 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005207 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005208 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005209
Jordan Liu4c733742019-02-28 12:03:40 -08005210 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5211 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5212 if (phoneId == -1) {
5213 throw new IllegalArgumentException("Given slot index: " + slotIndex
5214 + " does not correspond to an active phone");
5215 }
5216 return PhoneFactory.getPhone(phoneId);
5217 }
5218
Shishir Agrawal566b7612013-10-28 14:41:00 -07005219 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005220 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5221 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5223 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005225 if (DBG) {
5226 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5227 }
5228 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5229 p2);
5230 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005231
Jordan Liu4c733742019-02-28 12:03:40 -08005232
5233 @Override
5234 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5235 int slotIndex, String callingPackage, String aid, int p2) {
5236 enforceModifyPermission();
5237 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5238 if (DBG) {
5239 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5240 }
5241 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5242 callingPackage, aid, p2);
5243 }
5244
5245 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5246 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 if (TextUtils.equals(ISDR_AID, aid)) {
5250 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005251 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5252 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 if (bestComponent == null
5254 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5255 loge("The calling package is not allowed to access ISD-R.");
5256 throw new SecurityException(
5257 "The calling package is not allowed to access ISD-R.");
5258 }
Derek Tan740e1672017-06-27 14:56:27 -07005259 }
Derek Tan740e1672017-06-27 14:56:27 -07005260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005262 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5263 null /* workSource */);
5264 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 return response;
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005269 }
5270
5271 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005272 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5274 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005275 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5276 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5277 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005278
Jordan Liu4c733742019-02-28 12:03:40 -08005279 @Override
5280 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5281 enforceModifyPermission();
5282 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5283 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5284 channel);
5285 }
5286
5287 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 final long identity = Binder.clearCallingIdentity();
5289 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 if (channel < 0) {
5291 return false;
5292 }
Jordan Liu4c733742019-02-28 12:03:40 -08005293 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5294 null /* workSource */);
5295 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 return success;
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300 }
5301
5302 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005303 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5306 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005307 if (DBG) {
5308 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5309 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5310 + p3 + " data=" + data);
5311 }
5312 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5313 command, p1, p2, p3, data);
5314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315
Jordan Liu4c733742019-02-28 12:03:40 -08005316 @Override
5317 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5318 int command, int p1, int p2, int p3, String data) {
5319 enforceModifyPermission();
5320 if (DBG) {
5321 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5322 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5323 + p3 + " data=" + data);
5324 }
5325 return iccTransmitApduLogicalChannelWithPermission(
5326 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5327 data);
5328 }
5329
5330 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5331 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005334 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 return "";
5336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005339 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5340 null /* workSource */);
5341 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 // Append the returned status code to the end of the response payload.
5344 String s = Integer.toHexString(
5345 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5346 if (response.payload != null) {
5347 s = IccUtils.bytesToHexString(response.payload) + s;
5348 }
5349 return s;
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005352 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005353 }
Jake Hambye994d462014-02-03 13:10:13 -08005354
Evan Charltonc66da362014-05-16 14:06:40 -07005355 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005356 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5357 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5359 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005361 if (DBG) {
5362 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5363 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5364 }
5365 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5366 cla, command, p1, p2, p3, data);
5367 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005368
Jordan Liu4c733742019-02-28 12:03:40 -08005369 @Override
5370 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5371 int command, int p1, int p2, int p3, String data) {
5372 enforceModifyPermission();
5373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5374 if (DBG) {
5375 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5376 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5377 + " data=" + data);
5378 }
5379
5380 return iccTransmitApduBasicChannelWithPermission(
5381 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5382 p2, p3, data);
5383 }
5384
5385 // open APDU basic channel assuming the caller has sufficient permissions
5386 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5387 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5391 && TextUtils.equals(ISDR_AID, data)) {
5392 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5394 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 if (bestComponent == null
5396 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5397 loge("The calling package is not allowed to select ISD-R.");
5398 throw new SecurityException(
5399 "The calling package is not allowed to select ISD-R.");
5400 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005401 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005404 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5405 null /* workSource */);
5406 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 // Append the returned status code to the end of the response payload.
5409 String s = Integer.toHexString(
5410 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5411 if (response.payload != null) {
5412 s = IccUtils.bytesToHexString(response.payload) + s;
5413 }
5414 return s;
5415 } finally {
5416 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005417 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005418 }
5419
5420 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005421 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005422 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5424 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
5428 if (DBG) {
5429 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5430 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5431 }
5432
5433 IccIoResult response =
5434 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5435 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5436 subId);
5437
5438 if (DBG) {
5439 log("Exchange SIM_IO [R]" + response);
5440 }
5441
5442 byte[] result = null;
5443 int length = 2;
5444 if (response.payload != null) {
5445 length = 2 + response.payload.length;
5446 result = new byte[length];
5447 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5448 } else {
5449 result = new byte[length];
5450 }
5451
5452 result[length - 1] = (byte) response.sw2;
5453 result[length - 2] = (byte) response.sw1;
5454 return result;
5455 } finally {
5456 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005457 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005458 }
5459
Nathan Haroldb3014052017-01-25 15:57:32 -08005460 /**
5461 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5462 * on a particular subscription
5463 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005464 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5465 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005467 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005468 return null;
5469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 if (appType != TelephonyManager.APPTYPE_USIM
5474 && appType != TelephonyManager.APPTYPE_SIM) {
5475 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5476 return null;
5477 }
5478 Object response = sendRequest(
5479 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5480 if (response instanceof String[]) {
5481 return (String[]) response;
5482 }
yincheng zhao2737e882019-09-06 17:06:54 -07005483 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005485 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005488 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005489 }
5490
yincheng zhao2737e882019-09-06 17:06:54 -07005491 /**
5492 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5493 * subscription.
5494 *
5495 * @param subId the id of the subscription.
5496 * @param appType the uicc app type, must be USIM or SIM.
5497 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5498 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005499 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005500 * @return number of fplmns that is successfully written to the SIM.
5501 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005502 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5503 String callingFeatureId) {
5504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5505 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005506 if (DBG) logv("no permissions for setForbiddenplmns");
5507 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5508 }
5509 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5510 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5511 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5512 }
5513 if (fplmns == null) {
5514 throw new IllegalArgumentException("Fplmn List provided is null");
5515 }
5516 for (String fplmn : fplmns) {
5517 if (!CellIdentity.isValidPlmn(fplmn)) {
5518 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5519 }
5520 }
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 Object response = sendRequest(
5524 CMD_SET_FORBIDDEN_PLMNS,
5525 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5526 subId);
5527 return (int) response;
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
5531 }
5532
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005533 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005534 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5536 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5541 if (response.payload == null) {
5542 return "";
5543 }
Evan Charltonc66da362014-05-16 14:06:40 -07005544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 // Append the returned status code to the end of the response payload.
5546 String s = Integer.toHexString(
5547 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5548 s = IccUtils.bytesToHexString(response.payload) + s;
5549 return s;
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
Evan Charltonc66da362014-05-16 14:06:40 -07005553 }
5554
Jake Hambye994d462014-02-03 13:10:13 -08005555 /**
5556 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5557 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5558 *
5559 * @param itemID the ID of the item to read
5560 * @return the NV item as a String, or null on error.
5561 */
5562 @Override
5563 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5566 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005571 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5573 return value;
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
Jake Hambye994d462014-02-03 13:10:13 -08005577 }
5578
5579 /**
5580 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5581 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5582 *
5583 * @param itemID the ID of the item to read
5584 * @param itemValue the value to write, as a String
5585 * @return true on success; false on any failure
5586 */
5587 @Override
5588 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005589 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5591 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5596 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005597 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5599 return success;
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
Jake Hambye994d462014-02-03 13:10:13 -08005603 }
5604
5605 /**
5606 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5607 * Used for device configuration by some CDMA operators.
5608 *
5609 * @param preferredRoamingList byte array containing the new PRL
5610 * @return true on success; false on any failure
5611 */
5612 @Override
5613 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5620 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5621 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5622 return success;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Jake Hambye994d462014-02-03 13:10:13 -08005626 }
5627
5628 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005629 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005630 * Used for device configuration by some CDMA operators.
5631 *
chen xu6dac5ab2018-10-26 17:39:23 -07005632 * @param slotIndex - device slot.
5633 *
Jake Hambye994d462014-02-03 13:10:13 -08005634 * @return true on success; false on any failure
5635 */
5636 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005637 public boolean resetModemConfig(int slotIndex) {
5638 Phone phone = PhoneFactory.getPhone(slotIndex);
5639 if (phone != null) {
5640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5641 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642
chen xu6dac5ab2018-10-26 17:39:23 -07005643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5646 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5647 return success;
5648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651 }
chen xu6dac5ab2018-10-26 17:39:23 -07005652 return false;
5653 }
5654
5655 /**
5656 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5657 *
5658 * @param slotIndex - device slot.
5659 *
5660 * @return true on success; false on any failure
5661 */
5662 @Override
5663 public boolean rebootModem(int slotIndex) {
5664 Phone phone = PhoneFactory.getPhone(slotIndex);
5665 if (phone != null) {
5666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, phone.getSubId(), "rebootModem");
5668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5672 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5673 return success;
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 }
5678 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005679 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005680
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005681 public String[] getPcscfAddress(String apnType, String callingPackage,
5682 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5685 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005686 return new String[0];
5687 }
5688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 final long identity = Binder.clearCallingIdentity();
5690 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005691 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
Wink Saville36469e72014-06-11 15:17:00 -07005695 }
5696
Brad Ebinger51f743a2017-01-23 13:50:20 -08005697 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005698 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5699 * {@link #disableIms(int)}.
5700 * @param slotIndex device slot.
5701 */
5702 public void resetIms(int slotIndex) {
5703 enforceModifyPermission();
5704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 if (mImsResolver == null) {
5708 // may happen if the does not support IMS.
5709 return;
5710 }
5711 mImsResolver.disableIms(slotIndex);
5712 mImsResolver.enableIms(slotIndex);
5713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
5716 }
5717
5718 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005719 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5720 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005721 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005722 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005723 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005727 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005728 // may happen if the device does not support IMS.
5729 return;
5730 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005731 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005735 }
5736
5737 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005738 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5739 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005740 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005741 public void disableIms(int slotId) {
5742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743
5744 final long identity = Binder.clearCallingIdentity();
5745 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005747 // may happen if the device does not support IMS.
5748 return;
5749 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005750 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005754 }
5755
5756 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005757 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5758 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005760 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005761 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5768 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005769 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005770 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005774 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005775 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005776 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5777 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005778 @Override
5779 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005780 enforceModifyPermission();
5781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005785 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
5789 }
5790
5791 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005792 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005793 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005794 */
5795 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005800 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005801 // may happen if the device does not support IMS.
5802 return null;
5803 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005804 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005808 }
5809
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005810 /**
5811 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005812 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005813 */
5814 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005820 // may happen if the device does not support IMS.
5821 return null;
5822 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005827 }
5828
Brad Ebinger884c07b2018-02-15 16:17:40 -08005829 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005830 * Sets the ImsService Package Name that Telephony will bind to.
5831 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005832 * @param slotIndex the slot ID that the ImsService should bind for.
5833 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005834 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 * @param featureTypes An integer array of feature types associated with a packageName.
5836 * @param packageName The name of the package that the current configuration will be replaced
5837 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005838 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005839 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5841 int[] featureTypes, String packageName) {
5842 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5845 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
5849 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005851 // may happen if the device does not support IMS.
5852 return false;
5853 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 Map<Integer, String> featureConfig = new HashMap<>();
5855 for (int featureType : featureTypes) {
5856 featureConfig.put(featureType, packageName);
5857 }
5858 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5859 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005863 }
5864
5865 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005866 * Clears any carrier ImsService overrides for the slot index specified that were previously
5867 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5868 *
5869 * This should only be used for testing.
5870 *
5871 * @param slotIndex the slot ID that the ImsService should bind for.
5872 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5873 */
5874 @Override
5875 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5876 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5878 "clearCarrierImsServiceOverride");
5879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5880 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5881 "clearCarrierImsServiceOverride");
5882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 if (mImsResolver == null) {
5886 // may happen if the device does not support IMS.
5887 return false;
5888 }
5889 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
5893 }
5894
5895 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005897 *
5898 * @param slotId The slot that the ImsService is associated with.
5899 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5900 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005902 * @return the package name of the ImsService configuration.
5903 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5905 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005906 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005907 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005908 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005909 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5910 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 final long identity = Binder.clearCallingIdentity();
5913 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005915 // may happen if the device does not support IMS.
5916 return "";
5917 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005918 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005919 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5920 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005924 }
5925
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005926 /**
5927 * Get the MmTelFeature state associated with the requested subscription id.
5928 * @param subId The subscription that the MmTelFeature is associated with.
5929 * @param callback A callback with an integer containing the
5930 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5931 */
5932 @Override
5933 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5934 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5935 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5936 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5937 "IMS not available on device.");
5938 }
5939 final long token = Binder.clearCallingIdentity();
5940 try {
5941 int slotId = getSlotIndex(subId);
5942 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5943 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5944 + subId + "'");
5945 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5946 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005947 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005948 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5949 try {
5950 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5951 } catch (RemoteException e) {
5952 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5953 + "Ignore");
5954 }
5955 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005956 } catch (ImsException e) {
5957 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005958 } finally {
5959 Binder.restoreCallingIdentity(token);
5960 }
5961 }
5962
Daniel Brightbb5840b2021-01-12 15:48:18 -08005963 /**
5964 * Sets the ims registration state on all valid {@link Phone}s.
5965 */
5966 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968
5969 final long identity = Binder.clearCallingIdentity();
5970 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005971 // NOTE: Before S, this method only set the default phone.
5972 for (final Phone phone : PhoneFactory.getPhones()) {
5973 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5974 phone.setImsRegistrationState(registered);
5975 }
5976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
Wink Saville36469e72014-06-11 15:17:00 -07005980 }
5981
5982 /**
Stuart Scott54788802015-03-30 13:18:01 -07005983 * Set the network selection mode to automatic.
5984 *
5985 */
5986 @Override
5987 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5989 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990
5991 final long identity = Binder.clearCallingIdentity();
5992 try {
shilufc958392020-01-20 11:36:01 -08005993 if (!isActiveSubscription(subId)) {
5994 return;
5995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005997 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5998 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
Stuart Scott54788802015-03-30 13:18:01 -07006002 }
6003
Jack Yud10cdd42020-09-28 20:28:01 -07006004 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006005 * Ask the radio to connect to the input network and change selection mode to manual.
6006 *
6007 * @param subId the id of the subscription.
6008 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6009 * the operator to attach to.
6010 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6011 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6012 * normal network selection next time.
6013 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006014 */
6015 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006016 public boolean setNetworkSelectionModeManual(
6017 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6019 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006020
6021 if (!isActiveSubscription(subId)) {
6022 return false;
6023 }
6024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 final long identity = Binder.clearCallingIdentity();
6026 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006027 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006029 if (DBG) {
6030 log("setNetworkSelectionModeManual: subId: " + subId
6031 + " operator: " + operatorInfo);
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006037 }
shilu84f6e8b2019-12-19 13:58:01 -08006038 /**
6039 * Get the manual network selection
6040 *
6041 * @param subId the id of the subscription.
6042 *
6043 * @return the previously saved user selected PLMN
6044 */
6045 @Override
6046 public String getManualNetworkSelectionPlmn(int subId) {
6047 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006048 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006049 mApp, subId, "getManualNetworkSelectionPlmn");
6050
6051 final long identity = Binder.clearCallingIdentity();
6052 try {
6053 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006054 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006055 }
6056
6057 final Phone phone = getPhone(subId);
6058 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006059 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006060 }
6061 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6062 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6063 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
6067 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006068
6069 /**
6070 * Scans for available networks.
6071 */
6072 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006073 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6074 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6076 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006077 LocationAccessPolicy.LocationPermissionResult locationResult =
6078 LocationAccessPolicy.checkLocationPermission(mApp,
6079 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6080 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006081 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006082 .setCallingPid(Binder.getCallingPid())
6083 .setCallingUid(Binder.getCallingUid())
6084 .setMethod("getCellNetworkScanResults")
6085 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006086 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6087 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006088 .build());
6089 switch (locationResult) {
6090 case DENIED_HARD:
6091 throw new SecurityException("Not allowed to access scan results -- location");
6092 case DENIED_SOFT:
6093 return null;
6094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095
Pengquan Menga1bb6272018-09-06 09:59:22 -07006096 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 try {
6098 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006099 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006104 }
6105
6106 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006107 * Get the call forwarding info, given the call forwarding reason.
6108 */
6109 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006110 public void getCallForwarding(int subId, int callForwardingReason,
6111 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006112 enforceReadPrivilegedPermission("getCallForwarding");
6113 long identity = Binder.clearCallingIdentity();
6114 try {
6115 if (DBG) {
6116 log("getCallForwarding: subId " + subId
6117 + " callForwardingReason" + callForwardingReason);
6118 }
Hall Liu27d24262020-09-18 19:04:59 -07006119
6120 Phone phone = getPhone(subId);
6121 if (phone == null) {
6122 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006123 callback.onError(
6124 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006125 } catch (RemoteException e) {
6126 // ignore
6127 }
6128 return;
6129 }
6130
6131 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6132 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6133 @Override
6134 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6135 try {
6136 callback.onCallForwardingInfoAvailable(info);
6137 } catch (RemoteException e) {
6138 // ignore
6139 }
6140 }
6141
6142 @Override
6143 public void onError(int error) {
6144 try {
6145 callback.onError(error);
6146 } catch (RemoteException e) {
6147 // ignore
6148 }
6149 }
6150 });
6151 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154 }
6155 }
6156
6157 /**
6158 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6159 * reason, the number to forward, and the timeout before the forwarding is attempted.
6160 */
6161 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006162 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6163 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006164 enforceModifyPermission();
6165 long identity = Binder.clearCallingIdentity();
6166 try {
6167 if (DBG) {
6168 log("setCallForwarding: subId " + subId
6169 + " callForwardingInfo" + callForwardingInfo);
6170 }
Hall Liu27d24262020-09-18 19:04:59 -07006171
6172 Phone phone = getPhone(subId);
6173 if (phone == null) {
6174 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006175 callback.accept(
6176 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006177 } catch (RemoteException e) {
6178 // ignore
6179 }
6180 return;
6181 }
6182
6183 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6184 FunctionalUtils.ignoreRemoteException(callback::accept));
6185
6186 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Hall Liu27d24262020-09-18 19:04:59 -07006193 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006194 */
6195 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006196 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006197 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006198 long identity = Binder.clearCallingIdentity();
6199 try {
Hall Liu27d24262020-09-18 19:04:59 -07006200 Phone phone = getPhone(subId);
6201 if (phone == null) {
6202 try {
6203 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6204 } catch (RemoteException e) {
6205 // ignore
6206 }
6207 return;
6208 }
SongFerngWang0e767992021-03-31 22:08:45 +08006209 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6210 PersistableBundle c = configManager.getConfigForSubId(subId);
6211 boolean requireUssd = c.getBoolean(
6212 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006213
Shuo Qian4a594052020-01-23 11:59:30 -08006214 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006215 if (requireUssd) {
6216 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6217 getSubscriptionCarrierId(subId));
6218 String newUssdCommand = "";
6219 try {
6220 newUssdCommand = carrierXmlParser.getFeature(
6221 CarrierXmlParser.FEATURE_CALL_WAITING)
6222 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6223 } catch (NullPointerException e) {
6224 loge("Failed to generate USSD number" + e);
6225 }
6226 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6227 mMainThreadHandler, callback, carrierXmlParser,
6228 CarrierXmlParser.SsEntry.SSAction.QUERY);
6229 final String ussdCommand = newUssdCommand;
6230 Executors.newSingleThreadExecutor().execute(() -> {
6231 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6232 });
6233 } else {
6234 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6235 callback::accept);
6236 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6237 }
Shuo Qian4a594052020-01-23 11:59:30 -08006238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
6241 }
6242
6243 /**
Hall Liu27d24262020-09-18 19:04:59 -07006244 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006245 */
6246 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006247 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006248 enforceModifyPermission();
6249 long identity = Binder.clearCallingIdentity();
6250 try {
Hall Liu27d24262020-09-18 19:04:59 -07006251 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6252
6253 Phone phone = getPhone(subId);
6254 if (phone == null) {
6255 try {
6256 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6257 } catch (RemoteException e) {
6258 // ignore
6259 }
6260 return;
6261 }
6262
SongFerngWang0e767992021-03-31 22:08:45 +08006263 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6264 PersistableBundle c = configManager.getConfigForSubId(subId);
6265 boolean requireUssd = c.getBoolean(
6266 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006267
SongFerngWang0e767992021-03-31 22:08:45 +08006268 if (DBG) log("getCallWaitingStatus: subId " + subId);
6269 if (requireUssd) {
6270 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6271 getSubscriptionCarrierId(subId));
6272 CarrierXmlParser.SsEntry.SSAction ssAction =
6273 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6274 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6275 String newUssdCommand = "";
6276 try {
6277 newUssdCommand = carrierXmlParser.getFeature(
6278 CarrierXmlParser.FEATURE_CALL_WAITING)
6279 .makeCommand(ssAction, null);
6280 } catch (NullPointerException e) {
6281 loge("Failed to generate USSD number" + e);
6282 }
6283 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6284 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6285 final String ussdCommand = newUssdCommand;
6286 Executors.newSingleThreadExecutor().execute(() -> {
6287 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6288 });
6289 } else {
6290 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6291 FunctionalUtils.ignoreRemoteException(callback::accept));
6292
6293 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6294 }
Shuo Qian4a594052020-01-23 11:59:30 -08006295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
6298 }
6299
6300 /**
yinxub1bed742017-04-17 11:45:04 -07006301 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006302 *
yinxub1bed742017-04-17 11:45:04 -07006303 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006304 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6305 * location related information which will be sent if the caller already possess
6306 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006307 * @param request contains the radio access networks with bands/channels to scan
6308 * @param messenger callback messenger for scan results or errors
6309 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006310 * @return the id of the requested scan which can be used to stop the scan.
6311 */
6312 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006313 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6314 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006315 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6317 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006318 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006319 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6320 if (!renounceFineLocationAccess) {
6321 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6322 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6323 .setCallingPackage(callingPackage)
6324 .setCallingFeatureId(callingFeatureId)
6325 .setCallingPid(Binder.getCallingPid())
6326 .setCallingUid(Binder.getCallingUid())
6327 .setMethod("requestNetworkScan")
6328 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6329 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6330 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6331 .build());
6332 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006333 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006334 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6335 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006336 if (e != null) {
6337 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6338 throw e;
6339 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006340 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006341 return TelephonyScanManager.INVALID_SCAN_ID;
6342 }
6343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 }
Hall Liu912dfd32019-04-25 14:02:26 -07006345 int callingUid = Binder.getCallingUid();
6346 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006350 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006351 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
yinxu504e1392017-04-12 16:03:22 -07006355 }
6356
Hall Liub2ac8ef2019-02-28 15:56:23 -08006357 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006358 NetworkScanRequest request, int subId, String callingPackage) {
6359 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006360 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6361 boolean hasNetworkScanPermission =
6362 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6363 == PERMISSION_GRANTED;
6364
6365 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6366 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6367 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006368 }
6369
6370 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6371 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6373 return new SecurityException("Specific channels must not be"
6374 + " scanned without location access.");
6375 }
6376 }
6377 }
6378
Hall Liub2ac8ef2019-02-28 15:56:23 -08006379 return null;
6380 }
6381
yinxu504e1392017-04-12 16:03:22 -07006382 /**
6383 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006384 *
6385 * @param subId id of the subscription
6386 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006387 */
6388 @Override
6389 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6391 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392
Hall Liu912dfd32019-04-25 14:02:26 -07006393 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 final long identity = Binder.clearCallingIdentity();
6395 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006396 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 } finally {
6398 Binder.restoreCallingIdentity(identity);
6399 }
yinxu504e1392017-04-12 16:03:22 -07006400 }
6401
6402 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006403 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006404 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006405 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006406 */
6407 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006408 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006409 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006410 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006411 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
6413 final long identity = Binder.clearCallingIdentity();
6414 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006415 if (DBG) log("getAllowedNetworkTypesBitmask");
6416 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6417 int networkTypesBitmask = (result != null ? result[0] : -1);
6418 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6419 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006423 }
6424
6425 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006426 * Get the allowed network types for certain reason.
6427 *
6428 * @param subId the id of the subscription.
6429 * @param reason the reason the allowed network type change is taking place
6430 * @return the allowed network types.
6431 */
6432 @Override
6433 public long getAllowedNetworkTypesForReason(int subId,
6434 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006435 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006436 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006437 final long identity = Binder.clearCallingIdentity();
6438 try {
6439 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444
6445 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006446 * Enable/Disable E-UTRA-NR Dual Connectivity
6447 * @param subId subscription id of the sim card
6448 * @param nrDualConnectivityState expected NR dual connectivity state
6449 * This can be passed following states
6450 * <ol>
6451 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6452 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6453 * <li>Disable NR dual connectivity and force secondary cell to be released
6454 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6455 * </ol>
6456 * @return operation result.
6457 */
6458 @Override
6459 public int setNrDualConnectivityState(int subId,
6460 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6462 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006463 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006464 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6465 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6466 }
6467
Sooraj Sasindran37444802020-08-11 10:40:43 -07006468 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6472 nrDualConnectivityState, subId,
6473 workSource);
6474 if (DBG) log("enableNRDualConnectivity result: " + result);
6475 return result;
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480
6481 /**
6482 * Is E-UTRA-NR Dual Connectivity enabled
6483 * @return true if dual connectivity is enabled else false
6484 */
6485 @Override
6486 public boolean isNrDualConnectivityEnabled(int subId) {
6487 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006488 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006489 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006490 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006491 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6492 return false;
6493 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006494 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6495 final long identity = Binder.clearCallingIdentity();
6496 try {
6497 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6498 null, subId, workSource);
6499 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6500 return isEnabled;
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
6506 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006507 * Set the allowed network types of the device and
6508 * provide the reason triggering the allowed network change.
6509 *
6510 * @param subId the id of the subscription.
6511 * @param reason the reason the allowed network type change is taking place
6512 * @param allowedNetworkTypes the allowed network types.
6513 * @return true on success; false on any failure.
6514 */
6515 @Override
6516 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006517 @TelephonyManager.AllowedNetworkTypesReason int reason,
6518 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6520 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006521 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006522 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6523 return false;
6524 }
6525 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6526 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006527 return false;
6528 }
6529
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006530 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6531 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6532
6533
6534 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6535 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6536 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006538
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006539 final long identity = Binder.clearCallingIdentity();
6540 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 Boolean success = (Boolean) sendRequest(
6542 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6543 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6544
6545 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6546 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
6550 }
6551
6552 /**
Miaoa84611c2019-03-15 09:21:10 +08006553 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006554 *
Miaoa84611c2019-03-15 09:21:10 +08006555 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006556 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006557 * @hide
6558 */
6559 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006560 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006561 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006563 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 try {
Miaoa84611c2019-03-15 09:21:10 +08006565 if (phone != null) {
6566 return phone.hasMatchedTetherApnSetting();
6567 } else {
6568 return false;
6569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006572 }
Junda Liu475951f2014-11-07 16:45:03 -08006573 }
6574
6575 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006576 * Get the user enabled state of Mobile Data.
6577 *
6578 * TODO: remove and use isUserDataEnabled.
6579 * This can't be removed now because some vendor codes
6580 * calls through ITelephony directly while they should
6581 * use TelephonyManager.
6582 *
6583 * @return true on enabled
6584 */
6585 @Override
6586 public boolean getDataEnabled(int subId) {
6587 return isUserDataEnabled(subId);
6588 }
6589
6590 /**
6591 * Get whether mobile data is enabled per user setting.
6592 *
6593 * There are other factors deciding whether mobile data is actually enabled, but they are
6594 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006595 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006596 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6597 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006598 *
6599 * @return {@code true} if data is enabled else {@code false}
6600 */
6601 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006602 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006603 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006604 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006605 try {
6606 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6607 functionName);
6608 } catch (Exception e) {
6609 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6610 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006611 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006613 mApp, subId, functionName);
6614
Robert Greenwalt646120a2014-05-23 11:54:03 -07006615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 int phoneId = mSubscriptionController.getPhoneId(subId);
6620 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6621 Phone phone = PhoneFactory.getPhone(phoneId);
6622 if (phone != null) {
6623 boolean retVal = phone.isUserDataEnabled();
6624 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6625 return retVal;
6626 } else {
6627 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6628 return false;
6629 }
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006632 }
6633 }
6634
6635 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006636 * Checks if the device is capable of mobile data by considering whether whether the
6637 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6638 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006639 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006640 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006641 */
6642 @Override
6643 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006644 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006645 try {
6646 try {
6647 mApp.enforceCallingOrSelfPermission(
6648 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006649 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006650 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006651 try {
6652 mApp.enforceCallingOrSelfPermission(
6653 android.Manifest.permission.READ_PHONE_STATE,
6654 functionName);
6655 } catch (Exception e2) {
6656 mApp.enforceCallingOrSelfPermission(
6657 permission.READ_BASIC_PHONE_STATE, functionName);
6658 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006659 }
6660 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006661 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663
6664 final long identity = Binder.clearCallingIdentity();
6665 try {
6666 int phoneId = mSubscriptionController.getPhoneId(subId);
6667 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6668 Phone phone = PhoneFactory.getPhone(phoneId);
6669 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006670 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6672 return retVal;
6673 } else {
6674 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6675 return false;
6676 }
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006679 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006680 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006681
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006682 /**
6683 * Check if data is enabled for a specific reason
6684 * @param subId Subscription index
6685 * @param reason the reason the data enable change is taking place
6686 * @return {@code true} if the overall data is enabled; {@code false} if not.
6687 */
6688 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006689 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006691 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006692 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006693 try {
6694 mApp.enforceCallingOrSelfPermission(
6695 android.Manifest.permission.ACCESS_NETWORK_STATE,
6696 functionName);
6697 } catch (Exception e) {
6698 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6699 functionName);
6700 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006701 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006702 try {
6703 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006704 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006705 } catch (Exception e2) {
6706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006707 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006708 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006709 }
6710
6711
6712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 int phoneId = mSubscriptionController.getPhoneId(subId);
6715 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006716 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006717 + " reason=" + reason);
6718 }
6719 Phone phone = PhoneFactory.getPhone(phoneId);
6720 if (phone != null) {
6721 boolean retVal;
6722 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6723 retVal = phone.isUserDataEnabled();
6724 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006725 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006727 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 return retVal;
6729 } else {
6730 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006731 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 + subId + " retVal=false");
6733 }
6734 return false;
6735 }
6736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
6739 }
6740
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006741 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006742 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006743 if (uid == Process.PHONE_UID) {
6744 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6745 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006746 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6747 }
6748
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006749 //load access rules from carrier configs, and check those as well: b/139133814
6750 SubscriptionController subController = SubscriptionController.getInstance();
6751 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6752 || subController == null) return privilegeFromSim;
6753
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754 PackageManager pkgMgr = phone.getContext().getPackageManager();
6755 String[] packages = pkgMgr.getPackagesForUid(uid);
6756
6757 final long identity = Binder.clearCallingIdentity();
6758 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006759 int subId = phone.getSubId();
6760 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6761 // A test override is in place for the privileges for this subId, so don't try to
6762 // read the subscription privileges.
6763 return privilegeFromSim;
6764 }
6765 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006766 SubscriptionManager subManager = (SubscriptionManager)
6767 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6768 for (String pkg : packages) {
6769 if (subManager.canManageSubscription(subInfo, pkg)) {
6770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6771 }
6772 }
6773 return privilegeFromSim;
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
6777 }
6778
6779 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6780 String pkgName) {
6781 //load access rules from carrier configs, and check those as well: b/139133814
6782 SubscriptionController subController = SubscriptionController.getInstance();
6783 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6784 || subController == null) return privilegeFromSim;
6785
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006788 int subId = phone.getSubId();
6789 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6790 // A test override is in place for the privileges for this subId, so don't try to
6791 // read the subscription privileges.
6792 return privilegeFromSim;
6793 }
6794 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 SubscriptionManager subManager = (SubscriptionManager)
6796 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6797 return subManager.canManageSubscription(subInfo, pkgName)
6798 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
6802 }
6803
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006804 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006805 public int getCarrierPrivilegeStatus(int subId) {
6806 final Phone phone = getPhone(subId);
6807 if (phone == null) {
6808 loge("getCarrierPrivilegeStatus: Invalid subId");
6809 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6810 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006811 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6812 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006813 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006814 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6815 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006816
6817 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006818 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006819 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006820 }
Junda Liu29340342014-07-10 15:23:27 -07006821
6822 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006823 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006824 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006825 final Phone phone = getPhone(subId);
6826 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006827 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006828 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6829 }
6830 UiccProfile profile =
6831 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6832 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006833 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6835 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006836 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006837 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006838 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 }
6840
6841 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006842 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006843 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006844 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006846 }
6847
6848 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006849 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6850 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006851 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006852 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6853 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006854 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006855 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006856 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006857 }
6858
6859 @Override
6860 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006861 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006862 if (TextUtils.isEmpty(pkgName))
6863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006864 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6865 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006866 UiccPort port = UiccController.getInstance().getUiccPort(i);
6867 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006868 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006869 continue;
6870 }
6871
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006872 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006873 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006874 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006875 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6876 break;
6877 }
6878 }
6879
6880 return result;
Junda Liu29340342014-07-10 15:23:27 -07006881 }
Derek Tan89e89d42014-07-08 17:00:10 -07006882
6883 @Override
Junda Liue64de782015-04-16 17:19:16 -07006884 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006885 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006886 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6887 loge("phoneId " + phoneId + " is not valid.");
6888 return null;
6889 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006890 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6891 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006892 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006893 return null ;
6894 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006895 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006896 }
6897
Amith Yamasani6e118872016-02-19 12:53:51 -08006898 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006899 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006900 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006901 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006902 List<String> privilegedPackages = new ArrayList<>();
6903 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006904 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006905 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006906 if (port != null) {
6907 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006908 if (packages == null) {
6909 // Only check packages in user 0 for now
6910 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006911 PackageManager.MATCH_DISABLED_COMPONENTS
6912 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006913 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006914 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006915 }
6916 for (int p = packages.size() - 1; p >= 0; p--) {
6917 PackageInfo pkgInfo = packages.get(p);
6918 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006919 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006920 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006921 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006922 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006923 privilegedPackages.add(pkgInfo.packageName);
6924 }
6925 }
6926 }
6927 }
6928 return privilegedPackages;
6929 }
6930
chen xuf7e9fe82019-05-09 19:31:02 -07006931 @Override
6932 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006933 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6934
6935 final long identity = Binder.clearCallingIdentity();
6936
chen xuf7e9fe82019-05-09 19:31:02 -07006937 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006938 try {
6939 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6940 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6941 }
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006944 }
6945 return privilegedPackages;
6946 }
6947
Wink Savilleb564aae2014-10-23 10:18:09 -07006948 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006949 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006950 UiccPort port = phone == null ? null : phone.getUiccPort();
6951 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006952 return null;
6953 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006954 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006955 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006956 return null;
6957 }
6958 return iccId;
6959 }
6960
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006961 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006962 public void setCallComposerStatus(int subId, int status) {
6963 enforceModifyPermission();
6964
6965 final long identity = Binder.clearCallingIdentity();
6966 try {
6967 Phone phone = getPhone(subId);
6968 if (phone != null) {
6969 Phone defaultPhone = phone.getImsPhone();
6970 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6971 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6972 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006973 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6974 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006975 }
6976 }
Shuo Qian284ae752020-12-22 19:10:14 -08006977 } catch (ImsException e) {
6978 throw new ServiceSpecificException(e.getCode());
6979 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006980 Binder.restoreCallingIdentity(identity);
6981 }
6982 }
6983
6984 @Override
6985 public int getCallComposerStatus(int subId) {
6986 enforceReadPrivilegedPermission("getCallComposerStatus");
6987
6988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 Phone phone = getPhone(subId);
6991 if (phone != null) {
6992 Phone defaultPhone = phone.getImsPhone();
6993 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6994 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6995 return imsPhone.getCallComposerStatus();
6996 }
6997 }
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7002 }
7003
7004 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007005 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7006 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007007 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007008 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 final String iccId = getIccId(subId);
7013 final Phone phone = getPhone(subId);
7014 if (phone == null) {
7015 return false;
7016 }
7017 final String subscriberId = phone.getSubscriberId();
7018
7019 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007020 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 + subscriberId + " to " + number);
7022 }
7023
7024 if (TextUtils.isEmpty(iccId)) {
7025 return false;
7026 }
7027
7028 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7029
7030 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7031 if (alphaTag == null) {
7032 editor.remove(alphaTagPrefKey);
7033 } else {
7034 editor.putString(alphaTagPrefKey, alphaTag);
7035 }
7036
7037 // Record both the line number and IMSI for this ICCID, since we need to
7038 // track all merged IMSIs based on line number
7039 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7040 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7041 if (number == null) {
7042 editor.remove(numberPrefKey);
7043 editor.remove(subscriberPrefKey);
7044 } else {
7045 editor.putString(numberPrefKey, number);
7046 editor.putString(subscriberPrefKey, subscriberId);
7047 }
7048
7049 editor.commit();
7050 return true;
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007053 }
Derek Tan7226c842014-07-02 17:42:23 -07007054 }
7055
7056 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007057 public String getLine1NumberForDisplay(int subId, String callingPackage,
7058 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007059 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007061 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007062 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007063 return null;
7064 }
Derek Tan97ebb422014-09-05 16:55:38 -07007065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 String iccId = getIccId(subId);
7069 if (iccId != null) {
7070 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7071 if (DBG_MERGE) {
7072 log("getLine1NumberForDisplay returning "
7073 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7074 }
7075 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7078 return null;
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007081 }
Derek Tan7226c842014-07-02 17:42:23 -07007082 }
7083
7084 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007085 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7086 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007088 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007089 return null;
7090 }
Derek Tan97ebb422014-09-05 16:55:38 -07007091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 String iccId = getIccId(subId);
7095 if (iccId != null) {
7096 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7097 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7098 }
7099 return null;
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007102 }
Derek Tan7226c842014-07-02 17:42:23 -07007103 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007104
7105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007106 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7107 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007108 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7109 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007111 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007112 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007113 return null;
7114 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007115
Jordan Liub49b04b2019-05-06 14:45:15 -07007116 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7117 // the process, where TelephonyManager was instantiated.
7118 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007119 final long identity = Binder.clearCallingIdentity();
7120 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 final TelephonyManager tele = TelephonyManager.from(context);
7123 final SubscriptionManager sub = SubscriptionManager.from(context);
7124
7125 // Figure out what subscribers are currently active
7126 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127
Jordan Liub49b04b2019-05-06 14:45:15 -07007128 // Only consider subs which match the current subId
7129 // This logic can be simplified. See b/131189269 for progress.
7130 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007131 activeSubscriberIds.add(tele.getSubscriberId(subId));
7132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133
7134 // First pass, find a number override for an active subscriber
7135 String mergeNumber = null;
7136 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7137 for (String key : prefs.keySet()) {
7138 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7139 final String subscriberId = (String) prefs.get(key);
7140 if (activeSubscriberIds.contains(subscriberId)) {
7141 final String iccId = key.substring(
7142 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7143 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7144 mergeNumber = (String) prefs.get(numberKey);
7145 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007146 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 + " for active subscriber " + subscriberId);
7148 }
7149 if (!TextUtils.isEmpty(mergeNumber)) {
7150 break;
7151 }
7152 }
7153 }
7154 }
7155
7156 // Shortcut when no active merged subscribers
7157 if (TextUtils.isEmpty(mergeNumber)) {
7158 return null;
7159 }
7160
7161 // Second pass, find all subscribers under that line override
7162 final ArraySet<String> result = new ArraySet<>();
7163 for (String key : prefs.keySet()) {
7164 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7165 final String number = (String) prefs.get(key);
7166 if (mergeNumber.equals(number)) {
7167 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7168 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7169 final String subscriberId = (String) prefs.get(subscriberKey);
7170 if (!TextUtils.isEmpty(subscriberId)) {
7171 result.add(subscriberId);
7172 }
7173 }
7174 }
7175 }
7176
7177 final String[] resultArray = result.toArray(new String[result.size()]);
7178 Arrays.sort(resultArray);
7179 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007180 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7182 }
7183 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007184 } finally {
7185 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007186 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007187 }
7188
7189 @Override
zoey chen38003472019-12-13 17:16:31 +08007190 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7191 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007192
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 final TelephonyManager telephonyManager = mApp.getSystemService(
7196 TelephonyManager.class);
7197 String subscriberId = telephonyManager.getSubscriberId(subId);
7198 if (subscriberId == null) {
7199 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007200 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007201 + subId);
7202 }
7203 return null;
7204 }
7205
7206 final SubscriptionInfo info = SubscriptionController.getInstance()
7207 .getSubscriptionInfo(subId);
7208 final ParcelUuid groupUuid = info.getGroupUuid();
7209 // If it doesn't belong to any group, return just subscriberId of itself.
7210 if (groupUuid == null) {
7211 return new String[]{subscriberId};
7212 }
7213
7214 // Get all subscriberIds from the group.
7215 final List<String> mergedSubscriberIds = new ArrayList<>();
7216 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007217 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007218 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007219 for (SubscriptionInfo subInfo : groupInfos) {
7220 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7221 if (subscriberId != null) {
7222 mergedSubscriberIds.add(subscriberId);
7223 }
7224 }
7225
7226 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229
7230 }
7231 }
7232
7233 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007234 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007235 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007236 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 final Phone phone = getPhone(subId);
7241 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007245 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007246
7247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007248 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007249 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7250 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007251 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7252 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 final Phone phone = getPhone(subId);
7257 if (phone == null) {
7258 return false;
7259 }
7260 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7261 cdmaNonRoamingList);
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007264 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007265 }
7266
7267 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007268 @Deprecated
7269 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7270 enforceModifyPermission();
7271
7272 int returnValue = 0;
7273 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007274 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007275 if(result.exception == null) {
7276 if (result.result != null) {
7277 byte[] responseData = (byte[])(result.result);
7278 if(responseData.length > oemResp.length) {
7279 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7280 responseData.length + "bytes. Buffer Size is " +
7281 oemResp.length + "bytes.");
7282 }
7283 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7284 returnValue = responseData.length;
7285 }
7286 } else {
7287 CommandException ex = (CommandException) result.exception;
7288 returnValue = ex.getCommandError().ordinal();
7289 if(returnValue > 0) returnValue *= -1;
7290 }
7291 } catch (RuntimeException e) {
7292 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7293 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7294 if(returnValue > 0) returnValue *= -1;
7295 }
7296
7297 return returnValue;
7298 }
7299
7300 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007301 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007302 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007303 try {
7304 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007305 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007306 mApp, phone.getSubId(), "getRadioAccessFamily");
7307 } catch (SecurityException e) {
7308 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7309 throw e;
7310 }
chen xub97461a2018-10-26 14:17:57 -07007311 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007312 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007313 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 final long identity = Binder.clearCallingIdentity();
7316 try {
chen xub97461a2018-10-26 14:17:57 -07007317 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007318 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007319 mApp, phone.getSubId(), "getRadioAccessFamily");
7320 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
chen xub97461a2018-10-26 14:17:57 -07007324 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007325 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007326
7327 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007328 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007329 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007330 try {
7331 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7332 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007333 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007334 }
7335 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007336 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007337 }
7338 RoleManager rm = mApp.getSystemService(RoleManager.class);
7339 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7340 if (!dialerRoleHolders.contains(callingPackage)) {
7341 throw new SecurityException("App must be the dialer role holder to"
7342 + " upload a call composer pic");
7343 }
7344
7345 Executors.newSingleThreadExecutor().execute(() -> {
7346 ByteArrayOutputStream output = new ByteArrayOutputStream(
7347 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7348 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7349 boolean readUntilEnd = false;
7350 int totalBytesRead = 0;
7351 byte[] buffer = new byte[16 * 1024];
7352 while (true) {
7353 int numRead;
7354 try {
7355 numRead = input.read(buffer);
7356 } catch (IOException e) {
7357 try {
7358 fd.checkError();
7359 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7360 null);
7361 } catch (IOException e1) {
7362 // This means that the other side closed explicitly with an error. If this
7363 // happens, log and ignore.
7364 loge("Remote end of call composer picture pipe closed: " + e1);
7365 }
7366 break;
7367 }
7368 if (numRead == -1) {
7369 readUntilEnd = true;
7370 break;
7371 }
7372 totalBytesRead += numRead;
7373 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7374 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7375 try {
7376 input.close();
7377 } catch (IOException e) {
7378 // ignore
7379 }
7380 break;
7381 }
7382 output.write(buffer, 0, numRead);
7383 }
7384 // Generally, the remote end will close the file descriptors. The only case where we
7385 // close is above, where the picture size is too big.
7386
7387 try {
7388 fd.checkError();
7389 } catch (IOException e) {
7390 loge("Remote end for call composer closed with an error: " + e);
7391 return;
7392 }
7393
Hall Liuaa4211e2021-01-20 15:43:39 -08007394 if (!readUntilEnd) {
7395 loge("Did not finish reading entire image; aborting");
7396 return;
7397 }
Hall Liu82694d52020-12-11 18:22:04 -08007398
Hall Liuaa4211e2021-01-20 15:43:39 -08007399 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7400 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7401 new CallComposerPictureTransfer.Factory() {},
7402 imageData,
7403 (result) -> {
7404 if (result.first != null) {
7405 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7406 Bundle outputResult = new Bundle();
7407 outputResult.putParcelable(
7408 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7409 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7410 outputResult);
7411 } else {
7412 callback.send(result.second, null);
7413 }
7414 }
7415 );
Hall Liu82694d52020-12-11 18:22:04 -08007416 });
7417 }
7418
7419 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007420 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007421 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007422 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423
7424 final long identity = Binder.clearCallingIdentity();
7425 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007426 ImsManager.getInstance(defaultPhone.getContext(),
7427 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007431 }
7432
7433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007434 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7437 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007438 return false;
7439 }
Svet Ganovb320e182015-04-16 12:30:10 -07007440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 // Check the user preference and the system-level IMS setting. Even if the user has
7444 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7445 // In the long run, we may instead need to check if there exists a connection service
7446 // which can support video calling.
7447 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007448 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 return imsManager.isVtEnabledByPlatform()
7450 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7451 && imsManager.isVtEnabledByUser();
7452 } finally {
7453 Binder.restoreCallingIdentity(identity);
7454 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007455 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007456
Andrew Leea1239f22015-03-02 17:44:07 -08007457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007458 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7459 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007461 mApp, subId, callingPackage, callingFeatureId,
7462 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 return false;
7464 }
7465
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 CarrierConfigManager configManager =
7469 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007470 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Andrew Leea1239f22015-03-02 17:44:07 -08007475 }
7476
7477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 return false;
7482 }
7483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 CarrierConfigManager configManager =
7487 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Andrew Leea1239f22015-03-02 17:44:07 -08007493 }
7494
Andrew Lee9431b832015-03-09 18:46:45 -07007495 @Override
7496 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007497 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007498 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007499 }
7500
7501 @Override
7502 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007505 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
Andrew Lee9431b832015-03-09 18:46:45 -07007509 }
7510
Hall Liuf6668912018-10-31 17:05:23 -07007511 /**
7512 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7513 * support for the feature and device firmware support.
7514 *
7515 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7516 */
7517 @Override
7518 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 final Phone phone = getPhone(subscriptionId);
7521 if (phone == null) {
7522 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7523 return false;
7524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7528 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 return isCarrierSupported && isDeviceSupported;
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
7533 }
Hall Liu98187582018-01-22 19:15:32 -08007534 }
7535
Hall Liuf6668912018-10-31 17:05:23 -07007536 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007537 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7538 * RTT setting, will return true if the device and carrier both support RTT.
7539 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007540 */
7541 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 final long identity = Binder.clearCallingIdentity();
7543 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007544 boolean isRttSupported = isRttSupported(subscriptionId);
7545 boolean isUserRttSettingOn = Settings.Secure.getInt(
7546 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7547 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7548 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7549 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007553 }
7554
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007555 @Deprecated
7556 @Override
7557 public String getDeviceId(String callingPackage) {
7558 return getDeviceIdWithFeature(callingPackage, null);
7559 }
7560
Sanket Padawe7310cc72015-01-14 09:53:20 -08007561 /**
7562 * Returns the unique device ID of phone, for example, the IMEI for
7563 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7564 *
7565 * <p>Requires Permission:
7566 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7567 */
7568 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007569 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007570 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007571 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007572 return null;
7573 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007574 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007575 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007577 return null;
7578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 return phone.getDeviceId();
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007586 }
7587
Ping Sunc67b7c22016-03-02 19:16:45 +08007588 /**
7589 * {@hide}
7590 * Returns the IMS Registration Status on a particular subid
7591 *
7592 * @param subId
7593 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007594 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007595 Phone phone = getPhone(subId);
7596 if (phone != null) {
7597 return phone.isImsRegistered();
7598 } else {
7599 return false;
7600 }
7601 }
7602
Santos Cordon7a1885b2015-02-03 11:15:19 -08007603 @Override
7604 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
7610 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007611 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007612
Tyler Gunnf70ed162019-04-03 15:28:53 -07007613 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007614 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007615 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007617 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007618 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7619 }
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
7625 }
7626 }
7627
7628 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007629 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007630 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007631 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007632 mApp,
7633 subscriptionId,
7634 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007635 final long identity = Binder.clearCallingIdentity();
7636 try {
7637 Phone phone = getPhone(subscriptionId);
7638 if (phone == null) {
7639 return null;
7640 }
7641 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
7645 }
7646
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007647 /**
7648 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007649 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007650 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 Phone phone = getPhone(subId);
7654 if (phone != null) {
7655 return phone.isWifiCallingEnabled();
7656 } else {
7657 return false;
7658 }
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007661 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007662 }
7663
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007664 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007665 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007666 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007667 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 final long identity = Binder.clearCallingIdentity();
7669 try {
7670 Phone phone = getPhone(subId);
7671 if (phone != null) {
7672 return phone.isVideoEnabled();
7673 } else {
7674 return false;
7675 }
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007678 }
7679 }
7680
7681 /**
7682 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7683 * defined in {@link ImsRegistrationImplBase}.
7684 */
7685 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 Phone phone = getPhone(subId);
7689 if (phone != null) {
7690 return phone.getImsRegistrationTech();
7691 } else {
7692 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7693 }
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007696 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007697 }
7698
Stuart Scott8eef64f2015-04-08 15:13:54 -07007699 @Override
7700 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007701 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007702 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7703 return;
7704 }
Kai Shif70f46f2021-03-03 13:59:46 -08007705 Phone defaultPhone = getDefaultPhone();
7706 if (defaultPhone != null) {
7707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7708 mApp, getDefaultPhone().getSubId(), "factoryReset");
7709 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007710 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007711
Svet Ganovcc087f82015-05-12 20:35:54 -07007712 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007713 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7714 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007715 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007716 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007717 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007718 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007719 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007720 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007721 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007722 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007723 // There has been issues when Sms raw table somehow stores orphan
7724 // fragments. They lead to garbled message when new fragments come
7725 // in and combined with those stale ones. In case this happens again,
7726 // user can reset all network settings which will clean up this table.
7727 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007728 // Clean up IMS settings as well here.
7729 int slotId = getSlotIndex(subId);
7730 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7731 ImsManager.getInstance(mApp, slotId).factoryReset();
7732 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007733
Kai Shif70f46f2021-03-03 13:59:46 -08007734 if (defaultPhone == null) {
7735 return;
7736 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007737 // Erase modem config if erase modem on network setting is enabled.
7738 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7739 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7740 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007741 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007742 }
Kai Shif70f46f2021-03-03 13:59:46 -08007743
7744 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007745 } finally {
7746 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007747 }
7748 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007749
SongFerngWangfd89b102021-05-27 22:44:54 +08007750 @VisibleForTesting
7751 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7752 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7753 return;
7754 }
7755 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7756 RILConstants.PREFERRED_NETWORK_MODE);
7757 SubscriptionManager.setSubscriptionProperty(subId,
7758 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7759 "user=" + defaultNetworkType);
7760 phone.loadAllowedNetworksFromSubscriptionDatabase();
7761 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7762 defaultNetworkType, null);
7763 }
7764
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007765 private void cleanUpSmsRawTable(Context context) {
7766 ContentResolver resolver = context.getContentResolver();
7767 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7768 resolver.delete(uri, null, null);
7769 }
7770
Narayan Kamath1c496c22015-04-16 14:40:19 +01007771 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007772 public String getSimLocaleForSubscriber(int subId) {
7773 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7774 final Phone phone = getPhone(subId);
7775 if (phone == null) {
7776 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007777 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 final long identity = Binder.clearCallingIdentity();
7780 try {
chen xu5d3637b2019-01-21 23:31:38 -08007781 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007782 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007783 if (info == null) {
7784 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7785 return null;
7786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 // Try and fetch the locale from the carrier properties or from the SIM language
7788 // preferences (EF-PL and EF-LI)...
7789 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007791 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7792 if (localeFromDefaultSim != null) {
7793 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7794 if (DBG) log("Using locale from subId: " + subId + " locale: "
7795 + localeFromDefaultSim);
7796 return localeFromDefaultSim.toLanguageTag();
7797 } else {
7798 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 }
7800 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 // The SIM language preferences only store a language (e.g. fr = French), not an
7803 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7804 // the SIM and carrier preferences does not include a country we add the country
7805 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007806 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007808 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 return mccLocale.toLanguageTag();
7810 }
7811
7812 if (DBG) log("No locale found - returning null");
7813 return null;
7814 } finally {
7815 Binder.restoreCallingIdentity(identity);
7816 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007817 }
7818
7819 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007820 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007821 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007822 }
7823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 /**
7825 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7826 */
7827 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007828 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007829 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007830 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007831
Chenjie Yu1ba97252018-01-11 18:16:20 -08007832 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007833 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007834
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007835 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007836 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7837 * representing the state of the modem.
7838 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007839 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7840 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007841 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007842 */
7843 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007844 public void requestModemActivityInfo(ResultReceiver result) {
7845 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847
7848 final long identity = Binder.clearCallingIdentity();
7849 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007850 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 } finally {
7852 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007853 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007854 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007855
Siddharth Rayb8114062018-06-17 15:02:38 -07007856 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7857 // less than total activity duration.
7858 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7859 if (info == null) {
7860 return false;
7861 }
7862 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007863 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7864 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7865
Siddharth Rayb8114062018-06-17 15:02:38 -07007866 return (info.isValid()
7867 && (info.getSleepTimeMillis() <= activityDurationMs)
7868 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007869 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007870 && (totalTxTimeMs <= activityDurationMs));
7871 }
7872
Jack Yu85bd38a2015-11-09 11:34:32 -08007873 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007874 * Returns the service state information on specified subscription.
7875 */
7876 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007877 public ServiceState getServiceStateForSubscriber(int subId,
7878 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7879 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007881 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007882 return null;
7883 }
7884
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007885 boolean hasFinePermission = false;
7886 boolean hasCoarsePermission = false;
7887 if (!renounceFineLocationAccess) {
7888 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7889 LocationAccessPolicy.checkLocationPermission(mApp,
7890 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7891 .setCallingPackage(callingPackage)
7892 .setCallingFeatureId(callingFeatureId)
7893 .setCallingPid(Binder.getCallingPid())
7894 .setCallingUid(Binder.getCallingUid())
7895 .setMethod("getServiceStateForSubscriber")
7896 .setLogAsInfo(true)
7897 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7899 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7900 .build());
7901 hasFinePermission =
7902 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7903 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007904
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007905 if (!renounceCoarseLocationAccess) {
7906 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7907 LocationAccessPolicy.checkLocationPermission(mApp,
7908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7909 .setCallingPackage(callingPackage)
7910 .setCallingFeatureId(callingFeatureId)
7911 .setCallingPid(Binder.getCallingPid())
7912 .setCallingUid(Binder.getCallingUid())
7913 .setMethod("getServiceStateForSubscriber")
7914 .setLogAsInfo(true)
7915 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7916 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7917 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7918 .build());
7919 hasCoarsePermission =
7920 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7921 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007922
Jack Yu479f40e2020-10-27 21:29:25 -07007923 final Phone phone = getPhone(subId);
7924 if (phone == null) {
7925 return null;
7926 }
7927
Jordan Liu0f2bc442020-11-18 16:47:37 -08007928 final long identity = Binder.clearCallingIdentity();
7929
Jack Yu479f40e2020-10-27 21:29:25 -07007930 boolean isCallingPackageDataService = phone.getDataServicePackages()
7931 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007933 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7934 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7935 Rlog.d(LOG_TAG,
7936 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7937 return null;
7938 }
7939
Hall Liuf19c44f2018-11-27 14:38:17 -08007940 ServiceState ss = phone.getServiceState();
7941
7942 // Scrub out the location info in ServiceState depending on what level of access
7943 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007944 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007945 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7946 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007951
7952 /**
7953 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7954 *
7955 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7956 * voicemail ringtone.
7957 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7958 * PhoneAccount.
7959 */
7960 @Override
7961 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7965 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007966 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
7972 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007973 }
7974
7975 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 * Sets the per-account voicemail ringtone.
7977 *
7978 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7979 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7980 *
7981 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7982 * voicemail ringtone.
7983 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7984 * PhoneAccount.
7985 */
7986 @Override
7987 public void setVoicemailRingtoneUri(String callingPackage,
7988 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007989 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007991 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7992 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7994 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7995 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8001 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 }
8004 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8005 } finally {
8006 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008008 }
8009
8010 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008011 * Returns whether vibration is set for voicemail notification in Phone settings.
8012 *
8013 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8014 * voicemail vibration setting.
8015 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8016 */
8017 @Override
8018 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8022 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008030 }
8031
Youhan Wange64578a2016-05-02 15:32:42 -07008032 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 * Sets the per-account voicemail vibration.
8034 *
8035 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8036 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8037 *
8038 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8039 * voicemail vibration setting.
8040 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8041 * specific PhoneAccount.
8042 */
8043 @Override
8044 public void setVoicemailVibrationEnabled(String callingPackage,
8045 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008046 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008048 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8049 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8051 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8052 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008053 }
8054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8058 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008059 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 }
8061 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008065 }
8066
8067 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008068 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8069 *
8070 * @throws SecurityException if the caller does not have the required permission
8071 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008072 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008073 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008074 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008075 }
8076
8077 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008078 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8079 * permission.
8080 *
8081 * @throws SecurityException if the caller does not have the required permission
8082 */
8083 private void enforceSendSmsPermission() {
8084 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8085 }
8086
8087 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008088 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008090 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008091 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008092 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 final long identity = Binder.clearCallingIdentity();
8094 try {
8095 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 if (componentName == null) {
8098 throw new SecurityException(
8099 "Caller not current active visual voicemail package[null]");
8100 }
8101 String vvmPackage = componentName.getPackageName();
8102 if (!callingPackage.equals(vvmPackage)) {
8103 throw new SecurityException("Caller not current active visual voicemail package["
8104 + vvmPackage + "]");
8105 }
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008108 }
8109 }
8110
8111 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008112 * Return the application ID for the app type.
8113 *
8114 * @param subId the subscription ID that this request applies to.
8115 * @param appType the uicc app type.
8116 * @return Application ID for specificied app type, or null if no uicc.
8117 */
8118 @Override
8119 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008120 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008121 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122
8123 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008124 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 if (phone == null) {
8126 return null;
8127 }
8128 String aid = null;
8129 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008130 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 .getApplicationByType(appType).getAid();
8132 } catch (Exception e) {
8133 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8134 }
8135 return aid;
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008138 }
Youhan Wange64578a2016-05-02 15:32:42 -07008139 }
8140
Youhan Wang4001d252016-05-11 10:29:41 -07008141 /**
8142 * Return the Electronic Serial Number.
8143 *
8144 * @param subId the subscription ID that this request applies to.
8145 * @return ESN or null if error.
8146 */
8147 @Override
8148 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008149 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008150 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151
8152 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008153 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154 if (phone == null) {
8155 return null;
8156 }
8157 String esn = null;
8158 try {
8159 esn = phone.getEsn();
8160 } catch (Exception e) {
8161 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8162 }
8163 return esn;
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008166 }
Youhan Wang4001d252016-05-11 10:29:41 -07008167 }
8168
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008169 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008170 * Return the Preferred Roaming List Version.
8171 *
8172 * @param subId the subscription ID that this request applies to.
8173 * @return PRLVersion or null if error.
8174 */
8175 @Override
8176 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008177 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008178 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179
8180 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 if (phone == null) {
8183 return null;
8184 }
8185 String cdmaPrlVersion = null;
8186 try {
8187 cdmaPrlVersion = phone.getCdmaPrlVersion();
8188 } catch (Exception e) {
8189 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8190 }
8191 return cdmaPrlVersion;
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008194 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008195 }
8196
8197 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008198 * Get snapshot of Telephony histograms
8199 * @return List of Telephony histograms
8200 * @hide
8201 */
8202 @Override
8203 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8205 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 return RIL.getTelephonyRILTimingHistograms();
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008213 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008214
8215 /**
8216 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008217 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8218 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008219 * Require system privileges. In the future we may add this to carrier APIs.
8220 *
Michele Berionne482f8202018-11-27 18:57:59 -08008221 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222 */
8223 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008224 @TelephonyManager.SetCarrierRestrictionResult
8225 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008227 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008228
Michele Berionne482f8202018-11-27 18:57:59 -08008229 if (carrierRestrictionRules == null) {
8230 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008231 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 final long identity = Binder.clearCallingIdentity();
8234 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008235 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008236 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008240 }
8241
8242 /**
8243 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008244 * Get the allowed carrier list and the excluded carrier list, including the priority between
8245 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008246 * Require system privileges. In the future we may add this to carrier APIs.
8247 *
Michele Berionne482f8202018-11-27 18:57:59 -08008248 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008249 */
8250 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008251 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008252 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254
8255 final long identity = Binder.clearCallingIdentity();
8256 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008257 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8258 if (response instanceof CarrierRestrictionRules) {
8259 return (CarrierRestrictionRules) response;
8260 }
8261 // Response is an Exception of some kind,
8262 // which is signalled to the user as a NULL retval
8263 return null;
8264 } catch (Exception e) {
8265 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8266 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008270 }
8271
fionaxu59545b42016-05-25 15:53:37 -07008272 /**
fionaxu59545b42016-05-25 15:53:37 -07008273 * Action set from carrier signalling broadcast receivers to enable/disable radio
8274 * @param subId the subscription ID that this action applies to.
8275 * @param enabled control enable or disable radio.
8276 * {@hide}
8277 */
8278 @Override
8279 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8280 enforceModifyPermission();
8281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282
8283 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008284 if (phone == null) {
8285 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8286 return;
8287 }
8288 try {
8289 phone.carrierActionSetRadioEnabled(enabled);
8290 } catch (Exception e) {
8291 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 } finally {
8293 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008294 }
8295 }
8296
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008297 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008298 * Enable or disable Voice over NR (VoNR)
8299 * @param subId the subscription ID that this action applies to.
8300 * @param enabled enable or disable VoNR.
8301 * @return operation result.
8302 */
8303 @Override
8304 public int setVoNrEnabled(int subId, boolean enabled) {
8305 enforceModifyPermission();
8306 final Phone phone = getPhone(subId);
8307
8308 final long identity = Binder.clearCallingIdentity();
8309 if (phone == null) {
8310 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8311 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8312 }
8313
8314 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8315 try {
8316 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8317 workSource);
8318 if (DBG) log("setVoNrEnabled result: " + result);
8319 return result;
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
8324
8325 /**
8326 * Is voice over NR enabled
8327 * @return true if VoNR is enabled else false
8328 */
8329 @Override
8330 public boolean isVoNrEnabled(int subId) {
8331 enforceReadPrivilegedPermission("isVoNrEnabled");
8332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8336 null, subId, workSource);
8337 if (DBG) log("isVoNrEnabled: " + isEnabled);
8338 return isEnabled;
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008345 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8346 * network status based on which carrier apps could apply actions accordingly,
8347 * enable/disable default url handler for example.
8348 *
8349 * @param subId the subscription ID that this action applies to.
8350 * @param report control start/stop reporting the default network status.
8351 * {@hide}
8352 */
8353 @Override
8354 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8355 enforceModifyPermission();
8356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357
8358 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008359 if (phone == null) {
8360 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8361 return;
8362 }
8363 try {
8364 phone.carrierActionReportDefaultNetworkStatus(report);
8365 } catch (Exception e) {
8366 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 } finally {
8368 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008369 }
8370 }
8371
8372 /**
fionaxud9622282017-07-17 17:51:30 -07008373 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8374 * @param subId the subscription ID that this action applies to.
8375 * {@hide}
8376 */
8377 @Override
8378 public void carrierActionResetAll(int subId) {
8379 enforceModifyPermission();
8380 final Phone phone = getPhone(subId);
8381 if (phone == null) {
8382 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8383 return;
8384 }
8385 try {
8386 phone.carrierActionResetAll();
8387 } catch (Exception e) {
8388 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8389 }
8390 }
8391
8392 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008393 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8394 * bug report is being generated.
8395 */
8396 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008397 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008398 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8399 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008400 writer.println("Permission Denial: can't dump Phone from pid="
8401 + Binder.getCallingPid()
8402 + ", uid=" + Binder.getCallingUid()
8403 + "without permission "
8404 + android.Manifest.permission.DUMP);
8405 return;
8406 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008408 }
Jack Yueb89b242016-06-22 13:27:47 -07008409
Brad Ebingerdac2f002018-04-03 15:17:52 -07008410 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008411 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8412 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8413 @NonNull String[] args) {
8414 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8415 this, in.getFileDescriptor(), out.getFileDescriptor(),
8416 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008417 }
8418
Jack Yueb89b242016-06-22 13:27:47 -07008419 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008420 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008421 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008422 * @param reason the reason the data enable change is taking place
8423 * @param enabled True if enabling the data, otherwise disabling.
8424 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008425 */
8426 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008427 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008428 boolean enabled) {
8429 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8430 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8431 try {
8432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008433 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008434 } catch (SecurityException se) {
8435 enforceModifyPermission();
8436 }
8437 } else {
8438 enforceModifyPermission();
8439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 Phone phone = getPhone(subId);
8444 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008445 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8446 phone.carrierActionSetMeteredApnsEnabled(enabled);
8447 } else {
8448 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 }
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008453 }
8454 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008455
8456 /**
8457 * Get Client request stats
8458 * @return List of Client Request Stats
8459 * @hide
8460 */
8461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008462 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8463 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008466 return null;
8467 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 if (phone != null) {
8473 return phone.getClientRequestStats();
8474 }
8475
8476 return null;
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480 }
8481
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008482 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008483 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008484 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008485 }
Jack Yueb4124c2017-02-16 15:32:43 -08008486
8487 /**
Grace Chen70990072017-03-24 17:21:30 -07008488 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008489 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008490 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008491 * @param state State of SIM (power down, power up, pass through)
8492 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8493 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8494 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008495 *
8496 **/
8497 @Override
Grace Chen70990072017-03-24 17:21:30 -07008498 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008499 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008500 Phone phone = PhoneFactory.getPhone(slotIndex);
8501
vagdeviaf9a5b92018-08-15 16:01:53 -07008502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008507 phone.setSimPowerState(state, null, workSource);
8508 }
8509 } finally {
8510 Binder.restoreCallingIdentity(identity);
8511 }
8512 }
8513
8514 /**
8515 * Set SIM card power state.
8516 *
8517 * @param slotIndex SIM slot id.
8518 * @param state State of SIM (power down, power up, pass through)
8519 * @param callback callback to trigger after success or failure
8520 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8521 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8522 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8523 *
8524 **/
8525 @Override
8526 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8527 IIntegerConsumer callback) {
8528 enforceModifyPermission();
8529 Phone phone = PhoneFactory.getPhone(slotIndex);
8530
8531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8532
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 if (phone != null) {
8536 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8537 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008541 }
8542 }
Shuo Qiandd210312017-04-12 22:11:33 +00008543
Tyler Gunn65d45c22017-06-05 11:22:26 -07008544 private boolean isUssdApiAllowed(int subId) {
8545 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008546 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008547 if (configManager == null) {
8548 return false;
8549 }
8550 PersistableBundle pb = configManager.getConfigForSubId(subId);
8551 if (pb == null) {
8552 return false;
8553 }
8554 return pb.getBoolean(
8555 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8556 }
8557
Shuo Qiandd210312017-04-12 22:11:33 +00008558 /**
8559 * Check if phone is in emergency callback mode
8560 * @return true if phone is in emergency callback mode
8561 * @param subId sub id
8562 */
goneil9c5f4872017-12-05 14:07:56 -08008563 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008564 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008565 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008566 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 if (phone != null) {
8571 return phone.isInEcm();
8572 } else {
8573 return false;
8574 }
8575 } finally {
8576 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008577 }
8578 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008579
8580 /**
8581 * Get the current signal strength information for the given subscription.
8582 * Because this information is not updated when the device is in a low power state
8583 * it should not be relied-upon to be current.
8584 * @param subId Subscription index
8585 * @return the most recent cached signal strength info from the modem
8586 */
8587 @Override
8588 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008589 final long identity = Binder.clearCallingIdentity();
8590 try {
8591 Phone p = getPhone(subId);
8592 if (p == null) {
8593 return null;
8594 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 return p.getSignalStrength();
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008601
Pengquan Meng77b7f132018-08-22 14:49:57 -07008602 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008603 * Get the current modem radio state for the given slot.
8604 * @param slotIndex slot index.
8605 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008606 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008607 * @return the current radio power state from the modem
8608 */
8609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008610 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008611 Phone phone = PhoneFactory.getPhone(slotIndex);
8612 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8614 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008615 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8616 }
8617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 return phone.getRadioPowerState();
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8626 }
8627
8628 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008629 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8630 *
8631 * <p>Requires one of the following permissions:
8632 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008633 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008634 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8635 * privileges.
8636 *
8637 * @param subId subscription id
8638 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8639 * {@code false}.
8640 */
8641 @Override
8642 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008643 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008644 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008645 try {
8646 mApp.enforceCallingOrSelfPermission(
8647 android.Manifest.permission.ACCESS_NETWORK_STATE,
8648 functionName);
8649 } catch (Exception e) {
8650 mApp.enforceCallingOrSelfPermission(
8651 permission.READ_BASIC_PHONE_STATE, functionName);
8652 }
Shuo Qian093013d2020-08-13 15:42:55 -07008653 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008654 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008655 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008656 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008657
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 boolean isEnabled = false;
8659 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008660 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 Phone phone = getPhone(subId);
8662 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 } finally {
8664 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008667 }
8668
8669
8670 /**
8671 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8672 *
8673 * <p> Requires permission:
8674 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8675 * privileges.
8676 *
8677 * @param subId subscription id
8678 * @param isEnabled {@code true} means enable, {@code false} means disable.
8679 */
8680 @Override
8681 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8683 mApp, subId, "setDataRoamingEnabled");
8684
Pengquan Menga1bb6272018-09-06 09:59:22 -07008685 final long identity = Binder.clearCallingIdentity();
8686 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008687 Phone phone = getPhone(subId);
8688 if (phone != null) {
8689 phone.setDataRoamingEnabled(isEnabled);
8690 }
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008693 }
8694 }
8695
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008696 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008697 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008698 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008699 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008700 mApp, subId, "isManualNetworkSelectionAllowed");
8701
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008702 boolean isAllowed = true;
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 Phone phone = getPhone(subId);
8706 if (phone != null) {
8707 isAllowed = phone.isCspPlmnEnabled();
8708 }
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 return isAllowed;
8713 }
8714
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008715 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8716 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8717 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8718 // Update each UiccPort object based on privilege access
8719 UiccPort[] uiccPorts = card.getUiccPortList();
8720 for (UiccPort port : uiccPorts) {
8721 UiccProfile profile = port.getUiccProfile();
8722 if (profile == null ||
8723 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8724 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8725 return false;
8726 }
8727 }
8728 return true;
8729 }
8730
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008731 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008732 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008733 // Verify that tha callingPackage belongs to the calling UID
8734 mApp.getSystemService(AppOpsManager.class)
8735 .checkPackage(Binder.getCallingUid(), callingPackage);
8736
Jordan Liu1e142fc2019-04-22 15:10:43 -07008737 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008738 try {
8739 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008741 } catch (SecurityException e) {
8742 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8743 // has carrier privileges on an active UICC
8744 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8745 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008746 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008747 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008748 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008749
8750 final long identity = Binder.clearCallingIdentity();
8751 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008752 UiccController uiccController = UiccController.getInstance();
8753 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 if (hasReadPermission) {
8755 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008756 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008757
8758 // Remove private info if the caller doesn't have access
8759 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8760 for (UiccCardInfo cardInfo : cardInfos) {
8761 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8762 // is available
8763 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008764 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8765 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8766 if (card == null || card.getUiccPortList().length == 0) {
8767 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768 filteredInfos.add(cardInfo.getUnprivileged());
8769 continue;
8770 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008771
8772 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008773 filteredInfos.add(cardInfo);
8774 } else {
8775 filteredInfos.add(cardInfo.getUnprivileged());
8776 }
8777 }
8778 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008779 } finally {
8780 Binder.restoreCallingIdentity(identity);
8781 }
8782 }
8783
8784 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008785 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008786 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008788 final long identity = Binder.clearCallingIdentity();
8789 try {
8790 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8791 if (slots == null) {
8792 Rlog.i(LOG_TAG, "slots is null.");
8793 return null;
8794 }
8795
8796 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8797 for (int i = 0; i < slots.length; i++) {
8798 UiccSlot slot = slots[i];
8799 if (slot == null) {
8800 continue;
8801 }
8802
Jordan Liu7be7e652019-05-06 18:55:02 +00008803 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008804 UiccCard card = slot.getUiccCard();
8805 if (card != null) {
8806 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008807 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008808 cardId = slot.getEid();
8809 if (TextUtils.isEmpty(cardId)) {
8810 cardId = slot.getIccId();
8811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008812 }
8813
Jordan Liu857451f2019-05-09 16:35:35 -07008814 if (cardId != null) {
8815 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8816 // if cardId is an EID, it's all digits so this is fine
8817 cardId = IccUtils.stripTrailingFs(cardId);
8818 }
8819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008820 int cardState = 0;
8821 switch (slot.getCardState()) {
8822 case CARDSTATE_ABSENT:
8823 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8824 break;
8825 case CARDSTATE_PRESENT:
8826 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8827 break;
8828 case CARDSTATE_ERROR:
8829 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8830 break;
8831 case CARDSTATE_RESTRICTED:
8832 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8833 break;
8834 default:
8835 break;
8836
8837 }
8838
8839 infos[i] = new UiccSlotInfo(
8840 slot.isActive(),
8841 slot.isEuicc(),
8842 cardId,
8843 cardState,
8844 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008845 slot.isExtendedApduSupported(),
8846 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008847 }
8848 return infos;
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008851 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008852 }
8853
8854 @Override
8855 public boolean switchSlots(int[] physicalSlots) {
8856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008864 }
Jack Yu4c988042018-02-27 15:30:01 -08008865
8866 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008867 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008868 final long identity = Binder.clearCallingIdentity();
8869 try {
8870 return UiccController.getInstance().getCardIdForDefaultEuicc();
8871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
8874 }
8875
Pengquan Meng85728fb2018-03-12 16:31:21 -07008876 /**
goneil47ffb6e2018-04-06 15:40:58 -07008877 * A test API to reload the UICC profile.
8878 *
8879 * <p>Requires that the calling app has permission
8880 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8881 * @hide
8882 */
8883 @Override
8884 public void refreshUiccProfile(int subId) {
8885 enforceModifyPermission();
8886
8887 final long identity = Binder.clearCallingIdentity();
8888 try {
8889 Phone phone = getPhone(subId);
8890 if (phone == null) {
8891 return;
8892 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008893 UiccPort uiccPort = phone.getUiccPort();
8894 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008895 return;
8896 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008897 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008898 if (uiccProfile == null) {
8899 return;
8900 }
8901 uiccProfile.refresh();
8902 } finally {
8903 Binder.restoreCallingIdentity(identity);
8904 }
8905 }
8906
8907 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008908 * Returns false if the mobile data is disabled by default, otherwise return true.
8909 */
8910 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008911 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008912 }
8913
8914 /**
8915 * Returns true if the data roaming is enabled by default, i.e the system property
8916 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8917 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8918 */
8919 private boolean getDefaultDataRoamingEnabled(int subId) {
8920 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008921 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008922 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008923 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8924 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8925 return isDataRoamingEnabled;
8926 }
8927
8928 /**
8929 * Returns the default network type for the given {@code subId}, if the default network type is
8930 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8931 */
8932 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008933 List<Integer> list = TelephonyProperties.default_network();
8934 int phoneId = mSubscriptionController.getPhoneId(subId);
8935 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8936 return list.get(phoneId);
8937 }
8938 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008939 }
fionaxua13278b2018-03-21 00:08:13 -07008940
8941 @Override
8942 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008943 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945
8946 final long identity = Binder.clearCallingIdentity();
8947 try {
8948 final Phone phone = getPhone(subId);
8949 if (phone == null) {
8950 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8951 return;
8952 }
chen xueaba88a2019-03-15 13:15:10 -07008953 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8954 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008955 if (carrierPrivilegeRules == null) {
8956 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8957 } else {
8958 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 } finally {
8961 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008962 }
fionaxua13278b2018-03-21 00:08:13 -07008963 }
8964
8965 @Override
8966 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008967 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 final Phone phone = getPhone(subId);
8972 if (phone == null) {
8973 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8974 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8975 }
8976 return phone.getCarrierIdListVersion();
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008979 }
fionaxua13278b2018-03-21 00:08:13 -07008980 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008981
8982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008983 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8984 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008986 mApp, subId, callingPackage, callingFeatureId,
8987 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008988 return -1;
8989 }
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008998
8999 @Override
9000 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009001 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009002 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009003 mApp, subId, "getCdmaRoamingMode");
9004
9005 final long identity = Binder.clearCallingIdentity();
9006 try {
9007 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9008 } finally {
9009 Binder.restoreCallingIdentity(identity);
9010 }
9011 }
9012
9013 @Override
9014 public boolean setCdmaRoamingMode(int subId, int mode) {
9015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9016 mApp, subId, "setCdmaRoamingMode");
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
9026 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009027 public int getCdmaSubscriptionMode(int subId) {
9028 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009029 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009030 mApp, subId, "getCdmaSubscriptionMode");
9031
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009041 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9043 mApp, subId, "setCdmaSubscriptionMode");
9044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009052
sqianc5eccab2018-10-19 18:46:41 -07009053 @Override
sqian8c685422019-02-22 15:55:18 -08009054 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009055 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009057 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9058 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009059 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9060 }
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
sqian854d44b2018-12-12 16:48:18 -08009063 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9064 for (Phone phone: PhoneFactory.getPhones()) {
9065 if (phone.getEmergencyNumberTracker() != null
9066 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9067 emergencyNumberListInternal.put(
9068 phone.getSubId(),
9069 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9070 }
sqian11b7a0e2018-12-05 18:48:28 -08009071 }
sqian854d44b2018-12-12 16:48:18 -08009072 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
sqianc5eccab2018-10-19 18:46:41 -07009076 }
9077
9078 @Override
sqian8c685422019-02-22 15:55:18 -08009079 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009080 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009081 if (!exactMatch) {
9082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009083 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009084 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009085 }
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
sqian854d44b2018-12-12 16:48:18 -08009088 for (Phone phone: PhoneFactory.getPhones()) {
9089 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009090 && phone.getEmergencyNumberTracker()
9091 .isEmergencyNumber(number, exactMatch)) {
9092 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009093 }
sqian11b7a0e2018-12-05 18:48:28 -08009094 }
9095 return false;
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
sqianf4ca7ed2019-01-15 18:32:07 -08009101 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009102 * Start emergency callback mode for GsmCdmaPhone for testing.
9103 */
9104 @Override
9105 public void startEmergencyCallbackMode() {
9106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9107 "startEmergencyCallbackMode");
9108 enforceModifyPermission();
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 for (Phone phone : PhoneFactory.getPhones()) {
9112 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9113 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9114 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9115 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9116 gsmCdmaPhone.obtainMessage(
9117 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9118 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9119 }
9120 }
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
9125
9126 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009127 * Update emergency number list for test mode.
9128 */
9129 @Override
9130 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9132 "updateEmergencyNumberListTestMode");
9133
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
9136 for (Phone phone: PhoneFactory.getPhones()) {
9137 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9138 if (tracker != null) {
9139 tracker.executeEmergencyNumberTestModeCommand(action, num);
9140 }
9141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
9146
9147 /**
9148 * Get the full emergency number list for test mode.
9149 */
9150 @Override
9151 public List<String> getEmergencyNumberListTestMode() {
9152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9153 "getEmergencyNumberListTestMode");
9154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
9157 Set<String> emergencyNumbers = new HashSet<>();
9158 for (Phone phone: PhoneFactory.getPhones()) {
9159 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9160 if (tracker != null) {
9161 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9162 emergencyNumbers.add(num.getNumber());
9163 }
9164 }
9165 }
9166 return new ArrayList<>(emergencyNumbers);
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
9170 }
9171
chen xud6b45bd2018-10-30 22:27:10 -07009172 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009173 public int getEmergencyNumberDbVersion(int subId) {
9174 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9175
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
9178 final Phone phone = getPhone(subId);
9179 if (phone == null) {
9180 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9181 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9182 }
9183 return phone.getEmergencyNumberDbVersion();
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
9189 @Override
9190 public void notifyOtaEmergencyNumberDbInstalled() {
9191 enforceModifyPermission();
9192
9193 final long identity = Binder.clearCallingIdentity();
9194 try {
9195 for (Phone phone: PhoneFactory.getPhones()) {
9196 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9197 if (tracker != null) {
9198 tracker.updateOtaEmergencyNumberDatabase();
9199 }
9200 }
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
9206 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009207 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009208 enforceActiveEmergencySessionPermission();
9209
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
9212 for (Phone phone: PhoneFactory.getPhones()) {
9213 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9214 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009215 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9216 }
9217 }
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 }
9222
9223 @Override
9224 public void resetOtaEmergencyNumberDbFilePath() {
9225 enforceActiveEmergencySessionPermission();
9226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 for (Phone phone: PhoneFactory.getPhones()) {
9230 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9231 if (tracker != null) {
9232 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009233 }
9234 }
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
9240 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009241 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9242 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9243 Phone phone = getPhone(subId);
9244 if (phone == null) {
9245 return null;
9246 }
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 UiccProfile profile = UiccController.getInstance()
9250 .getUiccProfileForPhone(phone.getPhoneId());
9251 if (profile != null) {
9252 return profile.getCertsFromCarrierPrivilegeAccessRules();
9253 }
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 return null;
9258 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009259
9260 /**
9261 * Enable or disable a modem stack.
9262 */
9263 @Override
9264 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9265 enforceModifyPermission();
9266
9267 final long identity = Binder.clearCallingIdentity();
9268 try {
9269 Phone phone = PhoneFactory.getPhone(slotIndex);
9270 if (phone == null) {
9271 return false;
9272 } else {
9273 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9274 }
9275 } finally {
9276 Binder.restoreCallingIdentity(identity);
9277 }
9278 }
Michelecea4cf22018-12-21 15:00:11 -08009279
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009280 /**
9281 * Whether a modem stack is enabled or not.
9282 */
9283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009284 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9285 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009286 Phone phone = PhoneFactory.getPhone(slotIndex);
9287 if (phone == null) return false;
9288
9289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009290 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9291 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009292 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9293 }
9294
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009297 try {
9298 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9299 } catch (NoSuchElementException ex) {
9300 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9301 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
Michelecea4cf22018-12-21 15:00:11 -08009307 @Override
Michele0ea7d782019-03-19 14:58:42 -07009308 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009309 enforceModifyPermission();
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009314 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009315 .commit();
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 @Override
Michele0ea7d782019-03-19 14:58:42 -07009322 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009323 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009325 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9326 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009327 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009328 }
Michelecea4cf22018-12-21 15:00:11 -08009329
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
Michele0ea7d782019-03-19 14:58:42 -07009332 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009333 } finally {
9334 Binder.restoreCallingIdentity(identity);
9335 }
9336 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009337
Michele0ea7d782019-03-19 14:58:42 -07009338 @TelephonyManager.IsMultiSimSupportedResult
9339 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009340 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9341 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9342 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009343 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9344 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009345 }
9346 // Check if the hardware supports multisim functionality. If usage of multisim is not
9347 // supported by the modem, indicate that it is restricted.
9348 PhoneCapability staticCapability =
9349 mPhoneConfigurationManager.getStaticPhoneCapability();
9350 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009351 loge("isMultiSimSupportedInternal: no static configuration available");
9352 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009353 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009354 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009355 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9356 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009357 }
9358 // Check if support of multiple SIMs is restricted by carrier
9359 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009360 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009361 }
9362
Michele0ea7d782019-03-19 14:58:42 -07009363 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009364 }
9365
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009366 /**
9367 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009368 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9369 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9370 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009371 * @param numOfSims number of active sims we want to switch to
9372 */
9373 @Override
9374 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009375 if (numOfSims == 1) {
9376 enforceModifyPermission();
9377 } else {
9378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9379 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9380 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009381 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009382
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009383 try {
Michele30b57b22019-03-01 12:01:14 -08009384 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009385 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009386 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9387 return;
9388 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009389 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9390 } finally {
9391 Binder.restoreCallingIdentity(identity);
9392 }
9393 }
9394
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009395 @Override
9396 public boolean isApplicationOnUicc(int subId, int appType) {
9397 enforceReadPrivilegedPermission("isApplicationOnUicc");
9398 Phone phone = getPhone(subId);
9399 if (phone == null) {
9400 return false;
9401 }
9402 final long identity = Binder.clearCallingIdentity();
9403 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009404 UiccPort uiccPort = phone.getUiccPort();
9405 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009406 return false;
9407 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009408 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009409 if (uiccProfile == null) {
9410 return false;
9411 }
9412 if (TelephonyManager.APPTYPE_SIM <= appType
9413 && appType <= TelephonyManager.APPTYPE_ISIM) {
9414 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9415 }
9416 return false;
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009422 /**
chen xub4baa772019-04-03 10:23:41 -07009423 * Get whether making changes to modem configurations will trigger reboot.
9424 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009425 */
9426 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009427 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9428 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009430 mApp, subId, callingPackage, callingFeatureId,
9431 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009432 return false;
9433 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
Nathan Harold29f5f052019-02-15 13:41:57 -08009442 private void updateModemStateMetrics() {
9443 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9444 // TODO: check the state for each modem if the api is ready.
9445 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9446 }
9447
Pengquan Meng3889a572019-01-23 11:16:29 -08009448 @Override
9449 public int[] getSlotsMapping() {
9450 enforceReadPrivilegedPermission("getSlotsMapping");
9451
9452 final long identity = Binder.clearCallingIdentity();
9453 try {
9454 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9455 // All logical slots should have a mapping to a physical slot.
9456 int[] logicalSlotsMapping = new int[phoneCount];
9457 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9458 for (int i = 0; i < slotInfos.length; i++) {
9459 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9460 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9461 }
9462 }
9463 return logicalSlotsMapping;
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009468
9469 /**
9470 * Get the IRadio HAL Version
9471 */
9472 @Override
9473 public int getRadioHalVersion() {
9474 Phone phone = getDefaultPhone();
9475 if (phone == null) return -1;
9476 HalVersion hv = phone.getHalVersion();
9477 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9478 return hv.major * 100 + hv.minor;
9479 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009480
9481 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009482 * Get the current calling package name.
9483 * @return the current calling package name
9484 */
9485 @Override
9486 public String getCurrentPackageName() {
9487 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9488 }
9489
9490 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009491 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9492 * corresponding network requests on a subId.
9493 *
9494 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009495 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009496 * 2) APN is un-metered for this subscription, or
9497 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009498 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009499 *
9500 * @return whether data is allowed for a apn type.
9501 *
9502 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009503 */
9504 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009505 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009506 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9507 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009508
9509 // Now that all security checks passes, perform the operation as ourselves.
9510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 Phone phone = getPhone(subId);
9513 if (phone == null) return false;
9514
Jack Yu41407ee2019-05-13 16:54:09 -07009515 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009516 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
9522 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009523 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009524 enforceReadPrivilegedPermission("isApnMetered");
9525
9526 // Now that all security checks passes, perform the operation as ourselves.
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
9529 Phone phone = getPhone(subId);
9530 if (phone == null) return true; // By default return true.
9531
Jack Yu41407ee2019-05-13 16:54:09 -07009532 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009537
9538 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009539 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9540 int subscriptionId, IBooleanConsumer resultCallback) {
9541 enforceModifyPermission();
9542 long token = Binder.clearCallingIdentity();
9543 try {
9544 Phone phone = getPhone(subscriptionId);
9545 if (phone == null) {
9546 try {
9547 if (resultCallback != null) {
9548 resultCallback.accept(false);
9549 }
9550 } catch (RemoteException e) {
9551 // ignore
9552 }
9553 return;
9554 }
9555 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9556 Pair.create(specifiers, (x) -> {
9557 try {
9558 if (resultCallback != null) {
9559 resultCallback.accept(x);
9560 }
9561 } catch (RemoteException e) {
9562 // ignore
9563 }
9564 });
9565 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9566 } finally {
9567 Binder.restoreCallingIdentity(token);
9568 }
9569 }
9570
9571 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009572 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9573 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009574 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009575 mApp, subId, "getSystemSelectionChannels");
9576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009579 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9580 if (result instanceof IllegalStateException) {
9581 throw (IllegalStateException) result;
9582 }
9583 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009584 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9585 return specifiers;
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
9590
9591 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009592 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009593 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009594 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9595 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9596 if (iccRecords == null) {
9597 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9598 return false;
9599 }
9600 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9601 }
9602
9603 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009604 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9605 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009606 if (callingPackage == null) {
9607 callingPackage = getCurrentPackageName();
9608 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009609 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9610 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009611 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9612 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009613 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9614 }
9615 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9616 Intent intent = new Intent();
9617 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9618 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9619 // Bring up choose default SMS subscription dialog right now
9620 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9621 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9622 mApp.startActivity(intent);
9623 }
chen xud5ca2d52019-05-28 15:20:57 -07009624
9625 @Override
9626 public String getMmsUAProfUrl(int subId) {
9627 //TODO investigate if this API should require proper permission check in R b/133791609
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009630 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9631 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9632 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9633 return carrierUAProfUrl;
9634 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009635 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9636 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009637 } finally {
9638 Binder.restoreCallingIdentity(identity);
9639 }
9640 }
9641
9642 @Override
9643 public String getMmsUserAgent(int subId) {
9644 //TODO investigate if this API should require proper permission check in R b/133791609
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009647 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9648 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9649 if (!TextUtils.isEmpty(carrierUserAgent)) {
9650 return carrierUserAgent;
9651 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009652 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9653 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009654 } finally {
9655 Binder.restoreCallingIdentity(identity);
9656 }
9657 }
Jack Yub07d4972019-05-28 16:12:25 -07009658
9659 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009660 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9661 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009662
Jack Yub07d4972019-05-28 16:12:25 -07009663 final long identity = Binder.clearCallingIdentity();
9664 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009665 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009666 if (phone == null) return false;
9667
Hall Liua62f5da2020-09-25 10:42:19 -07009668 switch (policy) {
9669 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9670 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9671 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9672 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9673 default:
9674 throw new IllegalArgumentException(policy + " is not a valid policy");
9675 }
Jack Yub07d4972019-05-28 16:12:25 -07009676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680
9681 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009682 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009683 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009684 enforceModifyPermission();
9685
changbettyd5c246e2019-12-24 15:40:37 +08009686 final long identity = Binder.clearCallingIdentity();
9687 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009688 Phone phone = getPhone(subscriptionId);
9689 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009690
Hall Liua62f5da2020-09-25 10:42:19 -07009691 switch (policy) {
9692 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9693 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9694 break;
9695 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9696 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9697 break;
9698 default:
9699 throw new IllegalArgumentException(policy + " is not a valid policy");
9700 }
changbettyd5c246e2019-12-24 15:40:37 +08009701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009706 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009707 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009708 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9709 * otherwise.
9710 */
9711 @Override
9712 public void setCepEnabled(boolean isCepEnabled) {
9713 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9714
9715 final long identity = Binder.clearCallingIdentity();
9716 try {
9717 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9718 for (Phone phone : PhoneFactory.getPhones()) {
9719 Phone defaultPhone = phone.getImsPhone();
9720 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9721 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9722 ImsPhoneCallTracker imsPhoneCallTracker =
9723 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9724 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9725 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9726 + imsPhone.getMsisdn());
9727 }
9728 }
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
allenwtsu46dcc572020-01-08 18:24:03 +08009733
9734 /**
9735 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9736 *
9737 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9738 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9739 * before being read.
9740 */
9741 @Override
9742 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9743 isCompressed) {
9744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9745 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9747 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9748 }
9749 if (!isImsAvailableOnDevice()) {
9750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9751 "IMS not available on device.");
9752 }
9753
9754 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009755 try {
Hui Wang761a6682020-10-31 05:12:53 +00009756 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9757 } finally {
9758 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009759 }
9760 }
zoey chene02881a2019-12-30 16:11:23 +08009761
9762 @Override
9763 public boolean isIccLockEnabled(int subId) {
9764 enforceReadPrivilegedPermission("isIccLockEnabled");
9765
9766 // Now that all security checks passes, perform the operation as ourselves.
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 Phone phone = getPhone(subId);
9770 if (phone != null && phone.getIccCard() != null) {
9771 return phone.getIccCard().getIccLockEnabled();
9772 } else {
9773 return false;
9774 }
9775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 /**
9781 * Set the ICC pin lock enabled or disabled.
9782 *
9783 * @return an integer representing the status of IccLock enabled or disabled in the following
9784 * three cases:
9785 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9786 * successfully.
9787 * - Positive number and zero for remaining password attempts.
9788 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9789 *
9790 */
9791 @Override
9792 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9793 enforceModifyPermission();
9794
9795 Phone phone = getPhone(subId);
9796 if (phone == null) {
9797 return 0;
9798 }
9799 // Now that all security checks passes, perform the operation as ourselves.
9800 final long identity = Binder.clearCallingIdentity();
9801 try {
9802 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9803 new Pair<Boolean, String>(enabled, password), phone, null);
9804 return attemptsRemaining;
9805
9806 } catch (Exception e) {
9807 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 return 0;
9812 }
9813
9814 /**
9815 * Change the ICC password used in ICC pin lock.
9816 *
9817 * @return an integer representing the status of IccLock changed in the following three cases:
9818 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9819 * - Positive number and zero for remaining password attempts.
9820 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9821 *
9822 */
9823 @Override
9824 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9825 enforceModifyPermission();
9826
9827 Phone phone = getPhone(subId);
9828 if (phone == null) {
9829 return 0;
9830 }
9831 // Now that all security checks passes, perform the operation as ourselves.
9832 final long identity = Binder.clearCallingIdentity();
9833 try {
9834 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9835 new Pair<String, String>(oldPassword, newPassword), phone, null);
9836 return attemptsRemaining;
9837
9838 } catch (Exception e) {
9839 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 return 0;
9844 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009845
9846 /**
9847 * Request for receiving user activity notification
9848 */
9849 @Override
9850 public void requestUserActivityNotification() {
9851 if (!mNotifyUserActivity.get()
9852 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9853 mNotifyUserActivity.set(true);
9854 }
9855 }
9856
9857 /**
9858 * Called when userActivity is signalled in the power manager.
9859 * This is safe to call from any thread, with any window manager locks held or not.
9860 */
9861 @Override
9862 public void userActivity() {
9863 // ***************************************
9864 // * Inherited from PhoneWindowManager *
9865 // ***************************************
9866 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9867 // WITH ITS LOCKS HELD.
9868 //
9869 // This code must be VERY careful about the locks
9870 // it acquires.
9871 // In fact, the current code acquires way too many,
9872 // and probably has lurking deadlocks.
9873
9874 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9875 throw new SecurityException("Only the OS may call notifyUserActivity()");
9876 }
9877
9878 if (mNotifyUserActivity.getAndSet(false)) {
9879 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9880 USER_ACTIVITY_NOTIFICATION_DELAY);
9881 }
9882 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009883
9884 @Override
9885 public boolean canConnectTo5GInDsdsMode() {
9886 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9887 }
Jack Yud10cdd42020-09-28 20:28:01 -07009888
9889 @Override
9890 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9891 String callingFeatureId) {
9892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9893 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9894 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9895 }
9896
9897 Phone phone = getPhone(subId);
9898 if (phone == null) {
9899 throw new RuntimeException("phone is not available");
9900 }
9901 // Now that all security checks passes, perform the operation as ourselves.
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
9904 return phone.getEquivalentHomePlmns();
9905 } finally {
9906 Binder.restoreCallingIdentity(identity);
9907 }
9908 }
Daniel Bright59e67312020-11-13 11:49:37 -08009909
9910 @Override
9911 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009912 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9913 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009914 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009915 if (radioInterfaceCapabilities == null) {
9916 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009917 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009918 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009919 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009920
Hui Wang641e81c2020-10-12 12:14:23 -07009921 @Override
9922 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9923 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009924 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9925 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9926 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9927 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9928 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009929 if (DBG) {
9930 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9931 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9932 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9933 }
9934
9935 if (!SubscriptionManager.isValidSubscriptionId(subId)
9936 || appType < TelephonyManager.APPTYPE_UNKNOWN
9937 || appType > TelephonyManager.APPTYPE_ISIM
9938 || nafUrl == null || securityProtocol == null || callback == null) {
9939 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9940 if (callback != null) {
9941 try {
9942 callback.onAuthenticationFailure(
9943 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9944 } catch (RemoteException exception) {
9945 log("Fail to notify onAuthenticationFailure due to " + exception);
9946 }
9947 return;
9948 }
9949 }
9950
9951 final long token = Binder.clearCallingIdentity();
9952 try {
9953 getGbaManager(subId).bootstrapAuthenticationRequest(
9954 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9955 forceBootStrapping, callback));
9956 } finally {
9957 Binder.restoreCallingIdentity(token);
9958 }
9959 }
9960
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009961 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009962 * Attempts to set the radio power state for all phones for thermal reason.
9963 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009964 * requested radio power state will actually be set. See {@link
9965 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9966 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009967 * @param enable {@code true} if trying to turn radio on.
9968 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9969 * false}.
9970 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009971 private boolean setRadioPowerForThermal(boolean enable) {
9972 boolean isPhoneAvailable = false;
9973 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9974 Phone phone = PhoneFactory.getPhone(i);
9975 if (phone != null) {
9976 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9977 isPhoneAvailable = true;
9978 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009979 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009980
9981 // return true if successfully informed the phone object about the thermal radio power
9982 // request.
9983 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009984 }
9985
9986 private int handleDataThrottlingRequest(int subId,
9987 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009988 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9989 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9990 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9991 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9992 throw new IllegalArgumentException("modem does not support data throttling");
9993 }
9994
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009995 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9996 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009997 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009998 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9999 }
10000
10001 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10002
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010003 if (isDataThrottlingSupported) {
10004 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010005 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010006 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10007 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10008 } else if (thermalMitigationResult
10009 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010010 log("Modem likely does not support data throttling on secondary carrier. Data " +
10011 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10012 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010013 }
10014 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010015 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010016
10017 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010018 }
10019
Jack Nudelman644b91a2021-03-12 14:09:48 -080010020 private static List<String> getThermalMitigationAllowlist(Context context) {
10021 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10022 for (String pckg : context.getResources()
10023 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10024 sThermalMitigationAllowlistedPackages.add(pckg);
10025 }
10026 }
10027
10028 return sThermalMitigationAllowlistedPackages;
10029 }
10030
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010031 private boolean isAnyPhoneInEmergencyState() {
10032 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10033 if (tm.isInEmergencyCall()) {
10034 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10035 return true;
10036 }
10037 for (Phone phone : PhoneFactory.getPhones()) {
10038 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10039 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10040 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10041 + phone.isInEcm());
10042 return true;
10043 }
10044 }
10045
10046 return false;
10047 }
10048
Jack Nudelman644b91a2021-03-12 14:09:48 -080010049 /**
10050 * Used by shell commands to add an authorized package name for thermal mitigation.
10051 * @param packageName name of package to be allowlisted
10052 * @param context
10053 */
10054 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10055 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10056 sThermalMitigationAllowlistedPackages.add(packageName);
10057 }
10058
10059 /**
10060 * Used by shell commands to remove an authorized package name for thermal mitigation.
10061 * @param packageName name of package to remove from allowlist
10062 * @param context
10063 */
10064 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10065 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10066 sThermalMitigationAllowlistedPackages.remove(packageName);
10067 }
10068
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010069 /**
10070 * Thermal mitigation request to control functionalities at modem.
10071 *
10072 * @param subId the id of the subscription.
10073 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010074 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010075 *
10076 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10077 */
10078 @Override
10079 @ThermalMitigationResult
10080 public int sendThermalMitigationRequest(
10081 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010082 ThermalMitigationRequest thermalMitigationRequest,
10083 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010084 enforceModifyPermission();
10085
Jack Nudelman644b91a2021-03-12 14:09:48 -080010086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10087 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10088 .contains(callingPackage)) {
10089 throw new SecurityException("Calling package must be configured in the device config. "
10090 + "calling package: " + callingPackage);
10091 }
10092
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10094 final long identity = Binder.clearCallingIdentity();
10095
10096 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10097 try {
10098 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10099 switch (thermalMitigationAction) {
10100 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10101 thermalMitigationResult =
10102 handleDataThrottlingRequest(subId,
10103 thermalMitigationRequest.getDataThrottlingRequest());
10104 break;
10105 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10106 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10107 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10108 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10109 }
10110
10111 // Ensure that radio is on. If not able to power on due to phone being
10112 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010113 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 thermalMitigationResult =
10115 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10116 break;
10117 }
10118
10119 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10120 false);
10121 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10122 break;
10123 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10124 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10125 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10126 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10127 }
10128
10129 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10130 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 Phone phone = getPhone(subId);
10132 if (phone == null) {
10133 thermalMitigationResult =
10134 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10135 break;
10136 }
10137
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010138 TelephonyConnectionService service =
10139 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010140 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010141 Log.e(LOG_TAG, "An emergency call is pending");
10142 thermalMitigationResult =
10143 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10144 break;
10145 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010146 thermalMitigationResult =
10147 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10148 break;
10149 }
10150 } else {
10151 thermalMitigationResult =
10152 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10153 break;
10154 }
10155
10156 // Turn radio off. If not able to power off due to phone being unavailable,
10157 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010158 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010159 thermalMitigationResult =
10160 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10161 break;
10162 }
10163 thermalMitigationResult =
10164 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10165 break;
10166 default:
10167 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10168 + "not exist. Requested action: " + thermalMitigationAction);
10169 }
10170 } catch (IllegalArgumentException e) {
10171 throw e;
10172 } catch (Exception e) {
10173 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10174 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10175 } finally {
10176 Binder.restoreCallingIdentity(identity);
10177 }
10178
10179 if (DBG) {
10180 log("thermalMitigationRequest returning with thermalMitigationResult: "
10181 + thermalMitigationResult);
10182 }
10183
10184 return thermalMitigationResult;
10185 }
Hui Wang641e81c2020-10-12 12:14:23 -070010186
10187 /**
10188 * Set the GbaService Package Name that Telephony will bind to.
10189 *
10190 * @param subId The sim that the GbaService is associated with.
10191 * @param packageName The name of the package to be replaced with.
10192 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10193 */
10194 @Override
10195 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10196 enforceModifyPermission();
10197
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return getGbaManager(subId).overrideServicePackage(packageName);
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
10206 /**
10207 * Return the package name of the currently bound GbaService.
10208 *
10209 * @param subId The sim that the GbaService is associated with.
10210 * @return the package name of the GbaService configuration, null if GBA is not supported.
10211 */
10212 @Override
10213 public String getBoundGbaService(int subId) {
10214 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10215
10216 final long identity = Binder.clearCallingIdentity();
10217 try {
10218 return getGbaManager(subId).getServicePackage();
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
10223
10224 /**
10225 * Set the release time for telephony to unbind GbaService.
10226 *
10227 * @param subId The sim that the GbaService is associated with.
10228 * @param interval The release time to unbind GbaService by millisecond.
10229 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10230 */
10231 @Override
10232 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10233 enforceModifyPermission();
10234
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 return getGbaManager(subId).overrideReleaseTime(interval);
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 /**
10244 * Return the release time for telephony to unbind GbaService.
10245 *
10246 * @param subId The sim that the GbaService is associated with.
10247 * @return The release time to unbind GbaService by millisecond.
10248 */
10249 @Override
10250 public int getGbaReleaseTime(int subId) {
10251 enforceReadPrivilegedPermission("getGbaReleaseTime");
10252
10253 final long identity = Binder.clearCallingIdentity();
10254 try {
10255 return getGbaManager(subId).getReleaseTime();
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
10261 private GbaManager getGbaManager(int subId) {
10262 GbaManager instance = GbaManager.getInstance(subId);
10263 if (instance == null) {
10264 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10265 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10266 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10267 }
10268 return instance;
10269 }
Hui Wang761a6682020-10-31 05:12:53 +000010270
10271 /**
10272 * indicate whether the device and the carrier can support
10273 * RCS VoLTE single registration.
10274 */
10275 @Override
10276 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010277 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10278 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10279 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10280 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010281
10282 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10283 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10284 }
10285
10286 final long identity = Binder.clearCallingIdentity();
10287 try {
10288 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10289 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010290 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10291 if (isCapable != null) {
10292 return isCapable;
10293 }
Hui Wang761a6682020-10-31 05:12:53 +000010294 }
Hui Wang67af90e2021-06-04 16:57:15 -070010295 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10296 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
10300 }
10301
10302 /**
10303 * Register RCS provisioning callback.
10304 */
10305 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010306 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010307 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010308 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010309 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010310 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10311 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010312
10313 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10314 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10315 }
10316 if (!isImsAvailableOnDevice()) {
10317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10318 "IMS not available on device.");
10319 }
10320
10321 final long identity = Binder.clearCallingIdentity();
10322 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010323 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010324 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010325 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10326 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010327 }
Hui Wang761a6682020-10-31 05:12:53 +000010328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
10332
10333 /**
10334 * Unregister RCS provisioning callback.
10335 */
10336 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010337 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010338 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010339 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010340 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010341 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10342 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010343
10344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10346 }
10347 if (!isImsAvailableOnDevice()) {
10348 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10349 "IMS not available on device.");
10350 }
10351
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010354 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010355 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 /**
10362 * trigger RCS reconfiguration.
10363 */
10364 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010365 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10366 "triggerRcsReconfiguration",
10367 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010368
10369 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10370 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10371 }
10372 if (!isImsAvailableOnDevice()) {
10373 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10374 "IMS not available on device.");
10375 }
10376
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Provide the client configuration parameters of the RCS application.
10387 */
10388 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010389 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10390 "setRcsClientConfiguration",
10391 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010392
10393 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10394 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10395 }
10396 if (!isImsAvailableOnDevice()) {
10397 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10398 "IMS not available on device.");
10399 }
10400
10401 final long identity = Binder.clearCallingIdentity();
10402
10403 try {
10404 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10405 if (configBinder == null) {
10406 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010407 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10408 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010409 } else {
10410 configBinder.setRcsClientConfiguration(rcc);
10411 }
joonhunshin35f64142021-09-17 06:33:39 +000010412
10413 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10414 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010415 } catch (RemoteException e) {
10416 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010417 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10418 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010419 } finally {
10420 Binder.restoreCallingIdentity(identity);
10421 }
10422 }
10423
10424 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010425 * Enables or disables the test mode for RCS VoLTE single registration.
10426 */
10427 @Override
10428 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10429 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10430 "setRcsSingleRegistrationTestModeEnabled");
10431
10432 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10433 }
10434
10435 /**
10436 * Gets the test mode for RCS VoLTE single registration.
10437 */
10438 @Override
10439 public boolean getRcsSingleRegistrationTestModeEnabled() {
10440 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10441 "getRcsSingleRegistrationTestModeEnabled");
10442
10443 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10444 }
10445
10446 /**
Hui Wang761a6682020-10-31 05:12:53 +000010447 * Overrides the config of RCS VoLTE single registration enabled for the device.
10448 */
10449 @Override
10450 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10452 "setDeviceSingleRegistrationEnabledOverride");
10453 enforceModifyPermission();
10454
10455 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10456 : Boolean.parseBoolean(enabledStr);
10457 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010458 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010459 }
10460
10461 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010462 * Sends a device to device communication message. Only usable via shell.
10463 * @param message message to send.
10464 * @param value message value.
10465 */
10466 @Override
10467 public void sendDeviceToDeviceMessage(int message, int value) {
10468 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010469 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010470 enforceModifyPermission();
10471
10472 final long identity = Binder.clearCallingIdentity();
10473 try {
10474 TelephonyConnectionService service =
10475 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10476 if (service == null) {
10477 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10478 return;
10479 }
10480 service.sendTestDeviceToDeviceMessage(message, value);
10481 } finally {
10482 Binder.restoreCallingIdentity(identity);
10483 }
10484 }
10485
Tyler Gunnbabbda02021-02-10 11:05:02 -080010486 /**
10487 * Sets the specified device to device transport active.
10488 * @param transport The transport to set active.
10489 */
10490 @Override
10491 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10492 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10493 "setActiveDeviceToDeviceTransport");
10494 enforceModifyPermission();
10495
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 TelephonyConnectionService service =
10499 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10500 if (service == null) {
10501 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10502 return;
10503 }
10504 service.setActiveDeviceToDeviceTransport(transport);
10505 } finally {
10506 Binder.restoreCallingIdentity(identity);
10507 }
10508 }
Tyler Gunn92479152021-01-20 16:30:10 -080010509
Tyler Gunnd4575212021-05-03 14:46:49 -070010510 @Override
10511 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10513 "setDeviceToDeviceForceEnabled");
10514
10515 final long identity = Binder.clearCallingIdentity();
10516 try {
10517 Arrays.stream(PhoneFactory.getPhones()).forEach(
10518 p -> {
10519 Phone thePhone = p.getImsPhone();
10520 if (thePhone != null && thePhone instanceof ImsPhone) {
10521 ImsPhone imsPhone = (ImsPhone) thePhone;
10522 CallTracker tracker = imsPhone.getCallTracker();
10523 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10524 ImsPhoneCallTracker imsPhoneCallTracker =
10525 (ImsPhoneCallTracker) tracker;
10526 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10527 }
10528 }
10529 }
10530 );
10531 } finally {
10532 Binder.restoreCallingIdentity(identity);
10533 }
10534 }
10535
Tyler Gunn92479152021-01-20 16:30:10 -080010536 /**
Hui Wang761a6682020-10-31 05:12:53 +000010537 * Gets the config of RCS VoLTE single registration enabled for the device.
10538 */
10539 @Override
10540 public boolean getDeviceSingleRegistrationEnabled() {
10541 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10542 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10543 }
10544
10545 /**
10546 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10547 */
10548 @Override
10549 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10550 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10551 "setCarrierSingleRegistrationEnabledOverride");
10552 enforceModifyPermission();
10553
10554 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10555 : Boolean.parseBoolean(enabledStr);
10556 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10557 subId, enabled);
10558 }
10559
10560 /**
10561 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10562 */
10563 @Override
10564 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10565 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10566 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10567 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010568
10569 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010570 * Overrides the ims feature validation result
10571 */
10572 @Override
10573 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10574 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10575 "setImsFeatureValidationOverride");
10576
10577 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10578 : Boolean.parseBoolean(enabledStr);
10579 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10580 subId, enabled);
10581 }
10582
10583 /**
10584 * Gets the ims feature validation override value
10585 */
10586 @Override
10587 public boolean getImsFeatureValidationOverride(int subId) {
10588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10589 "getImsFeatureValidationOverride");
10590 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10591 }
10592
10593 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010594 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10595 * their mobile plan.
10596 */
10597 @Override
10598 public String getMobileProvisioningUrl() {
10599 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10600 final long identity = Binder.clearCallingIdentity();
10601 try {
10602 return getDefaultPhone().getMobileProvisioningUrl();
10603 } finally {
10604 Binder.restoreCallingIdentity(identity);
10605 }
10606 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010607
James.cf Linbcdf8b32021-01-14 16:44:13 +080010608 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010609 * Get the EAB contact from the EAB database.
10610 */
10611 @Override
10612 public String getContactFromEab(String contact) {
10613 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10614 enforceModifyPermission();
10615 final long identity = Binder.clearCallingIdentity();
10616 try {
10617 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
10622
10623 /**
Calvin Pana1434322021-07-01 19:27:01 +080010624 * Get the EAB capability from the EAB database.
10625 */
10626 @Override
10627 public String getCapabilityFromEab(String contact) {
10628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10629 enforceModifyPermission();
10630 final long identity = Binder.clearCallingIdentity();
10631 try {
10632 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
10637
10638 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010639 * Remove the EAB contacts from the EAB database.
10640 */
10641 @Override
10642 public int removeContactFromEab(int subId, String contacts) {
10643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10644 enforceModifyPermission();
10645 final long identity = Binder.clearCallingIdentity();
10646 try {
10647 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10648 } finally {
10649 Binder.restoreCallingIdentity(identity);
10650 }
10651 }
10652
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010653 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010654 public boolean getDeviceUceEnabled() {
10655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10656 final long identity = Binder.clearCallingIdentity();
10657 try {
10658 return mApp.getDeviceUceEnabled();
10659 } finally {
10660 Binder.restoreCallingIdentity(identity);
10661 }
10662 }
10663
10664 @Override
10665 public void setDeviceUceEnabled(boolean isEnabled) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
10669 mApp.setDeviceUceEnabled(isEnabled);
10670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
10674
Brad Ebinger14d467f2021-02-12 06:18:28 +000010675 /**
10676 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10677 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10678 */
10679 // Used for SHELL command only right now.
10680 @Override
10681 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10682 List<String> featureTags) {
10683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10684 "addUceRegistrationOverrideShell");
10685 final long identity = Binder.clearCallingIdentity();
10686 try {
10687 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10688 new ArraySet<>(featureTags));
10689 } catch (ImsException e) {
10690 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
10696 /**
10697 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10698 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10699 */
10700 // Used for SHELL command only right now.
10701 @Override
10702 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10703 List<String> featureTags) {
10704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10705 "removeUceRegistrationOverrideShell");
10706 final long identity = Binder.clearCallingIdentity();
10707 try {
10708 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10709 new ArraySet<>(featureTags));
10710 } catch (ImsException e) {
10711 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10712 } finally {
10713 Binder.restoreCallingIdentity(identity);
10714 }
10715 }
10716
10717 /**
10718 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10719 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10720 */
10721 // Used for SHELL command only right now.
10722 @Override
10723 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "clearUceRegistrationOverrideShell");
10726 final long identity = Binder.clearCallingIdentity();
10727 try {
10728 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10729 } catch (ImsException e) {
10730 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
10736 /**
10737 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10738 */
10739 // Used for SHELL command only right now.
10740 @Override
10741 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10742 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10743 "getLatestRcsContactUceCapabilityShell");
10744 final long identity = Binder.clearCallingIdentity();
10745 try {
10746 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10747 } catch (ImsException e) {
10748 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10749 } finally {
10750 Binder.restoreCallingIdentity(identity);
10751 }
10752 }
10753
10754 /**
10755 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10756 * device does not have an active PUBLISH.
10757 */
10758 // Used for SHELL command only right now.
10759 @Override
10760 public String getLastUcePidfXmlShell(int subId) {
10761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10762 final long identity = Binder.clearCallingIdentity();
10763 try {
10764 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10765 } catch (ImsException e) {
10766 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
James.cf Line8713a42021-04-29 16:04:26 +080010772 /**
10773 * Remove UCE requests cannot be sent to the network status.
10774 */
10775 // Used for SHELL command only right now.
10776 @Override
10777 public boolean removeUceRequestDisallowedStatus(int subId) {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
10781 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10782 } catch (ImsException e) {
10783 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10784 } finally {
10785 Binder.restoreCallingIdentity(identity);
10786 }
10787 }
10788
James.cf Lin0fc71b02021-05-25 01:37:38 +080010789 /**
10790 * Remove UCE requests cannot be sent to the network status.
10791 */
10792 // Used for SHELL command only.
10793 @Override
10794 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10796 final long identity = Binder.clearCallingIdentity();
10797 try {
10798 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10799 } catch (ImsException e) {
10800 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010805
James.cf Lin4b784aa2021-01-31 03:25:15 +080010806 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010807 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10808 String callingPackage) {
10809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10810 mApp, subId, "setSignalStrengthUpdateRequest");
10811
10812 final int callingUid = Binder.getCallingUid();
10813 // Verify that tha callingPackage belongs to the calling UID
10814 mApp.getSystemService(AppOpsManager.class)
10815 .checkPackage(callingUid, callingPackage);
10816
Rambo Wang3607f502021-02-01 21:51:40 -080010817 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010818
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10822 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10823
10824 if (result instanceof IllegalStateException) {
10825 throw (IllegalStateException) result;
10826 }
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 @Override
10833 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10834 String callingPackage) {
10835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10836 mApp, subId, "clearSignalStrengthUpdateRequest");
10837
10838 final int callingUid = Binder.getCallingUid();
10839 // Verify that tha callingPackage belongs to the calling UID
10840 mApp.getSystemService(AppOpsManager.class)
10841 .checkPackage(callingUid, callingPackage);
10842
10843 final long identity = Binder.clearCallingIdentity();
10844 try {
10845 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10846 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10847
10848 if (result instanceof IllegalStateException) {
10849 throw (IllegalStateException) result;
10850 }
10851 } finally {
10852 Binder.restoreCallingIdentity(identity);
10853 }
10854 }
10855
Rambo Wang3607f502021-02-01 21:51:40 -080010856 private static void validateSignalStrengthUpdateRequest(Context context,
10857 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010858 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10859 // phone/system process do not have further restriction on request
10860 return;
10861 }
10862
10863 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010864 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010865 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010866 context.enforceCallingOrSelfPermission(
10867 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10868 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010869 }
10870
10871 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10872 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10873 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10874 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10875 || info.isEnabled()) {
10876 throw new IllegalArgumentException(
10877 "Only system can set hide fields in SignalThresholdInfo");
10878 }
10879
10880 // Thresholds length for each RAN need in range. This has been validated in
10881 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10882 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10883 final int[] thresholds = info.getThresholds();
10884 Objects.requireNonNull(thresholds);
10885 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10886 || thresholds.length
10887 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10888 throw new IllegalArgumentException(
10889 "thresholds length is out of range: " + thresholds.length);
10890 }
10891 }
10892 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010893
10894 /**
10895 * Gets the current phone capability.
10896 *
10897 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10898 * @return the PhoneCapability which describes the data connection capability of modem.
10899 * It's used to evaluate possible phone config change, for example from single
10900 * SIM device to multi-SIM device.
10901 */
10902 @Override
10903 public PhoneCapability getPhoneCapability() {
10904 enforceReadPrivilegedPermission("getPhoneCapability");
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
Michele Berionne5e411512020-11-13 02:36:59 +000010912
10913 /**
10914 * Prepare TelephonyManager for an unattended reboot. The reboot is
10915 * required to be done shortly after the API is invoked.
10916 */
10917 @Override
10918 @TelephonyManager.PrepareUnattendedRebootResult
10919 public int prepareForUnattendedReboot() {
10920 enforceRebootPermission();
10921
10922 final long identity = Binder.clearCallingIdentity();
10923 try {
10924 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10925 } finally {
10926 Binder.restoreCallingIdentity(identity);
10927 }
10928 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010929
10930 /**
10931 * Request to get the current slicing configuration including URSP rules and
10932 * NSSAIs (configured, allowed and rejected).
10933 *
10934 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10935 */
10936 @Override
10937 public void getSlicingConfig(ResultReceiver callback) {
10938 enforceReadPrivilegedPermission("getSlicingConfig");
10939
10940 final long identity = Binder.clearCallingIdentity();
10941 try {
10942 Phone phone = getDefaultPhone();
10943 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010948
10949 /**
10950 * Register an IMS connection state callback
10951 */
10952 @Override
10953 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10954 String callingPackage) {
10955 if (feature == ImsFeature.FEATURE_MMTEL) {
10956 // ImsMmTelManager
10957 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10958 TelephonyPermissions
10959 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10960 mApp, subId, "registerImsStateCallback");
10961 } else if (feature == ImsFeature.FEATURE_RCS) {
10962 // ImsRcsManager or SipDelegateManager
10963 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10964 Binder.getCallingUid(), "registerImsStateCallback",
10965 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10966 Manifest.permission.READ_PRECISE_PHONE_STATE,
10967 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10968 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10969 }
10970
10971 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10972 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10973 "IMS not available on device.");
10974 }
10975
10976 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
10977 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
10978 }
10979
10980 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10981 if (controller == null) {
10982 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10983 "IMS not available on device.");
10984 }
10985
10986 if (callingPackage == null) {
10987 callingPackage = getCurrentPackageName();
10988 }
10989
10990 final long token = Binder.clearCallingIdentity();
10991 try {
10992 int slotId = getSlotIndexOrException(subId);
10993 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
10994 } catch (ImsException e) {
10995 throw new ServiceSpecificException(e.getCode());
10996 } finally {
10997 Binder.restoreCallingIdentity(token);
10998 }
10999 }
11000
11001 /**
11002 * Unregister an IMS connection state callback
11003 */
11004 @Override
11005 public void unregisterImsStateCallback(IImsStateCallback cb) {
11006 final long token = Binder.clearCallingIdentity();
11007 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11008 if (controller == null) {
11009 return;
11010 }
11011 try {
11012 controller.unregisterImsStateCallback(cb);
11013 } finally {
11014 Binder.restoreCallingIdentity(token);
11015 }
11016 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011017
11018 /**
11019 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11020 *
11021 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11022 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11023 * SecurityException.
11024 * If there is current registered network this value will be same as the registered cell
11025 * identity. If the device goes out of service the previous cell identity is cached and
11026 * will be returned. If the cache age of the Cell identity is more than 24 hours
11027 * it will be cleared and null will be returned.
11028 *
11029 */
11030 @Override
11031 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11032 String callingFeatureId) {
11033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11034 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11035 LocationAccessPolicy.checkLocationPermission(mApp,
11036 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11037 .setCallingPackage(callingPackage)
11038 .setCallingFeatureId(callingFeatureId)
11039 .setCallingPid(Binder.getCallingPid())
11040 .setCallingUid(Binder.getCallingUid())
11041 .setMethod("getLastKnownCellIdentity")
11042 .setLogAsInfo(true)
11043 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11044 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11045 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11046 .build());
11047
11048 boolean hasFinePermission =
11049 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11050 if (!hasFinePermission
11051 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11052 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11053 + "and BIND_CONNECTION_SERVICE permission.");
11054 }
11055
11056 final long identity = Binder.clearCallingIdentity();
11057 try {
11058 Phone phone = getPhone(subId);
11059 if (phone == null) return null;
11060 ServiceStateTracker sst = phone.getServiceStateTracker();
11061 if (sst == null) return null;
11062 return sst.getLastKnownCellIdentity();
11063 } finally {
11064 Binder.restoreCallingIdentity(identity);
11065 }
11066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011067}