blob: 50f17871649fe63fad3aed413716a1504be36ebf [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
6304 * @param request contains the radio access networks with bands/channels to scan
6305 * @param messenger callback messenger for scan results or errors
6306 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006307 * @return the id of the requested scan which can be used to stop the scan.
6308 */
6309 @Override
6310 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006311 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6313 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006314 LocationAccessPolicy.LocationPermissionResult locationResult =
6315 LocationAccessPolicy.checkLocationPermission(mApp,
6316 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6317 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006318 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006319 .setCallingPid(Binder.getCallingPid())
6320 .setCallingUid(Binder.getCallingUid())
6321 .setMethod("requestNetworkScan")
6322 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006323 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6324 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006325 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006326 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006327 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6328 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006329 if (e != null) {
6330 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6331 throw e;
6332 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006333 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006334 return TelephonyScanManager.INVALID_SCAN_ID;
6335 }
6336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 }
Hall Liu912dfd32019-04-25 14:02:26 -07006338 int callingUid = Binder.getCallingUid();
6339 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006340 final long identity = Binder.clearCallingIdentity();
6341 try {
6342 return mNetworkScanRequestTracker.startNetworkScan(
6343 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006344 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
yinxu504e1392017-04-12 16:03:22 -07006348 }
6349
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006351 NetworkScanRequest request, int subId, String callingPackage) {
6352 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006353 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6354 boolean hasNetworkScanPermission =
6355 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6356 == PERMISSION_GRANTED;
6357
6358 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6359 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6360 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 }
6362
6363 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6364 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006365 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6366 return new SecurityException("Specific channels must not be"
6367 + " scanned without location access.");
6368 }
6369 }
6370 }
6371
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 return null;
6373 }
6374
yinxu504e1392017-04-12 16:03:22 -07006375 /**
6376 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006377 *
6378 * @param subId id of the subscription
6379 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006380 */
6381 @Override
6382 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6384 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385
Hall Liu912dfd32019-04-25 14:02:26 -07006386 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 final long identity = Binder.clearCallingIdentity();
6388 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006389 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
yinxu504e1392017-04-12 16:03:22 -07006393 }
6394
6395 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006397 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006398 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006399 */
6400 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006401 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006402 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006403 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006404 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006408 if (DBG) log("getAllowedNetworkTypesBitmask");
6409 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6410 int networkTypesBitmask = (result != null ? result[0] : -1);
6411 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6412 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006416 }
6417
6418 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006419 * Get the allowed network types for certain reason.
6420 *
6421 * @param subId the id of the subscription.
6422 * @param reason the reason the allowed network type change is taking place
6423 * @return the allowed network types.
6424 */
6425 @Override
6426 public long getAllowedNetworkTypesForReason(int subId,
6427 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006428 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006429 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
6438 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006439 * Enable/Disable E-UTRA-NR Dual Connectivity
6440 * @param subId subscription id of the sim card
6441 * @param nrDualConnectivityState expected NR dual connectivity state
6442 * This can be passed following states
6443 * <ol>
6444 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6445 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6446 * <li>Disable NR dual connectivity and force secondary cell to be released
6447 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6448 * </ol>
6449 * @return operation result.
6450 */
6451 @Override
6452 public int setNrDualConnectivityState(int subId,
6453 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6455 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006456 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006457 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6458 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6459 }
6460
Sooraj Sasindran37444802020-08-11 10:40:43 -07006461 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6462 final long identity = Binder.clearCallingIdentity();
6463 try {
6464 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6465 nrDualConnectivityState, subId,
6466 workSource);
6467 if (DBG) log("enableNRDualConnectivity result: " + result);
6468 return result;
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
6472 }
6473
6474 /**
6475 * Is E-UTRA-NR Dual Connectivity enabled
6476 * @return true if dual connectivity is enabled else false
6477 */
6478 @Override
6479 public boolean isNrDualConnectivityEnabled(int subId) {
6480 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006481 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006482 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006483 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006484 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6485 return false;
6486 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6491 null, subId, workSource);
6492 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6493 return isEnabled;
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
6497 }
6498
6499 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006500 * Set the allowed network types of the device and
6501 * provide the reason triggering the allowed network change.
6502 *
6503 * @param subId the id of the subscription.
6504 * @param reason the reason the allowed network type change is taking place
6505 * @param allowedNetworkTypes the allowed network types.
6506 * @return true on success; false on any failure.
6507 */
6508 @Override
6509 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006510 @TelephonyManager.AllowedNetworkTypesReason int reason,
6511 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6513 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006514 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006515 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6516 return false;
6517 }
6518 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6519 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006520 return false;
6521 }
6522
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006523 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6524 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6525
6526
6527 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6528 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6529 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006530 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006531
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 final long identity = Binder.clearCallingIdentity();
6533 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006534 Boolean success = (Boolean) sendRequest(
6535 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6536 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6537
6538 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6539 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
6543 }
6544
6545 /**
Miaoa84611c2019-03-15 09:21:10 +08006546 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006547 *
Miaoa84611c2019-03-15 09:21:10 +08006548 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006549 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006550 * @hide
6551 */
6552 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006553 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006556 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 try {
Miaoa84611c2019-03-15 09:21:10 +08006558 if (phone != null) {
6559 return phone.hasMatchedTetherApnSetting();
6560 } else {
6561 return false;
6562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006565 }
Junda Liu475951f2014-11-07 16:45:03 -08006566 }
6567
6568 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006569 * Get the user enabled state of Mobile Data.
6570 *
6571 * TODO: remove and use isUserDataEnabled.
6572 * This can't be removed now because some vendor codes
6573 * calls through ITelephony directly while they should
6574 * use TelephonyManager.
6575 *
6576 * @return true on enabled
6577 */
6578 @Override
6579 public boolean getDataEnabled(int subId) {
6580 return isUserDataEnabled(subId);
6581 }
6582
6583 /**
6584 * Get whether mobile data is enabled per user setting.
6585 *
6586 * There are other factors deciding whether mobile data is actually enabled, but they are
6587 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006588 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006589 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6590 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006591 *
6592 * @return {@code true} if data is enabled else {@code false}
6593 */
6594 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006595 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006596 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006597 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006598 try {
6599 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6600 functionName);
6601 } catch (Exception e) {
6602 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6603 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006604 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006606 mApp, subId, functionName);
6607
Robert Greenwalt646120a2014-05-23 11:54:03 -07006608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
6612 int phoneId = mSubscriptionController.getPhoneId(subId);
6613 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6614 Phone phone = PhoneFactory.getPhone(phoneId);
6615 if (phone != null) {
6616 boolean retVal = phone.isUserDataEnabled();
6617 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6618 return retVal;
6619 } else {
6620 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6621 return false;
6622 }
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006625 }
6626 }
6627
6628 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006629 * Checks if the device is capable of mobile data by considering whether whether the
6630 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6631 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006632 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006633 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006634 */
6635 @Override
6636 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006637 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006638 try {
6639 try {
6640 mApp.enforceCallingOrSelfPermission(
6641 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006643 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006644 try {
6645 mApp.enforceCallingOrSelfPermission(
6646 android.Manifest.permission.READ_PHONE_STATE,
6647 functionName);
6648 } catch (Exception e2) {
6649 mApp.enforceCallingOrSelfPermission(
6650 permission.READ_BASIC_PHONE_STATE, functionName);
6651 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006652 }
6653 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006654 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 int phoneId = mSubscriptionController.getPhoneId(subId);
6660 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6661 Phone phone = PhoneFactory.getPhone(phoneId);
6662 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006663 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6665 return retVal;
6666 } else {
6667 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6668 return false;
6669 }
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006672 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006673 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006674
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006675 /**
6676 * Check if data is enabled for a specific reason
6677 * @param subId Subscription index
6678 * @param reason the reason the data enable change is taking place
6679 * @return {@code true} if the overall data is enabled; {@code false} if not.
6680 */
6681 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006684 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006686 try {
6687 mApp.enforceCallingOrSelfPermission(
6688 android.Manifest.permission.ACCESS_NETWORK_STATE,
6689 functionName);
6690 } catch (Exception e) {
6691 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6692 functionName);
6693 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006694 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006695 try {
6696 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006697 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006698 } catch (Exception e2) {
6699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006700 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006701 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006702 }
6703
6704
6705 final long identity = Binder.clearCallingIdentity();
6706 try {
6707 int phoneId = mSubscriptionController.getPhoneId(subId);
6708 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006709 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 + " reason=" + reason);
6711 }
6712 Phone phone = PhoneFactory.getPhone(phoneId);
6713 if (phone != null) {
6714 boolean retVal;
6715 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6716 retVal = phone.isUserDataEnabled();
6717 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006718 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006720 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 return retVal;
6722 } else {
6723 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006724 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006725 + subId + " retVal=false");
6726 }
6727 return false;
6728 }
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
6732 }
6733
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006734 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006735 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006736 if (uid == Process.PHONE_UID) {
6737 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6738 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6740 }
6741
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006742 //load access rules from carrier configs, and check those as well: b/139133814
6743 SubscriptionController subController = SubscriptionController.getInstance();
6744 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6745 || subController == null) return privilegeFromSim;
6746
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006747 PackageManager pkgMgr = phone.getContext().getPackageManager();
6748 String[] packages = pkgMgr.getPackagesForUid(uid);
6749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006752 int subId = phone.getSubId();
6753 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6754 // A test override is in place for the privileges for this subId, so don't try to
6755 // read the subscription privileges.
6756 return privilegeFromSim;
6757 }
6758 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 SubscriptionManager subManager = (SubscriptionManager)
6760 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6761 for (String pkg : packages) {
6762 if (subManager.canManageSubscription(subInfo, pkg)) {
6763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6764 }
6765 }
6766 return privilegeFromSim;
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
6769 }
6770 }
6771
6772 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6773 String pkgName) {
6774 //load access rules from carrier configs, and check those as well: b/139133814
6775 SubscriptionController subController = SubscriptionController.getInstance();
6776 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6777 || subController == null) return privilegeFromSim;
6778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006781 int subId = phone.getSubId();
6782 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6783 // A test override is in place for the privileges for this subId, so don't try to
6784 // read the subscription privileges.
6785 return privilegeFromSim;
6786 }
6787 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006788 SubscriptionManager subManager = (SubscriptionManager)
6789 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6790 return subManager.canManageSubscription(subInfo, pkgName)
6791 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
6795 }
6796
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006797 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006798 public int getCarrierPrivilegeStatus(int subId) {
6799 final Phone phone = getPhone(subId);
6800 if (phone == null) {
6801 loge("getCarrierPrivilegeStatus: Invalid subId");
6802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6803 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006804 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6805 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006806 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6808 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006809
6810 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006811 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006812 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006813 }
Junda Liu29340342014-07-10 15:23:27 -07006814
6815 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006816 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006817 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006818 final Phone phone = getPhone(subId);
6819 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006820 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6822 }
6823 UiccProfile profile =
6824 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6825 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006826 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6828 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006829 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006830 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006831 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006832 }
6833
6834 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006835 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006836 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006837 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006838 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006839 }
6840
6841 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006842 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6843 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006844 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6846 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006847 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006848 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006849 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006850 }
6851
6852 @Override
6853 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006854 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006855 if (TextUtils.isEmpty(pkgName))
6856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006857 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6858 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006859 UiccPort port = UiccController.getInstance().getUiccPort(i);
6860 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006861 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006862 continue;
6863 }
6864
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006865 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006866 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006867 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006868 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6869 break;
6870 }
6871 }
6872
6873 return result;
Junda Liu29340342014-07-10 15:23:27 -07006874 }
Derek Tan89e89d42014-07-08 17:00:10 -07006875
6876 @Override
Junda Liue64de782015-04-16 17:19:16 -07006877 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006878 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006879 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6880 loge("phoneId " + phoneId + " is not valid.");
6881 return null;
6882 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006883 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6884 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006885 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006886 return null ;
6887 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006888 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006889 }
6890
Amith Yamasani6e118872016-02-19 12:53:51 -08006891 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006892 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006893 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006894 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006895 List<String> privilegedPackages = new ArrayList<>();
6896 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006897 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006898 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006899 if (port != null) {
6900 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006901 if (packages == null) {
6902 // Only check packages in user 0 for now
6903 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006904 PackageManager.MATCH_DISABLED_COMPONENTS
6905 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006906 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006907 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006908 }
6909 for (int p = packages.size() - 1; p >= 0; p--) {
6910 PackageInfo pkgInfo = packages.get(p);
6911 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006912 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006913 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006914 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006915 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006916 privilegedPackages.add(pkgInfo.packageName);
6917 }
6918 }
6919 }
6920 }
6921 return privilegedPackages;
6922 }
6923
chen xuf7e9fe82019-05-09 19:31:02 -07006924 @Override
6925 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006926 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6927
6928 final long identity = Binder.clearCallingIdentity();
6929
chen xuf7e9fe82019-05-09 19:31:02 -07006930 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006931 try {
6932 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6933 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6934 }
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006937 }
6938 return privilegedPackages;
6939 }
6940
Wink Savilleb564aae2014-10-23 10:18:09 -07006941 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006942 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006943 UiccPort port = phone == null ? null : phone.getUiccPort();
6944 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006945 return null;
6946 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006947 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006948 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006949 return null;
6950 }
6951 return iccId;
6952 }
6953
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006954 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006955 public void setCallComposerStatus(int subId, int status) {
6956 enforceModifyPermission();
6957
6958 final long identity = Binder.clearCallingIdentity();
6959 try {
6960 Phone phone = getPhone(subId);
6961 if (phone != null) {
6962 Phone defaultPhone = phone.getImsPhone();
6963 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6964 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6965 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006966 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6967 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006968 }
6969 }
Shuo Qian284ae752020-12-22 19:10:14 -08006970 } catch (ImsException e) {
6971 throw new ServiceSpecificException(e.getCode());
6972 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006973 Binder.restoreCallingIdentity(identity);
6974 }
6975 }
6976
6977 @Override
6978 public int getCallComposerStatus(int subId) {
6979 enforceReadPrivilegedPermission("getCallComposerStatus");
6980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 Phone phone = getPhone(subId);
6984 if (phone != null) {
6985 Phone defaultPhone = phone.getImsPhone();
6986 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6987 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6988 return imsPhone.getCallComposerStatus();
6989 }
6990 }
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
6993 }
6994 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6995 }
6996
6997 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006998 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6999 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007000 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007001 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 final String iccId = getIccId(subId);
7006 final Phone phone = getPhone(subId);
7007 if (phone == null) {
7008 return false;
7009 }
7010 final String subscriberId = phone.getSubscriberId();
7011
7012 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007013 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 + subscriberId + " to " + number);
7015 }
7016
7017 if (TextUtils.isEmpty(iccId)) {
7018 return false;
7019 }
7020
7021 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7022
7023 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7024 if (alphaTag == null) {
7025 editor.remove(alphaTagPrefKey);
7026 } else {
7027 editor.putString(alphaTagPrefKey, alphaTag);
7028 }
7029
7030 // Record both the line number and IMSI for this ICCID, since we need to
7031 // track all merged IMSIs based on line number
7032 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7033 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7034 if (number == null) {
7035 editor.remove(numberPrefKey);
7036 editor.remove(subscriberPrefKey);
7037 } else {
7038 editor.putString(numberPrefKey, number);
7039 editor.putString(subscriberPrefKey, subscriberId);
7040 }
7041
7042 editor.commit();
7043 return true;
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007046 }
Derek Tan7226c842014-07-02 17:42:23 -07007047 }
7048
7049 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007050 public String getLine1NumberForDisplay(int subId, String callingPackage,
7051 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007052 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007054 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007055 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007056 return null;
7057 }
Derek Tan97ebb422014-09-05 16:55:38 -07007058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 final long identity = Binder.clearCallingIdentity();
7060 try {
7061 String iccId = getIccId(subId);
7062 if (iccId != null) {
7063 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7064 if (DBG_MERGE) {
7065 log("getLine1NumberForDisplay returning "
7066 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7067 }
7068 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7071 return null;
7072 } finally {
7073 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007074 }
Derek Tan7226c842014-07-02 17:42:23 -07007075 }
7076
7077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007078 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7079 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007081 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007082 return null;
7083 }
Derek Tan97ebb422014-09-05 16:55:38 -07007084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 String iccId = getIccId(subId);
7088 if (iccId != null) {
7089 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7090 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7091 }
7092 return null;
7093 } finally {
7094 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007095 }
Derek Tan7226c842014-07-02 17:42:23 -07007096 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007097
7098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007099 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7100 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007101 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7102 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007104 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007105 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007106 return null;
7107 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007108
Jordan Liub49b04b2019-05-06 14:45:15 -07007109 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7110 // the process, where TelephonyManager was instantiated.
7111 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007112 final long identity = Binder.clearCallingIdentity();
7113 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007114 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 final TelephonyManager tele = TelephonyManager.from(context);
7116 final SubscriptionManager sub = SubscriptionManager.from(context);
7117
7118 // Figure out what subscribers are currently active
7119 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120
Jordan Liub49b04b2019-05-06 14:45:15 -07007121 // Only consider subs which match the current subId
7122 // This logic can be simplified. See b/131189269 for progress.
7123 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007124 activeSubscriberIds.add(tele.getSubscriberId(subId));
7125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126
7127 // First pass, find a number override for an active subscriber
7128 String mergeNumber = null;
7129 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7130 for (String key : prefs.keySet()) {
7131 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7132 final String subscriberId = (String) prefs.get(key);
7133 if (activeSubscriberIds.contains(subscriberId)) {
7134 final String iccId = key.substring(
7135 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7136 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7137 mergeNumber = (String) prefs.get(numberKey);
7138 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007139 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 + " for active subscriber " + subscriberId);
7141 }
7142 if (!TextUtils.isEmpty(mergeNumber)) {
7143 break;
7144 }
7145 }
7146 }
7147 }
7148
7149 // Shortcut when no active merged subscribers
7150 if (TextUtils.isEmpty(mergeNumber)) {
7151 return null;
7152 }
7153
7154 // Second pass, find all subscribers under that line override
7155 final ArraySet<String> result = new ArraySet<>();
7156 for (String key : prefs.keySet()) {
7157 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7158 final String number = (String) prefs.get(key);
7159 if (mergeNumber.equals(number)) {
7160 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7161 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7162 final String subscriberId = (String) prefs.get(subscriberKey);
7163 if (!TextUtils.isEmpty(subscriberId)) {
7164 result.add(subscriberId);
7165 }
7166 }
7167 }
7168 }
7169
7170 final String[] resultArray = result.toArray(new String[result.size()]);
7171 Arrays.sort(resultArray);
7172 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007173 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7175 }
7176 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007177 } finally {
7178 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007179 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007180 }
7181
7182 @Override
zoey chen38003472019-12-13 17:16:31 +08007183 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7184 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007185
7186 final long identity = Binder.clearCallingIdentity();
7187 try {
7188 final TelephonyManager telephonyManager = mApp.getSystemService(
7189 TelephonyManager.class);
7190 String subscriberId = telephonyManager.getSubscriberId(subId);
7191 if (subscriberId == null) {
7192 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007193 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007194 + subId);
7195 }
7196 return null;
7197 }
7198
7199 final SubscriptionInfo info = SubscriptionController.getInstance()
7200 .getSubscriptionInfo(subId);
7201 final ParcelUuid groupUuid = info.getGroupUuid();
7202 // If it doesn't belong to any group, return just subscriberId of itself.
7203 if (groupUuid == null) {
7204 return new String[]{subscriberId};
7205 }
7206
7207 // Get all subscriberIds from the group.
7208 final List<String> mergedSubscriberIds = new ArrayList<>();
7209 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007210 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007211 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007212 for (SubscriptionInfo subInfo : groupInfos) {
7213 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7214 if (subscriberId != null) {
7215 mergedSubscriberIds.add(subscriberId);
7216 }
7217 }
7218
7219 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222
7223 }
7224 }
7225
7226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007227 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007228 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007229 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 final Phone phone = getPhone(subId);
7234 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007238 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007239
7240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007241 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007242 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7243 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007244 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7245 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 final Phone phone = getPhone(subId);
7250 if (phone == null) {
7251 return false;
7252 }
7253 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7254 cdmaNonRoamingList);
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007257 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007258 }
7259
7260 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007261 @Deprecated
7262 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7263 enforceModifyPermission();
7264
7265 int returnValue = 0;
7266 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007267 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007268 if(result.exception == null) {
7269 if (result.result != null) {
7270 byte[] responseData = (byte[])(result.result);
7271 if(responseData.length > oemResp.length) {
7272 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7273 responseData.length + "bytes. Buffer Size is " +
7274 oemResp.length + "bytes.");
7275 }
7276 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7277 returnValue = responseData.length;
7278 }
7279 } else {
7280 CommandException ex = (CommandException) result.exception;
7281 returnValue = ex.getCommandError().ordinal();
7282 if(returnValue > 0) returnValue *= -1;
7283 }
7284 } catch (RuntimeException e) {
7285 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7286 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7287 if(returnValue > 0) returnValue *= -1;
7288 }
7289
7290 return returnValue;
7291 }
7292
7293 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007294 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007295 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007296 try {
7297 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007298 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007299 mApp, phone.getSubId(), "getRadioAccessFamily");
7300 } catch (SecurityException e) {
7301 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7302 throw e;
7303 }
chen xub97461a2018-10-26 14:17:57 -07007304 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007305 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007306 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 final long identity = Binder.clearCallingIdentity();
7309 try {
chen xub97461a2018-10-26 14:17:57 -07007310 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007311 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007312 mApp, phone.getSubId(), "getRadioAccessFamily");
7313 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
chen xub97461a2018-10-26 14:17:57 -07007317 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007318 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007319
7320 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007321 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007322 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007323 try {
7324 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7325 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007326 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007327 }
7328 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007329 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007330 }
7331 RoleManager rm = mApp.getSystemService(RoleManager.class);
7332 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7333 if (!dialerRoleHolders.contains(callingPackage)) {
7334 throw new SecurityException("App must be the dialer role holder to"
7335 + " upload a call composer pic");
7336 }
7337
7338 Executors.newSingleThreadExecutor().execute(() -> {
7339 ByteArrayOutputStream output = new ByteArrayOutputStream(
7340 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7341 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7342 boolean readUntilEnd = false;
7343 int totalBytesRead = 0;
7344 byte[] buffer = new byte[16 * 1024];
7345 while (true) {
7346 int numRead;
7347 try {
7348 numRead = input.read(buffer);
7349 } catch (IOException e) {
7350 try {
7351 fd.checkError();
7352 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7353 null);
7354 } catch (IOException e1) {
7355 // This means that the other side closed explicitly with an error. If this
7356 // happens, log and ignore.
7357 loge("Remote end of call composer picture pipe closed: " + e1);
7358 }
7359 break;
7360 }
7361 if (numRead == -1) {
7362 readUntilEnd = true;
7363 break;
7364 }
7365 totalBytesRead += numRead;
7366 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7367 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7368 try {
7369 input.close();
7370 } catch (IOException e) {
7371 // ignore
7372 }
7373 break;
7374 }
7375 output.write(buffer, 0, numRead);
7376 }
7377 // Generally, the remote end will close the file descriptors. The only case where we
7378 // close is above, where the picture size is too big.
7379
7380 try {
7381 fd.checkError();
7382 } catch (IOException e) {
7383 loge("Remote end for call composer closed with an error: " + e);
7384 return;
7385 }
7386
Hall Liuaa4211e2021-01-20 15:43:39 -08007387 if (!readUntilEnd) {
7388 loge("Did not finish reading entire image; aborting");
7389 return;
7390 }
Hall Liu82694d52020-12-11 18:22:04 -08007391
Hall Liuaa4211e2021-01-20 15:43:39 -08007392 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7393 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7394 new CallComposerPictureTransfer.Factory() {},
7395 imageData,
7396 (result) -> {
7397 if (result.first != null) {
7398 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7399 Bundle outputResult = new Bundle();
7400 outputResult.putParcelable(
7401 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7402 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7403 outputResult);
7404 } else {
7405 callback.send(result.second, null);
7406 }
7407 }
7408 );
Hall Liu82694d52020-12-11 18:22:04 -08007409 });
7410 }
7411
7412 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007413 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007419 ImsManager.getInstance(defaultPhone.getContext(),
7420 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 } finally {
7422 Binder.restoreCallingIdentity(identity);
7423 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007424 }
7425
7426 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007427 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7430 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007431 return false;
7432 }
Svet Ganovb320e182015-04-16 12:30:10 -07007433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 final long identity = Binder.clearCallingIdentity();
7435 try {
7436 // Check the user preference and the system-level IMS setting. Even if the user has
7437 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7438 // In the long run, we may instead need to check if there exists a connection service
7439 // which can support video calling.
7440 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 return imsManager.isVtEnabledByPlatform()
7443 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7444 && imsManager.isVtEnabledByUser();
7445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007448 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007449
Andrew Leea1239f22015-03-02 17:44:07 -08007450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007451 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7452 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007454 mApp, subId, callingPackage, callingFeatureId,
7455 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 return false;
7457 }
7458
7459 final long identity = Binder.clearCallingIdentity();
7460 try {
7461 CarrierConfigManager configManager =
7462 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
Andrew Leea1239f22015-03-02 17:44:07 -08007468 }
7469
7470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 return false;
7475 }
7476
7477 final long identity = Binder.clearCallingIdentity();
7478 try {
7479 CarrierConfigManager configManager =
7480 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007481 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7483 } finally {
7484 Binder.restoreCallingIdentity(identity);
7485 }
Andrew Leea1239f22015-03-02 17:44:07 -08007486 }
7487
Andrew Lee9431b832015-03-09 18:46:45 -07007488 @Override
7489 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007490 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007491 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007492 }
7493
7494 @Override
7495 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 final long identity = Binder.clearCallingIdentity();
7497 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007498 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 } finally {
7500 Binder.restoreCallingIdentity(identity);
7501 }
Andrew Lee9431b832015-03-09 18:46:45 -07007502 }
7503
Hall Liuf6668912018-10-31 17:05:23 -07007504 /**
7505 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7506 * support for the feature and device firmware support.
7507 *
7508 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7509 */
7510 @Override
7511 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007513 final Phone phone = getPhone(subscriptionId);
7514 if (phone == null) {
7515 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7516 return false;
7517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007519 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7521 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007522 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 return isCarrierSupported && isDeviceSupported;
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Hall Liu98187582018-01-22 19:15:32 -08007527 }
7528
Hall Liuf6668912018-10-31 17:05:23 -07007529 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007530 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7531 * RTT setting, will return true if the device and carrier both support RTT.
7532 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007533 */
7534 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
7536 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007537 boolean isRttSupported = isRttSupported(subscriptionId);
7538 boolean isUserRttSettingOn = Settings.Secure.getInt(
7539 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7540 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7541 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7542 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007546 }
7547
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007548 @Deprecated
7549 @Override
7550 public String getDeviceId(String callingPackage) {
7551 return getDeviceIdWithFeature(callingPackage, null);
7552 }
7553
Sanket Padawe7310cc72015-01-14 09:53:20 -08007554 /**
7555 * Returns the unique device ID of phone, for example, the IMEI for
7556 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7557 *
7558 * <p>Requires Permission:
7559 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7560 */
7561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007562 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007563 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007564 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007565 return null;
7566 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007567 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007568 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007569 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007570 return null;
7571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572
7573 final long identity = Binder.clearCallingIdentity();
7574 try {
7575 return phone.getDeviceId();
7576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007579 }
7580
Ping Sunc67b7c22016-03-02 19:16:45 +08007581 /**
7582 * {@hide}
7583 * Returns the IMS Registration Status on a particular subid
7584 *
7585 * @param subId
7586 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007587 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007588 Phone phone = getPhone(subId);
7589 if (phone != null) {
7590 return phone.isImsRegistered();
7591 } else {
7592 return false;
7593 }
7594 }
7595
Santos Cordon7a1885b2015-02-03 11:15:19 -08007596 @Override
7597 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598 final long identity = Binder.clearCallingIdentity();
7599 try {
7600 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007604 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007605
Tyler Gunnf70ed162019-04-03 15:28:53 -07007606 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007607 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007608 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007610 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007611 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7612 }
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
7620
7621 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007622 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007623 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007624 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007625 mApp,
7626 subscriptionId,
7627 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007628 final long identity = Binder.clearCallingIdentity();
7629 try {
7630 Phone phone = getPhone(subscriptionId);
7631 if (phone == null) {
7632 return null;
7633 }
7634 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
7639
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007640 /**
7641 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007642 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007643 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 Phone phone = getPhone(subId);
7647 if (phone != null) {
7648 return phone.isWifiCallingEnabled();
7649 } else {
7650 return false;
7651 }
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007654 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007655 }
7656
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007657 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007658 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007659 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 Phone phone = getPhone(subId);
7664 if (phone != null) {
7665 return phone.isVideoEnabled();
7666 } else {
7667 return false;
7668 }
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 }
7672 }
7673
7674 /**
7675 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7676 * defined in {@link ImsRegistrationImplBase}.
7677 */
7678 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Phone phone = getPhone(subId);
7682 if (phone != null) {
7683 return phone.getImsRegistrationTech();
7684 } else {
7685 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007689 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007690 }
7691
Stuart Scott8eef64f2015-04-08 15:13:54 -07007692 @Override
7693 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007694 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007695 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7696 return;
7697 }
Kai Shif70f46f2021-03-03 13:59:46 -08007698 Phone defaultPhone = getDefaultPhone();
7699 if (defaultPhone != null) {
7700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7701 mApp, getDefaultPhone().getSubId(), "factoryReset");
7702 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007703 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007704
Svet Ganovcc087f82015-05-12 20:35:54 -07007705 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007706 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7707 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007708 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007709 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007710 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007711 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007712 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007713 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007714 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007715 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007716 // There has been issues when Sms raw table somehow stores orphan
7717 // fragments. They lead to garbled message when new fragments come
7718 // in and combined with those stale ones. In case this happens again,
7719 // user can reset all network settings which will clean up this table.
7720 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007721 // Clean up IMS settings as well here.
7722 int slotId = getSlotIndex(subId);
7723 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7724 ImsManager.getInstance(mApp, slotId).factoryReset();
7725 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007726
Kai Shif70f46f2021-03-03 13:59:46 -08007727 if (defaultPhone == null) {
7728 return;
7729 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007730 // Erase modem config if erase modem on network setting is enabled.
7731 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7732 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7733 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007734 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007735 }
Kai Shif70f46f2021-03-03 13:59:46 -08007736
7737 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007738 } finally {
7739 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007740 }
7741 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007742
SongFerngWangfd89b102021-05-27 22:44:54 +08007743 @VisibleForTesting
7744 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7745 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7746 return;
7747 }
7748 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7749 RILConstants.PREFERRED_NETWORK_MODE);
7750 SubscriptionManager.setSubscriptionProperty(subId,
7751 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7752 "user=" + defaultNetworkType);
7753 phone.loadAllowedNetworksFromSubscriptionDatabase();
7754 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7755 defaultNetworkType, null);
7756 }
7757
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007758 private void cleanUpSmsRawTable(Context context) {
7759 ContentResolver resolver = context.getContentResolver();
7760 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7761 resolver.delete(uri, null, null);
7762 }
7763
Narayan Kamath1c496c22015-04-16 14:40:19 +01007764 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007765 public String getSimLocaleForSubscriber(int subId) {
7766 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7767 final Phone phone = getPhone(subId);
7768 if (phone == null) {
7769 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007770 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772 final long identity = Binder.clearCallingIdentity();
7773 try {
chen xu5d3637b2019-01-21 23:31:38 -08007774 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007775 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007776 if (info == null) {
7777 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7778 return null;
7779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 // Try and fetch the locale from the carrier properties or from the SIM language
7781 // preferences (EF-PL and EF-LI)...
7782 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007784 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7785 if (localeFromDefaultSim != null) {
7786 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7787 if (DBG) log("Using locale from subId: " + subId + " locale: "
7788 + localeFromDefaultSim);
7789 return localeFromDefaultSim.toLanguageTag();
7790 } else {
7791 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 }
7793 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 // The SIM language preferences only store a language (e.g. fr = French), not an
7796 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7797 // the SIM and carrier preferences does not include a country we add the country
7798 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007799 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007801 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 return mccLocale.toLanguageTag();
7803 }
7804
7805 if (DBG) log("No locale found - returning null");
7806 return null;
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007810 }
7811
7812 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007813 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007814 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007815 }
7816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 /**
7818 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7819 */
7820 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007821 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007822 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007823 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007824
Chenjie Yu1ba97252018-01-11 18:16:20 -08007825 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007826 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007827
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007828 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007829 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7830 * representing the state of the modem.
7831 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007832 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7833 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007834 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007835 */
7836 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007837 public void requestModemActivityInfo(ResultReceiver result) {
7838 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007839 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840
7841 final long identity = Binder.clearCallingIdentity();
7842 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007843 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 } finally {
7845 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007846 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007847 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007848
Siddharth Rayb8114062018-06-17 15:02:38 -07007849 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7850 // less than total activity duration.
7851 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7852 if (info == null) {
7853 return false;
7854 }
7855 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007856 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7857 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7858
Siddharth Rayb8114062018-06-17 15:02:38 -07007859 return (info.isValid()
7860 && (info.getSleepTimeMillis() <= activityDurationMs)
7861 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007862 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007863 && (totalTxTimeMs <= activityDurationMs));
7864 }
7865
Jack Yu85bd38a2015-11-09 11:34:32 -08007866 /**
7867 * {@hide}
7868 * Returns the service state information on specified subscription.
7869 */
7870 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007871 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7872 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007874 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007875 return null;
7876 }
7877
Hall Liuf19c44f2018-11-27 14:38:17 -08007878 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7879 LocationAccessPolicy.checkLocationPermission(mApp,
7880 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7881 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007882 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007883 .setCallingPid(Binder.getCallingPid())
7884 .setCallingUid(Binder.getCallingUid())
7885 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007886 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007887 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007888 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7889 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007890 .build());
7891
7892 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7893 LocationAccessPolicy.checkLocationPermission(mApp,
7894 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7895 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007896 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007897 .setCallingPid(Binder.getCallingPid())
7898 .setCallingUid(Binder.getCallingUid())
7899 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007900 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007901 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007902 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7903 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007904 .build());
7905 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7906 boolean hasFinePermission =
7907 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7908 boolean hasCoarsePermission =
7909 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7910
Jack Yu479f40e2020-10-27 21:29:25 -07007911 final Phone phone = getPhone(subId);
7912 if (phone == null) {
7913 return null;
7914 }
7915
Jordan Liu0f2bc442020-11-18 16:47:37 -08007916 final long identity = Binder.clearCallingIdentity();
7917
Jack Yu479f40e2020-10-27 21:29:25 -07007918 boolean isCallingPackageDataService = phone.getDataServicePackages()
7919 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007921 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7922 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7923 Rlog.d(LOG_TAG,
7924 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7925 return null;
7926 }
7927
Hall Liuf19c44f2018-11-27 14:38:17 -08007928 ServiceState ss = phone.getServiceState();
7929
7930 // Scrub out the location info in ServiceState depending on what level of access
7931 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007932 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007933 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7934 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 } finally {
7936 Binder.restoreCallingIdentity(identity);
7937 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007938 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007939
7940 /**
7941 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7942 *
7943 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7944 * voicemail ringtone.
7945 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7946 * PhoneAccount.
7947 */
7948 @Override
7949 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 final long identity = Binder.clearCallingIdentity();
7951 try {
7952 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7953 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007954 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007961 }
7962
7963 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007964 * Sets the per-account voicemail ringtone.
7965 *
7966 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7967 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7968 *
7969 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7970 * voicemail ringtone.
7971 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7972 * PhoneAccount.
7973 */
7974 @Override
7975 public void setVoicemailRingtoneUri(String callingPackage,
7976 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007979 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7980 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7982 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7983 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985
7986 final long identity = Binder.clearCallingIdentity();
7987 try {
7988 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7989 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007990 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 }
7992 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007995 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007996 }
7997
7998 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007999 * Returns whether vibration is set for voicemail notification in Phone settings.
8000 *
8001 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8002 * voicemail vibration setting.
8003 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8004 */
8005 @Override
8006 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007 final long identity = Binder.clearCallingIdentity();
8008 try {
8009 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8010 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008011 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008018 }
8019
Youhan Wange64578a2016-05-02 15:32:42 -07008020 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008021 * Sets the per-account voicemail vibration.
8022 *
8023 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8024 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8025 *
8026 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8027 * voicemail vibration setting.
8028 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8029 * specific PhoneAccount.
8030 */
8031 @Override
8032 public void setVoicemailVibrationEnabled(String callingPackage,
8033 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008034 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008036 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8037 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8039 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8040 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 }
8042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 final long identity = Binder.clearCallingIdentity();
8044 try {
8045 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8046 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008047 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 }
8049 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008052 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008053 }
8054
8055 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008056 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8057 *
8058 * @throws SecurityException if the caller does not have the required permission
8059 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008060 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008061 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008062 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008063 }
8064
8065 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008066 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8067 * permission.
8068 *
8069 * @throws SecurityException if the caller does not have the required permission
8070 */
8071 private void enforceSendSmsPermission() {
8072 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8073 }
8074
8075 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008076 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008077 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008078 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008079 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008080 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 final long identity = Binder.clearCallingIdentity();
8082 try {
8083 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008084 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 if (componentName == null) {
8086 throw new SecurityException(
8087 "Caller not current active visual voicemail package[null]");
8088 }
8089 String vvmPackage = componentName.getPackageName();
8090 if (!callingPackage.equals(vvmPackage)) {
8091 throw new SecurityException("Caller not current active visual voicemail package["
8092 + vvmPackage + "]");
8093 }
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008096 }
8097 }
8098
8099 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008100 * Return the application ID for the app type.
8101 *
8102 * @param subId the subscription ID that this request applies to.
8103 * @param appType the uicc app type.
8104 * @return Application ID for specificied app type, or null if no uicc.
8105 */
8106 @Override
8107 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008108 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008109 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110
8111 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008112 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 if (phone == null) {
8114 return null;
8115 }
8116 String aid = null;
8117 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008118 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 .getApplicationByType(appType).getAid();
8120 } catch (Exception e) {
8121 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8122 }
8123 return aid;
8124 } finally {
8125 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008126 }
Youhan Wange64578a2016-05-02 15:32:42 -07008127 }
8128
Youhan Wang4001d252016-05-11 10:29:41 -07008129 /**
8130 * Return the Electronic Serial Number.
8131 *
8132 * @param subId the subscription ID that this request applies to.
8133 * @return ESN or null if error.
8134 */
8135 @Override
8136 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008137 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008138 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139
8140 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008141 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 if (phone == null) {
8143 return null;
8144 }
8145 String esn = null;
8146 try {
8147 esn = phone.getEsn();
8148 } catch (Exception e) {
8149 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8150 }
8151 return esn;
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008154 }
Youhan Wang4001d252016-05-11 10:29:41 -07008155 }
8156
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008157 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008158 * Return the Preferred Roaming List Version.
8159 *
8160 * @param subId the subscription ID that this request applies to.
8161 * @return PRLVersion or null if error.
8162 */
8163 @Override
8164 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008165 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008166 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167
8168 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008169 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 if (phone == null) {
8171 return null;
8172 }
8173 String cdmaPrlVersion = null;
8174 try {
8175 cdmaPrlVersion = phone.getCdmaPrlVersion();
8176 } catch (Exception e) {
8177 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8178 }
8179 return cdmaPrlVersion;
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008182 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008183 }
8184
8185 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008186 * Get snapshot of Telephony histograms
8187 * @return List of Telephony histograms
8188 * @hide
8189 */
8190 @Override
8191 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8193 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194
8195 final long identity = Binder.clearCallingIdentity();
8196 try {
8197 return RIL.getTelephonyRILTimingHistograms();
8198 } finally {
8199 Binder.restoreCallingIdentity(identity);
8200 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008201 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008202
8203 /**
8204 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008205 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8206 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008207 * Require system privileges. In the future we may add this to carrier APIs.
8208 *
Michele Berionne482f8202018-11-27 18:57:59 -08008209 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008210 */
8211 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008212 @TelephonyManager.SetCarrierRestrictionResult
8213 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008214 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008216
Michele Berionne482f8202018-11-27 18:57:59 -08008217 if (carrierRestrictionRules == null) {
8218 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008219 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 final long identity = Binder.clearCallingIdentity();
8222 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008223 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008224 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008228 }
8229
8230 /**
8231 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008232 * Get the allowed carrier list and the excluded carrier list, including the priority between
8233 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 * Require system privileges. In the future we may add this to carrier APIs.
8235 *
Michele Berionne482f8202018-11-27 18:57:59 -08008236 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008237 */
8238 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008239 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008240 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008241 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242
8243 final long identity = Binder.clearCallingIdentity();
8244 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008245 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8246 if (response instanceof CarrierRestrictionRules) {
8247 return (CarrierRestrictionRules) response;
8248 }
8249 // Response is an Exception of some kind,
8250 // which is signalled to the user as a NULL retval
8251 return null;
8252 } catch (Exception e) {
8253 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8254 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 } finally {
8256 Binder.restoreCallingIdentity(identity);
8257 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008258 }
8259
fionaxu59545b42016-05-25 15:53:37 -07008260 /**
fionaxu59545b42016-05-25 15:53:37 -07008261 * Action set from carrier signalling broadcast receivers to enable/disable radio
8262 * @param subId the subscription ID that this action applies to.
8263 * @param enabled control enable or disable radio.
8264 * {@hide}
8265 */
8266 @Override
8267 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8268 enforceModifyPermission();
8269 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
8271 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008272 if (phone == null) {
8273 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8274 return;
8275 }
8276 try {
8277 phone.carrierActionSetRadioEnabled(enabled);
8278 } catch (Exception e) {
8279 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280 } finally {
8281 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008282 }
8283 }
8284
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008285 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008286 * Enable or disable Voice over NR (VoNR)
8287 * @param subId the subscription ID that this action applies to.
8288 * @param enabled enable or disable VoNR.
8289 * @return operation result.
8290 */
8291 @Override
8292 public int setVoNrEnabled(int subId, boolean enabled) {
8293 enforceModifyPermission();
8294 final Phone phone = getPhone(subId);
8295
8296 final long identity = Binder.clearCallingIdentity();
8297 if (phone == null) {
8298 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8299 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8300 }
8301
8302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8303 try {
8304 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8305 workSource);
8306 if (DBG) log("setVoNrEnabled result: " + result);
8307 return result;
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
8312
8313 /**
8314 * Is voice over NR enabled
8315 * @return true if VoNR is enabled else false
8316 */
8317 @Override
8318 public boolean isVoNrEnabled(int subId) {
8319 enforceReadPrivilegedPermission("isVoNrEnabled");
8320 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8321 final long identity = Binder.clearCallingIdentity();
8322 try {
8323 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8324 null, subId, workSource);
8325 if (DBG) log("isVoNrEnabled: " + isEnabled);
8326 return isEnabled;
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008333 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8334 * network status based on which carrier apps could apply actions accordingly,
8335 * enable/disable default url handler for example.
8336 *
8337 * @param subId the subscription ID that this action applies to.
8338 * @param report control start/stop reporting the default network status.
8339 * {@hide}
8340 */
8341 @Override
8342 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8343 enforceModifyPermission();
8344 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345
8346 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008347 if (phone == null) {
8348 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8349 return;
8350 }
8351 try {
8352 phone.carrierActionReportDefaultNetworkStatus(report);
8353 } catch (Exception e) {
8354 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 } finally {
8356 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008357 }
8358 }
8359
8360 /**
fionaxud9622282017-07-17 17:51:30 -07008361 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8362 * @param subId the subscription ID that this action applies to.
8363 * {@hide}
8364 */
8365 @Override
8366 public void carrierActionResetAll(int subId) {
8367 enforceModifyPermission();
8368 final Phone phone = getPhone(subId);
8369 if (phone == null) {
8370 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8371 return;
8372 }
8373 try {
8374 phone.carrierActionResetAll();
8375 } catch (Exception e) {
8376 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8377 }
8378 }
8379
8380 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008381 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8382 * bug report is being generated.
8383 */
8384 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008385 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008386 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8387 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008388 writer.println("Permission Denial: can't dump Phone from pid="
8389 + Binder.getCallingPid()
8390 + ", uid=" + Binder.getCallingUid()
8391 + "without permission "
8392 + android.Manifest.permission.DUMP);
8393 return;
8394 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008395 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008396 }
Jack Yueb89b242016-06-22 13:27:47 -07008397
Brad Ebingerdac2f002018-04-03 15:17:52 -07008398 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008399 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8400 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8401 @NonNull String[] args) {
8402 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8403 this, in.getFileDescriptor(), out.getFileDescriptor(),
8404 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008405 }
8406
Jack Yueb89b242016-06-22 13:27:47 -07008407 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008408 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008409 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008410 * @param reason the reason the data enable change is taking place
8411 * @param enabled True if enabling the data, otherwise disabling.
8412 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008413 */
8414 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008415 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008416 boolean enabled) {
8417 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8418 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8419 try {
8420 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008421 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008422 } catch (SecurityException se) {
8423 enforceModifyPermission();
8424 }
8425 } else {
8426 enforceModifyPermission();
8427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 Phone phone = getPhone(subId);
8432 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008433 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8434 phone.carrierActionSetMeteredApnsEnabled(enabled);
8435 } else {
8436 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 }
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008441 }
8442 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008443
8444 /**
8445 * Get Client request stats
8446 * @return List of Client Request Stats
8447 * @hide
8448 */
8449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008450 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8451 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008453 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008454 return null;
8455 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008456 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 if (phone != null) {
8461 return phone.getClientRequestStats();
8462 }
8463
8464 return null;
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 }
8469
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008470 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008471 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008472 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008473 }
Jack Yueb4124c2017-02-16 15:32:43 -08008474
8475 /**
Grace Chen70990072017-03-24 17:21:30 -07008476 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008477 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008478 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008479 * @param state State of SIM (power down, power up, pass through)
8480 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8481 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8482 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008483 *
8484 **/
8485 @Override
Grace Chen70990072017-03-24 17:21:30 -07008486 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008487 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008488 Phone phone = PhoneFactory.getPhone(slotIndex);
8489
vagdeviaf9a5b92018-08-15 16:01:53 -07008490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008492 final long identity = Binder.clearCallingIdentity();
8493 try {
8494 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008495 phone.setSimPowerState(state, null, workSource);
8496 }
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
8501
8502 /**
8503 * Set SIM card power state.
8504 *
8505 * @param slotIndex SIM slot id.
8506 * @param state State of SIM (power down, power up, pass through)
8507 * @param callback callback to trigger after success or failure
8508 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8509 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8510 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8511 *
8512 **/
8513 @Override
8514 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8515 IIntegerConsumer callback) {
8516 enforceModifyPermission();
8517 Phone phone = PhoneFactory.getPhone(slotIndex);
8518
8519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8520
8521 final long identity = Binder.clearCallingIdentity();
8522 try {
8523 if (phone != null) {
8524 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8525 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 }
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008529 }
8530 }
Shuo Qiandd210312017-04-12 22:11:33 +00008531
Tyler Gunn65d45c22017-06-05 11:22:26 -07008532 private boolean isUssdApiAllowed(int subId) {
8533 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008534 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008535 if (configManager == null) {
8536 return false;
8537 }
8538 PersistableBundle pb = configManager.getConfigForSubId(subId);
8539 if (pb == null) {
8540 return false;
8541 }
8542 return pb.getBoolean(
8543 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8544 }
8545
Shuo Qiandd210312017-04-12 22:11:33 +00008546 /**
8547 * Check if phone is in emergency callback mode
8548 * @return true if phone is in emergency callback mode
8549 * @param subId sub id
8550 */
goneil9c5f4872017-12-05 14:07:56 -08008551 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008552 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008553 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008554 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 if (phone != null) {
8559 return phone.isInEcm();
8560 } else {
8561 return false;
8562 }
8563 } finally {
8564 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008565 }
8566 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008567
8568 /**
8569 * Get the current signal strength information for the given subscription.
8570 * Because this information is not updated when the device is in a low power state
8571 * it should not be relied-upon to be current.
8572 * @param subId Subscription index
8573 * @return the most recent cached signal strength info from the modem
8574 */
8575 @Override
8576 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 Phone p = getPhone(subId);
8580 if (p == null) {
8581 return null;
8582 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008584 return p.getSignalStrength();
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
8587 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008588 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008589
Pengquan Meng77b7f132018-08-22 14:49:57 -07008590 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008591 * Get the current modem radio state for the given slot.
8592 * @param slotIndex slot index.
8593 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008594 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008595 * @return the current radio power state from the modem
8596 */
8597 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008598 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008599 Phone phone = PhoneFactory.getPhone(slotIndex);
8600 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8602 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008603 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8604 }
8605
8606 final long identity = Binder.clearCallingIdentity();
8607 try {
8608 return phone.getRadioPowerState();
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
8612 }
8613 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8614 }
8615
8616 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008617 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8618 *
8619 * <p>Requires one of the following permissions:
8620 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008621 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008622 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8623 * privileges.
8624 *
8625 * @param subId subscription id
8626 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8627 * {@code false}.
8628 */
8629 @Override
8630 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008631 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008632 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008633 try {
8634 mApp.enforceCallingOrSelfPermission(
8635 android.Manifest.permission.ACCESS_NETWORK_STATE,
8636 functionName);
8637 } catch (Exception e) {
8638 mApp.enforceCallingOrSelfPermission(
8639 permission.READ_BASIC_PHONE_STATE, functionName);
8640 }
Shuo Qian093013d2020-08-13 15:42:55 -07008641 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008642 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008643 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008644 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008645
Pengquan Menga1bb6272018-09-06 09:59:22 -07008646 boolean isEnabled = false;
8647 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008648 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008649 Phone phone = getPhone(subId);
8650 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008651 } finally {
8652 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008654 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008655 }
8656
8657
8658 /**
8659 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8660 *
8661 * <p> Requires permission:
8662 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8663 * privileges.
8664 *
8665 * @param subId subscription id
8666 * @param isEnabled {@code true} means enable, {@code false} means disable.
8667 */
8668 @Override
8669 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8671 mApp, subId, "setDataRoamingEnabled");
8672
Pengquan Menga1bb6272018-09-06 09:59:22 -07008673 final long identity = Binder.clearCallingIdentity();
8674 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008675 Phone phone = getPhone(subId);
8676 if (phone != null) {
8677 phone.setDataRoamingEnabled(isEnabled);
8678 }
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008681 }
8682 }
8683
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008684 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008685 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008686 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008687 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008688 mApp, subId, "isManualNetworkSelectionAllowed");
8689
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008690 boolean isAllowed = true;
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008693 Phone phone = getPhone(subId);
8694 if (phone != null) {
8695 isAllowed = phone.isCspPlmnEnabled();
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 return isAllowed;
8701 }
8702
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008703 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8704 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8705 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8706 // Update each UiccPort object based on privilege access
8707 UiccPort[] uiccPorts = card.getUiccPortList();
8708 for (UiccPort port : uiccPorts) {
8709 UiccProfile profile = port.getUiccProfile();
8710 if (profile == null ||
8711 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8712 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8713 return false;
8714 }
8715 }
8716 return true;
8717 }
8718
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008719 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008720 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008721 // Verify that tha callingPackage belongs to the calling UID
8722 mApp.getSystemService(AppOpsManager.class)
8723 .checkPackage(Binder.getCallingUid(), callingPackage);
8724
Jordan Liu1e142fc2019-04-22 15:10:43 -07008725 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008726 try {
8727 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008728 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008729 } catch (SecurityException e) {
8730 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8731 // has carrier privileges on an active UICC
8732 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8733 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008734 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008735 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008736 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008737
8738 final long identity = Binder.clearCallingIdentity();
8739 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008740 UiccController uiccController = UiccController.getInstance();
8741 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008742 if (hasReadPermission) {
8743 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008744 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008745
8746 // Remove private info if the caller doesn't have access
8747 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8748 for (UiccCardInfo cardInfo : cardInfos) {
8749 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8750 // is available
8751 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008752 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8753 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8754 if (card == null || card.getUiccPortList().length == 0) {
8755 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008756 filteredInfos.add(cardInfo.getUnprivileged());
8757 continue;
8758 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008759
8760 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008761 filteredInfos.add(cardInfo);
8762 } else {
8763 filteredInfos.add(cardInfo.getUnprivileged());
8764 }
8765 }
8766 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008767 } finally {
8768 Binder.restoreCallingIdentity(identity);
8769 }
8770 }
8771
8772 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008773 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008774 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008776 final long identity = Binder.clearCallingIdentity();
8777 try {
8778 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8779 if (slots == null) {
8780 Rlog.i(LOG_TAG, "slots is null.");
8781 return null;
8782 }
8783
8784 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8785 for (int i = 0; i < slots.length; i++) {
8786 UiccSlot slot = slots[i];
8787 if (slot == null) {
8788 continue;
8789 }
8790
Jordan Liu7be7e652019-05-06 18:55:02 +00008791 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 UiccCard card = slot.getUiccCard();
8793 if (card != null) {
8794 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008795 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008796 cardId = slot.getEid();
8797 if (TextUtils.isEmpty(cardId)) {
8798 cardId = slot.getIccId();
8799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008800 }
8801
Jordan Liu857451f2019-05-09 16:35:35 -07008802 if (cardId != null) {
8803 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8804 // if cardId is an EID, it's all digits so this is fine
8805 cardId = IccUtils.stripTrailingFs(cardId);
8806 }
8807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008808 int cardState = 0;
8809 switch (slot.getCardState()) {
8810 case CARDSTATE_ABSENT:
8811 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8812 break;
8813 case CARDSTATE_PRESENT:
8814 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8815 break;
8816 case CARDSTATE_ERROR:
8817 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8818 break;
8819 case CARDSTATE_RESTRICTED:
8820 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8821 break;
8822 default:
8823 break;
8824
8825 }
8826
8827 infos[i] = new UiccSlotInfo(
8828 slot.isActive(),
8829 slot.isEuicc(),
8830 cardId,
8831 cardState,
8832 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008833 slot.isExtendedApduSupported(),
8834 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008835 }
8836 return infos;
8837 } finally {
8838 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008839 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008840 }
8841
8842 @Override
8843 public boolean switchSlots(int[] physicalSlots) {
8844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008845
8846 final long identity = Binder.clearCallingIdentity();
8847 try {
8848 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
8851 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008852 }
Jack Yu4c988042018-02-27 15:30:01 -08008853
8854 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008855 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008856 final long identity = Binder.clearCallingIdentity();
8857 try {
8858 return UiccController.getInstance().getCardIdForDefaultEuicc();
8859 } finally {
8860 Binder.restoreCallingIdentity(identity);
8861 }
8862 }
8863
Pengquan Meng85728fb2018-03-12 16:31:21 -07008864 /**
goneil47ffb6e2018-04-06 15:40:58 -07008865 * A test API to reload the UICC profile.
8866 *
8867 * <p>Requires that the calling app has permission
8868 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8869 * @hide
8870 */
8871 @Override
8872 public void refreshUiccProfile(int subId) {
8873 enforceModifyPermission();
8874
8875 final long identity = Binder.clearCallingIdentity();
8876 try {
8877 Phone phone = getPhone(subId);
8878 if (phone == null) {
8879 return;
8880 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008881 UiccPort uiccPort = phone.getUiccPort();
8882 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008883 return;
8884 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008885 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008886 if (uiccProfile == null) {
8887 return;
8888 }
8889 uiccProfile.refresh();
8890 } finally {
8891 Binder.restoreCallingIdentity(identity);
8892 }
8893 }
8894
8895 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008896 * Returns false if the mobile data is disabled by default, otherwise return true.
8897 */
8898 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008899 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008900 }
8901
8902 /**
8903 * Returns true if the data roaming is enabled by default, i.e the system property
8904 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8905 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8906 */
8907 private boolean getDefaultDataRoamingEnabled(int subId) {
8908 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008909 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008910 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008911 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8912 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8913 return isDataRoamingEnabled;
8914 }
8915
8916 /**
8917 * Returns the default network type for the given {@code subId}, if the default network type is
8918 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8919 */
8920 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008921 List<Integer> list = TelephonyProperties.default_network();
8922 int phoneId = mSubscriptionController.getPhoneId(subId);
8923 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8924 return list.get(phoneId);
8925 }
8926 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008927 }
fionaxua13278b2018-03-21 00:08:13 -07008928
8929 @Override
8930 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008931 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933
8934 final long identity = Binder.clearCallingIdentity();
8935 try {
8936 final Phone phone = getPhone(subId);
8937 if (phone == null) {
8938 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8939 return;
8940 }
chen xueaba88a2019-03-15 13:15:10 -07008941 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8942 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008943 if (carrierPrivilegeRules == null) {
8944 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8945 } else {
8946 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008948 } finally {
8949 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008950 }
fionaxua13278b2018-03-21 00:08:13 -07008951 }
8952
8953 @Override
8954 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008955 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956
8957 final long identity = Binder.clearCallingIdentity();
8958 try {
8959 final Phone phone = getPhone(subId);
8960 if (phone == null) {
8961 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8962 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8963 }
8964 return phone.getCarrierIdListVersion();
8965 } finally {
8966 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008967 }
fionaxua13278b2018-03-21 00:08:13 -07008968 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008969
8970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008971 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8972 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008974 mApp, subId, callingPackage, callingFeatureId,
8975 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008976 return -1;
8977 }
8978
8979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
8985 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008986
8987 @Override
8988 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008989 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008990 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008991 mApp, subId, "getCdmaRoamingMode");
8992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
9002 public boolean setCdmaRoamingMode(int subId, int mode) {
9003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9004 mApp, subId, "setCdmaRoamingMode");
9005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9009 } finally {
9010 Binder.restoreCallingIdentity(identity);
9011 }
9012 }
9013
9014 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009015 public int getCdmaSubscriptionMode(int subId) {
9016 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009017 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009018 mApp, subId, "getCdmaSubscriptionMode");
9019
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
9028 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009029 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9031 mApp, subId, "setCdmaSubscriptionMode");
9032
9033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9036 } finally {
9037 Binder.restoreCallingIdentity(identity);
9038 }
9039 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009040
sqianc5eccab2018-10-19 18:46:41 -07009041 @Override
sqian8c685422019-02-22 15:55:18 -08009042 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009043 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009045 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9046 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009047 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9048 }
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
sqian854d44b2018-12-12 16:48:18 -08009051 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9052 for (Phone phone: PhoneFactory.getPhones()) {
9053 if (phone.getEmergencyNumberTracker() != null
9054 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9055 emergencyNumberListInternal.put(
9056 phone.getSubId(),
9057 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9058 }
sqian11b7a0e2018-12-05 18:48:28 -08009059 }
sqian854d44b2018-12-12 16:48:18 -08009060 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009061 } finally {
9062 Binder.restoreCallingIdentity(identity);
9063 }
sqianc5eccab2018-10-19 18:46:41 -07009064 }
9065
9066 @Override
sqian8c685422019-02-22 15:55:18 -08009067 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009068 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009069 if (!exactMatch) {
9070 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009071 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009072 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009073 }
9074 final long identity = Binder.clearCallingIdentity();
9075 try {
sqian854d44b2018-12-12 16:48:18 -08009076 for (Phone phone: PhoneFactory.getPhones()) {
9077 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009078 && phone.getEmergencyNumberTracker()
9079 .isEmergencyNumber(number, exactMatch)) {
9080 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009081 }
sqian11b7a0e2018-12-05 18:48:28 -08009082 }
9083 return false;
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
9086 }
9087 }
9088
sqianf4ca7ed2019-01-15 18:32:07 -08009089 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009090 * Start emergency callback mode for GsmCdmaPhone for testing.
9091 */
9092 @Override
9093 public void startEmergencyCallbackMode() {
9094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9095 "startEmergencyCallbackMode");
9096 enforceModifyPermission();
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 for (Phone phone : PhoneFactory.getPhones()) {
9100 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9101 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9102 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9103 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9104 gsmCdmaPhone.obtainMessage(
9105 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9106 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9107 }
9108 }
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
9113
9114 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009115 * Update emergency number list for test mode.
9116 */
9117 @Override
9118 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9120 "updateEmergencyNumberListTestMode");
9121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 for (Phone phone: PhoneFactory.getPhones()) {
9125 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9126 if (tracker != null) {
9127 tracker.executeEmergencyNumberTestModeCommand(action, num);
9128 }
9129 }
9130 } finally {
9131 Binder.restoreCallingIdentity(identity);
9132 }
9133 }
9134
9135 /**
9136 * Get the full emergency number list for test mode.
9137 */
9138 @Override
9139 public List<String> getEmergencyNumberListTestMode() {
9140 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9141 "getEmergencyNumberListTestMode");
9142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 Set<String> emergencyNumbers = new HashSet<>();
9146 for (Phone phone: PhoneFactory.getPhones()) {
9147 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9148 if (tracker != null) {
9149 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9150 emergencyNumbers.add(num.getNumber());
9151 }
9152 }
9153 }
9154 return new ArrayList<>(emergencyNumbers);
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
9158 }
9159
chen xud6b45bd2018-10-30 22:27:10 -07009160 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009161 public int getEmergencyNumberDbVersion(int subId) {
9162 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 final Phone phone = getPhone(subId);
9167 if (phone == null) {
9168 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9169 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9170 }
9171 return phone.getEmergencyNumberDbVersion();
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 @Override
9178 public void notifyOtaEmergencyNumberDbInstalled() {
9179 enforceModifyPermission();
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 for (Phone phone: PhoneFactory.getPhones()) {
9184 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9185 if (tracker != null) {
9186 tracker.updateOtaEmergencyNumberDatabase();
9187 }
9188 }
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
9192 }
9193
9194 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009195 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009196 enforceActiveEmergencySessionPermission();
9197
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
9200 for (Phone phone: PhoneFactory.getPhones()) {
9201 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9202 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009203 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9204 }
9205 }
9206 } finally {
9207 Binder.restoreCallingIdentity(identity);
9208 }
9209 }
9210
9211 @Override
9212 public void resetOtaEmergencyNumberDbFilePath() {
9213 enforceActiveEmergencySessionPermission();
9214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
9217 for (Phone phone: PhoneFactory.getPhones()) {
9218 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9219 if (tracker != null) {
9220 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009221 }
9222 }
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
9226 }
9227
9228 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009229 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9230 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9231 Phone phone = getPhone(subId);
9232 if (phone == null) {
9233 return null;
9234 }
9235 final long identity = Binder.clearCallingIdentity();
9236 try {
9237 UiccProfile profile = UiccController.getInstance()
9238 .getUiccProfileForPhone(phone.getPhoneId());
9239 if (profile != null) {
9240 return profile.getCertsFromCarrierPrivilegeAccessRules();
9241 }
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 return null;
9246 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009247
9248 /**
9249 * Enable or disable a modem stack.
9250 */
9251 @Override
9252 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9253 enforceModifyPermission();
9254
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 Phone phone = PhoneFactory.getPhone(slotIndex);
9258 if (phone == null) {
9259 return false;
9260 } else {
9261 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9262 }
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
Michelecea4cf22018-12-21 15:00:11 -08009267
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009268 /**
9269 * Whether a modem stack is enabled or not.
9270 */
9271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009272 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9273 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009274 Phone phone = PhoneFactory.getPhone(slotIndex);
9275 if (phone == null) return false;
9276
9277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009278 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9279 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009280 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9281 }
9282
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009285 try {
9286 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9287 } catch (NoSuchElementException ex) {
9288 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9289 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009290 } finally {
9291 Binder.restoreCallingIdentity(identity);
9292 }
9293 }
9294
Michelecea4cf22018-12-21 15:00:11 -08009295 @Override
Michele0ea7d782019-03-19 14:58:42 -07009296 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009297 enforceModifyPermission();
9298
9299 final long identity = Binder.clearCallingIdentity();
9300 try {
9301 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009302 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009303 .commit();
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
9309 @Override
Michele0ea7d782019-03-19 14:58:42 -07009310 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009311 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009313 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9314 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009315 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009316 }
Michelecea4cf22018-12-21 15:00:11 -08009317
9318 final long identity = Binder.clearCallingIdentity();
9319 try {
Michele0ea7d782019-03-19 14:58:42 -07009320 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009321 } finally {
9322 Binder.restoreCallingIdentity(identity);
9323 }
9324 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009325
Michele0ea7d782019-03-19 14:58:42 -07009326 @TelephonyManager.IsMultiSimSupportedResult
9327 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009328 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9329 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9330 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009331 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9332 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009333 }
9334 // Check if the hardware supports multisim functionality. If usage of multisim is not
9335 // supported by the modem, indicate that it is restricted.
9336 PhoneCapability staticCapability =
9337 mPhoneConfigurationManager.getStaticPhoneCapability();
9338 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009339 loge("isMultiSimSupportedInternal: no static configuration available");
9340 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009341 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009342 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009343 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9344 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009345 }
9346 // Check if support of multiple SIMs is restricted by carrier
9347 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009348 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009349 }
9350
Michele0ea7d782019-03-19 14:58:42 -07009351 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009352 }
9353
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009354 /**
9355 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009356 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9357 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9358 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009359 * @param numOfSims number of active sims we want to switch to
9360 */
9361 @Override
9362 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009363 if (numOfSims == 1) {
9364 enforceModifyPermission();
9365 } else {
9366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9367 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9368 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009369 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009370
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009371 try {
Michele30b57b22019-03-01 12:01:14 -08009372 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009373 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009374 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9375 return;
9376 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009377 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
9381 }
9382
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009383 @Override
9384 public boolean isApplicationOnUicc(int subId, int appType) {
9385 enforceReadPrivilegedPermission("isApplicationOnUicc");
9386 Phone phone = getPhone(subId);
9387 if (phone == null) {
9388 return false;
9389 }
9390 final long identity = Binder.clearCallingIdentity();
9391 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009392 UiccPort uiccPort = phone.getUiccPort();
9393 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009394 return false;
9395 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009396 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009397 if (uiccProfile == null) {
9398 return false;
9399 }
9400 if (TelephonyManager.APPTYPE_SIM <= appType
9401 && appType <= TelephonyManager.APPTYPE_ISIM) {
9402 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9403 }
9404 return false;
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
9409
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009410 /**
chen xub4baa772019-04-03 10:23:41 -07009411 * Get whether making changes to modem configurations will trigger reboot.
9412 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009413 */
9414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009415 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9416 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009418 mApp, subId, callingPackage, callingFeatureId,
9419 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009420 return false;
9421 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009422 final long identity = Binder.clearCallingIdentity();
9423 try {
9424 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
Nathan Harold29f5f052019-02-15 13:41:57 -08009430 private void updateModemStateMetrics() {
9431 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9432 // TODO: check the state for each modem if the api is ready.
9433 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9434 }
9435
Pengquan Meng3889a572019-01-23 11:16:29 -08009436 @Override
9437 public int[] getSlotsMapping() {
9438 enforceReadPrivilegedPermission("getSlotsMapping");
9439
9440 final long identity = Binder.clearCallingIdentity();
9441 try {
9442 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9443 // All logical slots should have a mapping to a physical slot.
9444 int[] logicalSlotsMapping = new int[phoneCount];
9445 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9446 for (int i = 0; i < slotInfos.length; i++) {
9447 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9448 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9449 }
9450 }
9451 return logicalSlotsMapping;
9452 } finally {
9453 Binder.restoreCallingIdentity(identity);
9454 }
9455 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009456
9457 /**
9458 * Get the IRadio HAL Version
9459 */
9460 @Override
9461 public int getRadioHalVersion() {
9462 Phone phone = getDefaultPhone();
9463 if (phone == null) return -1;
9464 HalVersion hv = phone.getHalVersion();
9465 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9466 return hv.major * 100 + hv.minor;
9467 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009468
9469 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009470 * Get the current calling package name.
9471 * @return the current calling package name
9472 */
9473 @Override
9474 public String getCurrentPackageName() {
9475 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9476 }
9477
9478 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009479 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9480 * corresponding network requests on a subId.
9481 *
9482 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009483 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009484 * 2) APN is un-metered for this subscription, or
9485 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009486 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009487 *
9488 * @return whether data is allowed for a apn type.
9489 *
9490 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009491 */
9492 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009493 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009494 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9495 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009496
9497 // Now that all security checks passes, perform the operation as ourselves.
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 Phone phone = getPhone(subId);
9501 if (phone == null) return false;
9502
Jack Yu41407ee2019-05-13 16:54:09 -07009503 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009504 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9505 } finally {
9506 Binder.restoreCallingIdentity(identity);
9507 }
9508 }
9509
9510 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009511 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009512 enforceReadPrivilegedPermission("isApnMetered");
9513
9514 // Now that all security checks passes, perform the operation as ourselves.
9515 final long identity = Binder.clearCallingIdentity();
9516 try {
9517 Phone phone = getPhone(subId);
9518 if (phone == null) return true; // By default return true.
9519
Jack Yu41407ee2019-05-13 16:54:09 -07009520 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
9524 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009525
9526 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009527 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9528 int subscriptionId, IBooleanConsumer resultCallback) {
9529 enforceModifyPermission();
9530 long token = Binder.clearCallingIdentity();
9531 try {
9532 Phone phone = getPhone(subscriptionId);
9533 if (phone == null) {
9534 try {
9535 if (resultCallback != null) {
9536 resultCallback.accept(false);
9537 }
9538 } catch (RemoteException e) {
9539 // ignore
9540 }
9541 return;
9542 }
9543 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9544 Pair.create(specifiers, (x) -> {
9545 try {
9546 if (resultCallback != null) {
9547 resultCallback.accept(x);
9548 }
9549 } catch (RemoteException e) {
9550 // ignore
9551 }
9552 });
9553 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9554 } finally {
9555 Binder.restoreCallingIdentity(token);
9556 }
9557 }
9558
9559 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009560 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9561 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009562 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009563 mApp, subId, "getSystemSelectionChannels");
9564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9565 final long identity = Binder.clearCallingIdentity();
9566 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009567 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9568 if (result instanceof IllegalStateException) {
9569 throw (IllegalStateException) result;
9570 }
9571 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009572 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9573 return specifiers;
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009580 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009581 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009582 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9583 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9584 if (iccRecords == null) {
9585 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9586 return false;
9587 }
9588 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9589 }
9590
9591 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009592 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9593 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009594 if (callingPackage == null) {
9595 callingPackage = getCurrentPackageName();
9596 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009597 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9598 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009599 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9600 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009601 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9602 }
9603 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9604 Intent intent = new Intent();
9605 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9606 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9607 // Bring up choose default SMS subscription dialog right now
9608 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9609 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9610 mApp.startActivity(intent);
9611 }
chen xud5ca2d52019-05-28 15:20:57 -07009612
9613 @Override
9614 public String getMmsUAProfUrl(int subId) {
9615 //TODO investigate if this API should require proper permission check in R b/133791609
9616 final long identity = Binder.clearCallingIdentity();
9617 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009618 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9619 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9620 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9621 return carrierUAProfUrl;
9622 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009623 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9624 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009625 } finally {
9626 Binder.restoreCallingIdentity(identity);
9627 }
9628 }
9629
9630 @Override
9631 public String getMmsUserAgent(int subId) {
9632 //TODO investigate if this API should require proper permission check in R b/133791609
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009635 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9636 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9637 if (!TextUtils.isEmpty(carrierUserAgent)) {
9638 return carrierUserAgent;
9639 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009640 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9641 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
Jack Yub07d4972019-05-28 16:12:25 -07009646
9647 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009648 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9649 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009650
Jack Yub07d4972019-05-28 16:12:25 -07009651 final long identity = Binder.clearCallingIdentity();
9652 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009653 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009654 if (phone == null) return false;
9655
Hall Liua62f5da2020-09-25 10:42:19 -07009656 switch (policy) {
9657 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9658 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9659 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9660 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9661 default:
9662 throw new IllegalArgumentException(policy + " is not a valid policy");
9663 }
Jack Yub07d4972019-05-28 16:12:25 -07009664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
9668
9669 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009670 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009671 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009672 enforceModifyPermission();
9673
changbettyd5c246e2019-12-24 15:40:37 +08009674 final long identity = Binder.clearCallingIdentity();
9675 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009676 Phone phone = getPhone(subscriptionId);
9677 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009678
Hall Liua62f5da2020-09-25 10:42:19 -07009679 switch (policy) {
9680 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9681 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9682 break;
9683 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9684 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9685 break;
9686 default:
9687 throw new IllegalArgumentException(policy + " is not a valid policy");
9688 }
changbettyd5c246e2019-12-24 15:40:37 +08009689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009694 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009695 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009696 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9697 * otherwise.
9698 */
9699 @Override
9700 public void setCepEnabled(boolean isCepEnabled) {
9701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9702
9703 final long identity = Binder.clearCallingIdentity();
9704 try {
9705 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9706 for (Phone phone : PhoneFactory.getPhones()) {
9707 Phone defaultPhone = phone.getImsPhone();
9708 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9709 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9710 ImsPhoneCallTracker imsPhoneCallTracker =
9711 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9712 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9713 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9714 + imsPhone.getMsisdn());
9715 }
9716 }
9717 } finally {
9718 Binder.restoreCallingIdentity(identity);
9719 }
9720 }
allenwtsu46dcc572020-01-08 18:24:03 +08009721
9722 /**
9723 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9724 *
9725 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9726 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9727 * before being read.
9728 */
9729 @Override
9730 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9731 isCompressed) {
9732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9733 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9736 }
9737 if (!isImsAvailableOnDevice()) {
9738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9739 "IMS not available on device.");
9740 }
9741
9742 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009743 try {
Hui Wang761a6682020-10-31 05:12:53 +00009744 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009747 }
9748 }
zoey chene02881a2019-12-30 16:11:23 +08009749
9750 @Override
9751 public boolean isIccLockEnabled(int subId) {
9752 enforceReadPrivilegedPermission("isIccLockEnabled");
9753
9754 // Now that all security checks passes, perform the operation as ourselves.
9755 final long identity = Binder.clearCallingIdentity();
9756 try {
9757 Phone phone = getPhone(subId);
9758 if (phone != null && phone.getIccCard() != null) {
9759 return phone.getIccCard().getIccLockEnabled();
9760 } else {
9761 return false;
9762 }
9763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767
9768 /**
9769 * Set the ICC pin lock enabled or disabled.
9770 *
9771 * @return an integer representing the status of IccLock enabled or disabled in the following
9772 * three cases:
9773 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9774 * successfully.
9775 * - Positive number and zero for remaining password attempts.
9776 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9777 *
9778 */
9779 @Override
9780 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9781 enforceModifyPermission();
9782
9783 Phone phone = getPhone(subId);
9784 if (phone == null) {
9785 return 0;
9786 }
9787 // Now that all security checks passes, perform the operation as ourselves.
9788 final long identity = Binder.clearCallingIdentity();
9789 try {
9790 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9791 new Pair<Boolean, String>(enabled, password), phone, null);
9792 return attemptsRemaining;
9793
9794 } catch (Exception e) {
9795 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9796 } finally {
9797 Binder.restoreCallingIdentity(identity);
9798 }
9799 return 0;
9800 }
9801
9802 /**
9803 * Change the ICC password used in ICC pin lock.
9804 *
9805 * @return an integer representing the status of IccLock changed in the following three cases:
9806 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9807 * - Positive number and zero for remaining password attempts.
9808 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9809 *
9810 */
9811 @Override
9812 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9813 enforceModifyPermission();
9814
9815 Phone phone = getPhone(subId);
9816 if (phone == null) {
9817 return 0;
9818 }
9819 // Now that all security checks passes, perform the operation as ourselves.
9820 final long identity = Binder.clearCallingIdentity();
9821 try {
9822 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9823 new Pair<String, String>(oldPassword, newPassword), phone, null);
9824 return attemptsRemaining;
9825
9826 } catch (Exception e) {
9827 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 return 0;
9832 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009833
9834 /**
9835 * Request for receiving user activity notification
9836 */
9837 @Override
9838 public void requestUserActivityNotification() {
9839 if (!mNotifyUserActivity.get()
9840 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9841 mNotifyUserActivity.set(true);
9842 }
9843 }
9844
9845 /**
9846 * Called when userActivity is signalled in the power manager.
9847 * This is safe to call from any thread, with any window manager locks held or not.
9848 */
9849 @Override
9850 public void userActivity() {
9851 // ***************************************
9852 // * Inherited from PhoneWindowManager *
9853 // ***************************************
9854 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9855 // WITH ITS LOCKS HELD.
9856 //
9857 // This code must be VERY careful about the locks
9858 // it acquires.
9859 // In fact, the current code acquires way too many,
9860 // and probably has lurking deadlocks.
9861
9862 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9863 throw new SecurityException("Only the OS may call notifyUserActivity()");
9864 }
9865
9866 if (mNotifyUserActivity.getAndSet(false)) {
9867 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9868 USER_ACTIVITY_NOTIFICATION_DELAY);
9869 }
9870 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009871
9872 @Override
9873 public boolean canConnectTo5GInDsdsMode() {
9874 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9875 }
Jack Yud10cdd42020-09-28 20:28:01 -07009876
9877 @Override
9878 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9879 String callingFeatureId) {
9880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9881 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9882 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9883 }
9884
9885 Phone phone = getPhone(subId);
9886 if (phone == null) {
9887 throw new RuntimeException("phone is not available");
9888 }
9889 // Now that all security checks passes, perform the operation as ourselves.
9890 final long identity = Binder.clearCallingIdentity();
9891 try {
9892 return phone.getEquivalentHomePlmns();
9893 } finally {
9894 Binder.restoreCallingIdentity(identity);
9895 }
9896 }
Daniel Bright59e67312020-11-13 11:49:37 -08009897
9898 @Override
9899 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009900 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9901 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009902 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009903 if (radioInterfaceCapabilities == null) {
9904 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009905 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009906 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009907 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009908
Hui Wang641e81c2020-10-12 12:14:23 -07009909 @Override
9910 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9911 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009912 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9913 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9914 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9915 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9916 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009917 if (DBG) {
9918 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9919 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9920 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9921 }
9922
9923 if (!SubscriptionManager.isValidSubscriptionId(subId)
9924 || appType < TelephonyManager.APPTYPE_UNKNOWN
9925 || appType > TelephonyManager.APPTYPE_ISIM
9926 || nafUrl == null || securityProtocol == null || callback == null) {
9927 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9928 if (callback != null) {
9929 try {
9930 callback.onAuthenticationFailure(
9931 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9932 } catch (RemoteException exception) {
9933 log("Fail to notify onAuthenticationFailure due to " + exception);
9934 }
9935 return;
9936 }
9937 }
9938
9939 final long token = Binder.clearCallingIdentity();
9940 try {
9941 getGbaManager(subId).bootstrapAuthenticationRequest(
9942 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9943 forceBootStrapping, callback));
9944 } finally {
9945 Binder.restoreCallingIdentity(token);
9946 }
9947 }
9948
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009949 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009950 * Attempts to set the radio power state for all phones for thermal reason.
9951 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009952 * requested radio power state will actually be set. See {@link
9953 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9954 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009955 * @param enable {@code true} if trying to turn radio on.
9956 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9957 * false}.
9958 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009959 private boolean setRadioPowerForThermal(boolean enable) {
9960 boolean isPhoneAvailable = false;
9961 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9962 Phone phone = PhoneFactory.getPhone(i);
9963 if (phone != null) {
9964 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9965 isPhoneAvailable = true;
9966 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009967 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009968
9969 // return true if successfully informed the phone object about the thermal radio power
9970 // request.
9971 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009972 }
9973
9974 private int handleDataThrottlingRequest(int subId,
9975 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009976 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9977 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9978 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9979 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9980 throw new IllegalArgumentException("modem does not support data throttling");
9981 }
9982
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009983 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9984 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009985 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009986 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9987 }
9988
9989 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9990
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009991 if (isDataThrottlingSupported) {
9992 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009993 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009994 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9995 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9996 } else if (thermalMitigationResult
9997 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009998 log("Modem likely does not support data throttling on secondary carrier. Data " +
9999 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10000 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010001 }
10002 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010003 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010004
10005 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010006 }
10007
Jack Nudelman644b91a2021-03-12 14:09:48 -080010008 private static List<String> getThermalMitigationAllowlist(Context context) {
10009 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10010 for (String pckg : context.getResources()
10011 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10012 sThermalMitigationAllowlistedPackages.add(pckg);
10013 }
10014 }
10015
10016 return sThermalMitigationAllowlistedPackages;
10017 }
10018
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010019 private boolean isAnyPhoneInEmergencyState() {
10020 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10021 if (tm.isInEmergencyCall()) {
10022 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10023 return true;
10024 }
10025 for (Phone phone : PhoneFactory.getPhones()) {
10026 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10027 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10028 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10029 + phone.isInEcm());
10030 return true;
10031 }
10032 }
10033
10034 return false;
10035 }
10036
Jack Nudelman644b91a2021-03-12 14:09:48 -080010037 /**
10038 * Used by shell commands to add an authorized package name for thermal mitigation.
10039 * @param packageName name of package to be allowlisted
10040 * @param context
10041 */
10042 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10043 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10044 sThermalMitigationAllowlistedPackages.add(packageName);
10045 }
10046
10047 /**
10048 * Used by shell commands to remove an authorized package name for thermal mitigation.
10049 * @param packageName name of package to remove from allowlist
10050 * @param context
10051 */
10052 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10053 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10054 sThermalMitigationAllowlistedPackages.remove(packageName);
10055 }
10056
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010057 /**
10058 * Thermal mitigation request to control functionalities at modem.
10059 *
10060 * @param subId the id of the subscription.
10061 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010062 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010063 *
10064 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10065 */
10066 @Override
10067 @ThermalMitigationResult
10068 public int sendThermalMitigationRequest(
10069 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010070 ThermalMitigationRequest thermalMitigationRequest,
10071 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010072 enforceModifyPermission();
10073
Jack Nudelman644b91a2021-03-12 14:09:48 -080010074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10075 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10076 .contains(callingPackage)) {
10077 throw new SecurityException("Calling package must be configured in the device config. "
10078 + "calling package: " + callingPackage);
10079 }
10080
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10082 final long identity = Binder.clearCallingIdentity();
10083
10084 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10085 try {
10086 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10087 switch (thermalMitigationAction) {
10088 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10089 thermalMitigationResult =
10090 handleDataThrottlingRequest(subId,
10091 thermalMitigationRequest.getDataThrottlingRequest());
10092 break;
10093 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10094 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10095 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10096 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10097 }
10098
10099 // Ensure that radio is on. If not able to power on due to phone being
10100 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010101 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102 thermalMitigationResult =
10103 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10104 break;
10105 }
10106
10107 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10108 false);
10109 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10110 break;
10111 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10112 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10113 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10114 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10115 }
10116
10117 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10118 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 Phone phone = getPhone(subId);
10120 if (phone == null) {
10121 thermalMitigationResult =
10122 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10123 break;
10124 }
10125
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010126 TelephonyConnectionService service =
10127 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010128 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010129 Log.e(LOG_TAG, "An emergency call is pending");
10130 thermalMitigationResult =
10131 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10132 break;
10133 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 thermalMitigationResult =
10135 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10136 break;
10137 }
10138 } else {
10139 thermalMitigationResult =
10140 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10141 break;
10142 }
10143
10144 // Turn radio off. If not able to power off due to phone being unavailable,
10145 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010146 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 thermalMitigationResult =
10148 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10149 break;
10150 }
10151 thermalMitigationResult =
10152 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10153 break;
10154 default:
10155 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10156 + "not exist. Requested action: " + thermalMitigationAction);
10157 }
10158 } catch (IllegalArgumentException e) {
10159 throw e;
10160 } catch (Exception e) {
10161 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10162 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166
10167 if (DBG) {
10168 log("thermalMitigationRequest returning with thermalMitigationResult: "
10169 + thermalMitigationResult);
10170 }
10171
10172 return thermalMitigationResult;
10173 }
Hui Wang641e81c2020-10-12 12:14:23 -070010174
10175 /**
10176 * Set the GbaService Package Name that Telephony will bind to.
10177 *
10178 * @param subId The sim that the GbaService is associated with.
10179 * @param packageName The name of the package to be replaced with.
10180 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10181 */
10182 @Override
10183 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10184 enforceModifyPermission();
10185
10186 final long identity = Binder.clearCallingIdentity();
10187 try {
10188 return getGbaManager(subId).overrideServicePackage(packageName);
10189 } finally {
10190 Binder.restoreCallingIdentity(identity);
10191 }
10192 }
10193
10194 /**
10195 * Return the package name of the currently bound GbaService.
10196 *
10197 * @param subId The sim that the GbaService is associated with.
10198 * @return the package name of the GbaService configuration, null if GBA is not supported.
10199 */
10200 @Override
10201 public String getBoundGbaService(int subId) {
10202 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10203
10204 final long identity = Binder.clearCallingIdentity();
10205 try {
10206 return getGbaManager(subId).getServicePackage();
10207 } finally {
10208 Binder.restoreCallingIdentity(identity);
10209 }
10210 }
10211
10212 /**
10213 * Set the release time for telephony to unbind GbaService.
10214 *
10215 * @param subId The sim that the GbaService is associated with.
10216 * @param interval The release time to unbind GbaService by millisecond.
10217 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10218 */
10219 @Override
10220 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10221 enforceModifyPermission();
10222
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
10225 return getGbaManager(subId).overrideReleaseTime(interval);
10226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
10231 /**
10232 * Return the release time for telephony to unbind GbaService.
10233 *
10234 * @param subId The sim that the GbaService is associated with.
10235 * @return The release time to unbind GbaService by millisecond.
10236 */
10237 @Override
10238 public int getGbaReleaseTime(int subId) {
10239 enforceReadPrivilegedPermission("getGbaReleaseTime");
10240
10241 final long identity = Binder.clearCallingIdentity();
10242 try {
10243 return getGbaManager(subId).getReleaseTime();
10244 } finally {
10245 Binder.restoreCallingIdentity(identity);
10246 }
10247 }
10248
10249 private GbaManager getGbaManager(int subId) {
10250 GbaManager instance = GbaManager.getInstance(subId);
10251 if (instance == null) {
10252 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10253 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10254 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10255 }
10256 return instance;
10257 }
Hui Wang761a6682020-10-31 05:12:53 +000010258
10259 /**
10260 * indicate whether the device and the carrier can support
10261 * RCS VoLTE single registration.
10262 */
10263 @Override
10264 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010265 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10266 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10267 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10268 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010269
10270 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10271 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10272 }
10273
10274 final long identity = Binder.clearCallingIdentity();
10275 try {
10276 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10277 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010278 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10279 if (isCapable != null) {
10280 return isCapable;
10281 }
Hui Wang761a6682020-10-31 05:12:53 +000010282 }
Hui Wang67af90e2021-06-04 16:57:15 -070010283 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10284 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
10290 /**
10291 * Register RCS provisioning callback.
10292 */
10293 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010294 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010295 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010296 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010297 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010298 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10299 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010300
10301 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10302 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10303 }
10304 if (!isImsAvailableOnDevice()) {
10305 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10306 "IMS not available on device.");
10307 }
10308
10309 final long identity = Binder.clearCallingIdentity();
10310 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010311 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010312 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010313 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10314 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010315 }
Hui Wang761a6682020-10-31 05:12:53 +000010316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
10320
10321 /**
10322 * Unregister RCS provisioning callback.
10323 */
10324 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010325 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010326 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010327 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010328 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010329 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10330 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010331
10332 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10333 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10334 }
10335 if (!isImsAvailableOnDevice()) {
10336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10337 "IMS not available on device.");
10338 }
10339
10340 final long identity = Binder.clearCallingIdentity();
10341 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010342 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010343 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
10348
10349 /**
10350 * trigger RCS reconfiguration.
10351 */
10352 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010353 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10354 "triggerRcsReconfiguration",
10355 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010356
10357 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10358 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10359 }
10360 if (!isImsAvailableOnDevice()) {
10361 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10362 "IMS not available on device.");
10363 }
10364
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
10367 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10368 } finally {
10369 Binder.restoreCallingIdentity(identity);
10370 }
10371 }
10372
10373 /**
10374 * Provide the client configuration parameters of the RCS application.
10375 */
10376 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010377 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10378 "setRcsClientConfiguration",
10379 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010380
10381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10382 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10383 }
10384 if (!isImsAvailableOnDevice()) {
10385 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10386 "IMS not available on device.");
10387 }
10388
10389 final long identity = Binder.clearCallingIdentity();
10390
10391 try {
10392 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10393 if (configBinder == null) {
10394 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010395 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10396 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010397 } else {
10398 configBinder.setRcsClientConfiguration(rcc);
10399 }
joonhunshin35f64142021-09-17 06:33:39 +000010400
10401 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10402 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010403 } catch (RemoteException e) {
10404 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010405 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10406 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 }
10411
10412 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010413 * Enables or disables the test mode for RCS VoLTE single registration.
10414 */
10415 @Override
10416 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "setRcsSingleRegistrationTestModeEnabled");
10419
10420 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10421 }
10422
10423 /**
10424 * Gets the test mode for RCS VoLTE single registration.
10425 */
10426 @Override
10427 public boolean getRcsSingleRegistrationTestModeEnabled() {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "getRcsSingleRegistrationTestModeEnabled");
10430
10431 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10432 }
10433
10434 /**
Hui Wang761a6682020-10-31 05:12:53 +000010435 * Overrides the config of RCS VoLTE single registration enabled for the device.
10436 */
10437 @Override
10438 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10439 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10440 "setDeviceSingleRegistrationEnabledOverride");
10441 enforceModifyPermission();
10442
10443 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10444 : Boolean.parseBoolean(enabledStr);
10445 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010446 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010447 }
10448
10449 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010450 * Sends a device to device communication message. Only usable via shell.
10451 * @param message message to send.
10452 * @param value message value.
10453 */
10454 @Override
10455 public void sendDeviceToDeviceMessage(int message, int value) {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010457 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010458 enforceModifyPermission();
10459
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
10462 TelephonyConnectionService service =
10463 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10464 if (service == null) {
10465 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10466 return;
10467 }
10468 service.sendTestDeviceToDeviceMessage(message, value);
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
Tyler Gunnbabbda02021-02-10 11:05:02 -080010474 /**
10475 * Sets the specified device to device transport active.
10476 * @param transport The transport to set active.
10477 */
10478 @Override
10479 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10480 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10481 "setActiveDeviceToDeviceTransport");
10482 enforceModifyPermission();
10483
10484 final long identity = Binder.clearCallingIdentity();
10485 try {
10486 TelephonyConnectionService service =
10487 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10488 if (service == null) {
10489 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10490 return;
10491 }
10492 service.setActiveDeviceToDeviceTransport(transport);
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
Tyler Gunn92479152021-01-20 16:30:10 -080010497
Tyler Gunnd4575212021-05-03 14:46:49 -070010498 @Override
10499 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10500 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10501 "setDeviceToDeviceForceEnabled");
10502
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
10505 Arrays.stream(PhoneFactory.getPhones()).forEach(
10506 p -> {
10507 Phone thePhone = p.getImsPhone();
10508 if (thePhone != null && thePhone instanceof ImsPhone) {
10509 ImsPhone imsPhone = (ImsPhone) thePhone;
10510 CallTracker tracker = imsPhone.getCallTracker();
10511 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10512 ImsPhoneCallTracker imsPhoneCallTracker =
10513 (ImsPhoneCallTracker) tracker;
10514 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10515 }
10516 }
10517 }
10518 );
10519 } finally {
10520 Binder.restoreCallingIdentity(identity);
10521 }
10522 }
10523
Tyler Gunn92479152021-01-20 16:30:10 -080010524 /**
Hui Wang761a6682020-10-31 05:12:53 +000010525 * Gets the config of RCS VoLTE single registration enabled for the device.
10526 */
10527 @Override
10528 public boolean getDeviceSingleRegistrationEnabled() {
10529 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10530 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10531 }
10532
10533 /**
10534 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10535 */
10536 @Override
10537 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10538 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10539 "setCarrierSingleRegistrationEnabledOverride");
10540 enforceModifyPermission();
10541
10542 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10543 : Boolean.parseBoolean(enabledStr);
10544 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10545 subId, enabled);
10546 }
10547
10548 /**
10549 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10550 */
10551 @Override
10552 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10553 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10554 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10555 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010556
10557 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010558 * Overrides the ims feature validation result
10559 */
10560 @Override
10561 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10562 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10563 "setImsFeatureValidationOverride");
10564
10565 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10566 : Boolean.parseBoolean(enabledStr);
10567 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10568 subId, enabled);
10569 }
10570
10571 /**
10572 * Gets the ims feature validation override value
10573 */
10574 @Override
10575 public boolean getImsFeatureValidationOverride(int subId) {
10576 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10577 "getImsFeatureValidationOverride");
10578 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10579 }
10580
10581 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010582 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10583 * their mobile plan.
10584 */
10585 @Override
10586 public String getMobileProvisioningUrl() {
10587 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10588 final long identity = Binder.clearCallingIdentity();
10589 try {
10590 return getDefaultPhone().getMobileProvisioningUrl();
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010595
James.cf Linbcdf8b32021-01-14 16:44:13 +080010596 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010597 * Get the EAB contact from the EAB database.
10598 */
10599 @Override
10600 public String getContactFromEab(String contact) {
10601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10602 enforceModifyPermission();
10603 final long identity = Binder.clearCallingIdentity();
10604 try {
10605 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10606 } finally {
10607 Binder.restoreCallingIdentity(identity);
10608 }
10609 }
10610
10611 /**
Calvin Pana1434322021-07-01 19:27:01 +080010612 * Get the EAB capability from the EAB database.
10613 */
10614 @Override
10615 public String getCapabilityFromEab(String contact) {
10616 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10617 enforceModifyPermission();
10618 final long identity = Binder.clearCallingIdentity();
10619 try {
10620 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10621 } finally {
10622 Binder.restoreCallingIdentity(identity);
10623 }
10624 }
10625
10626 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010627 * Remove the EAB contacts from the EAB database.
10628 */
10629 @Override
10630 public int removeContactFromEab(int subId, String contacts) {
10631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10632 enforceModifyPermission();
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010641 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010642 public boolean getDeviceUceEnabled() {
10643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 return mApp.getDeviceUceEnabled();
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
10651
10652 @Override
10653 public void setDeviceUceEnabled(boolean isEnabled) {
10654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 mApp.setDeviceUceEnabled(isEnabled);
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
Brad Ebinger14d467f2021-02-12 06:18:28 +000010663 /**
10664 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10665 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10666 */
10667 // Used for SHELL command only right now.
10668 @Override
10669 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10670 List<String> featureTags) {
10671 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10672 "addUceRegistrationOverrideShell");
10673 final long identity = Binder.clearCallingIdentity();
10674 try {
10675 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10676 new ArraySet<>(featureTags));
10677 } catch (ImsException e) {
10678 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
10683
10684 /**
10685 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10686 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10687 */
10688 // Used for SHELL command only right now.
10689 @Override
10690 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10691 List<String> featureTags) {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10693 "removeUceRegistrationOverrideShell");
10694 final long identity = Binder.clearCallingIdentity();
10695 try {
10696 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10697 new ArraySet<>(featureTags));
10698 } catch (ImsException e) {
10699 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10700 } finally {
10701 Binder.restoreCallingIdentity(identity);
10702 }
10703 }
10704
10705 /**
10706 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10707 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10708 */
10709 // Used for SHELL command only right now.
10710 @Override
10711 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10713 "clearUceRegistrationOverrideShell");
10714 final long identity = Binder.clearCallingIdentity();
10715 try {
10716 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10717 } catch (ImsException e) {
10718 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
10723
10724 /**
10725 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10726 */
10727 // Used for SHELL command only right now.
10728 @Override
10729 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10731 "getLatestRcsContactUceCapabilityShell");
10732 final long identity = Binder.clearCallingIdentity();
10733 try {
10734 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10735 } catch (ImsException e) {
10736 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740 }
10741
10742 /**
10743 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10744 * device does not have an active PUBLISH.
10745 */
10746 // Used for SHELL command only right now.
10747 @Override
10748 public String getLastUcePidfXmlShell(int subId) {
10749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10753 } catch (ImsException e) {
10754 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
10759
James.cf Line8713a42021-04-29 16:04:26 +080010760 /**
10761 * Remove UCE requests cannot be sent to the network status.
10762 */
10763 // Used for SHELL command only right now.
10764 @Override
10765 public boolean removeUceRequestDisallowedStatus(int subId) {
10766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10770 } catch (ImsException e) {
10771 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
James.cf Lin0fc71b02021-05-25 01:37:38 +080010777 /**
10778 * Remove UCE requests cannot be sent to the network status.
10779 */
10780 // Used for SHELL command only.
10781 @Override
10782 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10784 final long identity = Binder.clearCallingIdentity();
10785 try {
10786 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10787 } catch (ImsException e) {
10788 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010793
James.cf Lin4b784aa2021-01-31 03:25:15 +080010794 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010795 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10796 String callingPackage) {
10797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10798 mApp, subId, "setSignalStrengthUpdateRequest");
10799
10800 final int callingUid = Binder.getCallingUid();
10801 // Verify that tha callingPackage belongs to the calling UID
10802 mApp.getSystemService(AppOpsManager.class)
10803 .checkPackage(callingUid, callingPackage);
10804
Rambo Wang3607f502021-02-01 21:51:40 -080010805 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010806
10807 final long identity = Binder.clearCallingIdentity();
10808 try {
10809 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10810 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10811
10812 if (result instanceof IllegalStateException) {
10813 throw (IllegalStateException) result;
10814 }
10815 } finally {
10816 Binder.restoreCallingIdentity(identity);
10817 }
10818 }
10819
10820 @Override
10821 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10822 String callingPackage) {
10823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10824 mApp, subId, "clearSignalStrengthUpdateRequest");
10825
10826 final int callingUid = Binder.getCallingUid();
10827 // Verify that tha callingPackage belongs to the calling UID
10828 mApp.getSystemService(AppOpsManager.class)
10829 .checkPackage(callingUid, callingPackage);
10830
10831 final long identity = Binder.clearCallingIdentity();
10832 try {
10833 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10834 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10835
10836 if (result instanceof IllegalStateException) {
10837 throw (IllegalStateException) result;
10838 }
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
Rambo Wang3607f502021-02-01 21:51:40 -080010844 private static void validateSignalStrengthUpdateRequest(Context context,
10845 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010846 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10847 // phone/system process do not have further restriction on request
10848 return;
10849 }
10850
10851 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010852 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010853 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010854 context.enforceCallingOrSelfPermission(
10855 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10856 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010857 }
10858
10859 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10860 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10861 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10862 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10863 || info.isEnabled()) {
10864 throw new IllegalArgumentException(
10865 "Only system can set hide fields in SignalThresholdInfo");
10866 }
10867
10868 // Thresholds length for each RAN need in range. This has been validated in
10869 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10870 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10871 final int[] thresholds = info.getThresholds();
10872 Objects.requireNonNull(thresholds);
10873 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10874 || thresholds.length
10875 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10876 throw new IllegalArgumentException(
10877 "thresholds length is out of range: " + thresholds.length);
10878 }
10879 }
10880 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010881
10882 /**
10883 * Gets the current phone capability.
10884 *
10885 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10886 * @return the PhoneCapability which describes the data connection capability of modem.
10887 * It's used to evaluate possible phone config change, for example from single
10888 * SIM device to multi-SIM device.
10889 */
10890 @Override
10891 public PhoneCapability getPhoneCapability() {
10892 enforceReadPrivilegedPermission("getPhoneCapability");
10893 final long identity = Binder.clearCallingIdentity();
10894 try {
10895 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10896 } finally {
10897 Binder.restoreCallingIdentity(identity);
10898 }
10899 }
Michele Berionne5e411512020-11-13 02:36:59 +000010900
10901 /**
10902 * Prepare TelephonyManager for an unattended reboot. The reboot is
10903 * required to be done shortly after the API is invoked.
10904 */
10905 @Override
10906 @TelephonyManager.PrepareUnattendedRebootResult
10907 public int prepareForUnattendedReboot() {
10908 enforceRebootPermission();
10909
10910 final long identity = Binder.clearCallingIdentity();
10911 try {
10912 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010917
10918 /**
10919 * Request to get the current slicing configuration including URSP rules and
10920 * NSSAIs (configured, allowed and rejected).
10921 *
10922 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10923 */
10924 @Override
10925 public void getSlicingConfig(ResultReceiver callback) {
10926 enforceReadPrivilegedPermission("getSlicingConfig");
10927
10928 final long identity = Binder.clearCallingIdentity();
10929 try {
10930 Phone phone = getDefaultPhone();
10931 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010936
10937 /**
10938 * Register an IMS connection state callback
10939 */
10940 @Override
10941 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10942 String callingPackage) {
10943 if (feature == ImsFeature.FEATURE_MMTEL) {
10944 // ImsMmTelManager
10945 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10946 TelephonyPermissions
10947 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10948 mApp, subId, "registerImsStateCallback");
10949 } else if (feature == ImsFeature.FEATURE_RCS) {
10950 // ImsRcsManager or SipDelegateManager
10951 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10952 Binder.getCallingUid(), "registerImsStateCallback",
10953 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10954 Manifest.permission.READ_PRECISE_PHONE_STATE,
10955 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10956 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10957 }
10958
10959 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10960 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10961 "IMS not available on device.");
10962 }
10963
10964 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
10965 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
10966 }
10967
10968 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10969 if (controller == null) {
10970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10971 "IMS not available on device.");
10972 }
10973
10974 if (callingPackage == null) {
10975 callingPackage = getCurrentPackageName();
10976 }
10977
10978 final long token = Binder.clearCallingIdentity();
10979 try {
10980 int slotId = getSlotIndexOrException(subId);
10981 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
10982 } catch (ImsException e) {
10983 throw new ServiceSpecificException(e.getCode());
10984 } finally {
10985 Binder.restoreCallingIdentity(token);
10986 }
10987 }
10988
10989 /**
10990 * Unregister an IMS connection state callback
10991 */
10992 @Override
10993 public void unregisterImsStateCallback(IImsStateCallback cb) {
10994 final long token = Binder.clearCallingIdentity();
10995 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10996 if (controller == null) {
10997 return;
10998 }
10999 try {
11000 controller.unregisterImsStateCallback(cb);
11001 } finally {
11002 Binder.restoreCallingIdentity(token);
11003 }
11004 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011005
11006 /**
11007 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11008 *
11009 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11010 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11011 * SecurityException.
11012 * If there is current registered network this value will be same as the registered cell
11013 * identity. If the device goes out of service the previous cell identity is cached and
11014 * will be returned. If the cache age of the Cell identity is more than 24 hours
11015 * it will be cleared and null will be returned.
11016 *
11017 */
11018 @Override
11019 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11020 String callingFeatureId) {
11021 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11022 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11023 LocationAccessPolicy.checkLocationPermission(mApp,
11024 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11025 .setCallingPackage(callingPackage)
11026 .setCallingFeatureId(callingFeatureId)
11027 .setCallingPid(Binder.getCallingPid())
11028 .setCallingUid(Binder.getCallingUid())
11029 .setMethod("getLastKnownCellIdentity")
11030 .setLogAsInfo(true)
11031 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11032 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11033 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11034 .build());
11035
11036 boolean hasFinePermission =
11037 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11038 if (!hasFinePermission
11039 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11040 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11041 + "and BIND_CONNECTION_SERVICE permission.");
11042 }
11043
11044 final long identity = Binder.clearCallingIdentity();
11045 try {
11046 Phone phone = getPhone(subId);
11047 if (phone == null) return null;
11048 ServiceStateTracker sst = phone.getServiceStateTracker();
11049 if (sst == null) return null;
11050 return sst.getLastKnownCellIdentity();
11051 } finally {
11052 Binder.restoreCallingIdentity(identity);
11053 }
11054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011055}