blob: 804382abda379c19e615a321b6e2b53c2263f36e [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) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005043 mApp, subId, callingPackage, callingFeatureId,
5044 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005045 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5046 }
5047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 final long identity = Binder.clearCallingIdentity();
5049 try {
5050 final Phone phone = getPhone(subId);
5051 if (phone != null) {
5052 return phone.getServiceState().getDataNetworkType();
5053 } else {
5054 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5055 }
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005059 }
5060
5061 /**
Wink Saville36469e72014-06-11 15:17:00 -07005062 * Returns the Voice network type for a subId
5063 */
5064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005065 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5066 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 mApp, subId, callingPackage, callingFeatureId,
5069 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005070 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5071 }
5072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 final Phone phone = getPhone(subId);
5076 if (phone != null) {
5077 return phone.getServiceState().getVoiceNetworkType();
5078 } else {
5079 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5080 }
5081 } finally {
5082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005084 }
5085
5086 /**
5087 * @return true if a ICC card is present
5088 */
5089 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005090 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005091 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5092 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005093 }
5094
5095 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005096 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005097 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005098 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005099 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
5102 final Phone phone = PhoneFactory.getPhone(slotIndex);
5103 if (phone != null) {
5104 return phone.getIccCard().hasIccCard();
5105 } else {
5106 return false;
5107 }
5108 } finally {
5109 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005111 }
5112
5113 /**
5114 * Return if the current radio is LTE on CDMA. This
5115 * is a tri-state return value as for a period of time
5116 * the mode may be unknown.
5117 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005118 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005119 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005120 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005121 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005123 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5124 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5125 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005126 }
5127
Sanket Padawe356d7632015-06-22 14:03:32 -07005128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005129 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5130 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005131 try {
5132 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5133 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005134 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5135 }
5136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 final long identity = Binder.clearCallingIdentity();
5138 try {
5139 final Phone phone = getPhone(subId);
5140 if (phone == null) {
5141 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5142 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005143 return TelephonyProperties.lte_on_cdma_device()
5144 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 }
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005148 }
Wink Saville36469e72014-06-11 15:17:00 -07005149 }
5150
Wink Saville36469e72014-06-11 15:17:00 -07005151 /**
5152 * {@hide}
5153 * Returns Default subId, 0 in the case of single standby.
5154 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005155 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005156 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005157 }
5158
Shishir Agrawala9f32182016-04-12 12:00:16 -07005159 private int getSlotForDefaultSubscription() {
5160 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5161 }
5162
Wink Savilleb564aae2014-10-23 10:18:09 -07005163 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005164 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005165 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005166
Pengquan Menge92a50d2018-09-21 15:54:48 -07005167 private boolean isActiveSubscription(int subId) {
5168 return mSubscriptionController.isActiveSubId(subId);
5169 }
5170
Ihab Awadf2177b72013-11-25 13:33:23 -08005171 /**
5172 * @see android.telephony.TelephonyManager.WifiCallingChoices
5173 */
5174 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 final long identity = Binder.clearCallingIdentity();
5176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005177 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5179 getWhenToMakeWifiCallsDefaultPreference());
5180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005183 }
5184
5185 /**
5186 * @see android.telephony.TelephonyManager.WifiCallingChoices
5187 */
5188 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 final long identity = Binder.clearCallingIdentity();
5190 try {
5191 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005192 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005197 }
5198
Sailesh Nepald1e68152013-12-12 19:08:02 -08005199 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005200 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005201 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005202 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005203
Jordan Liu4c733742019-02-28 12:03:40 -08005204 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5205 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5206 if (phoneId == -1) {
5207 throw new IllegalArgumentException("Given slot index: " + slotIndex
5208 + " does not correspond to an active phone");
5209 }
5210 return PhoneFactory.getPhone(phoneId);
5211 }
5212
Shishir Agrawal566b7612013-10-28 14:41:00 -07005213 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005214 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5215 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5217 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005219 if (DBG) {
5220 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5221 }
5222 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5223 p2);
5224 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005225
Jordan Liu4c733742019-02-28 12:03:40 -08005226
5227 @Override
5228 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5229 int slotIndex, String callingPackage, String aid, int p2) {
5230 enforceModifyPermission();
5231 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5232 if (DBG) {
5233 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5234 }
5235 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5236 callingPackage, aid, p2);
5237 }
5238
5239 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5240 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 if (TextUtils.equals(ISDR_AID, aid)) {
5244 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005245 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5246 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 if (bestComponent == null
5248 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5249 loge("The calling package is not allowed to access ISD-R.");
5250 throw new SecurityException(
5251 "The calling package is not allowed to access ISD-R.");
5252 }
Derek Tan740e1672017-06-27 14:56:27 -07005253 }
Derek Tan740e1672017-06-27 14:56:27 -07005254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005256 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5257 null /* workSource */);
5258 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 return response;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005263 }
5264
5265 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005266 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5268 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005269 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5270 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5271 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005272
Jordan Liu4c733742019-02-28 12:03:40 -08005273 @Override
5274 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5275 enforceModifyPermission();
5276 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5277 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5278 channel);
5279 }
5280
5281 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 if (channel < 0) {
5285 return false;
5286 }
Jordan Liu4c733742019-02-28 12:03:40 -08005287 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5288 null /* workSource */);
5289 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 return success;
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005294 }
5295
5296 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005297 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005298 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005301 if (DBG) {
5302 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5303 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5304 + p3 + " data=" + data);
5305 }
5306 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5307 command, p1, p2, p3, data);
5308 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005309
Jordan Liu4c733742019-02-28 12:03:40 -08005310 @Override
5311 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5312 int command, int p1, int p2, int p3, String data) {
5313 enforceModifyPermission();
5314 if (DBG) {
5315 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5316 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5317 + p3 + " data=" + data);
5318 }
5319 return iccTransmitApduLogicalChannelWithPermission(
5320 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5321 data);
5322 }
5323
5324 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5325 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005328 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 return "";
5330 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005333 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5334 null /* workSource */);
5335 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 // Append the returned status code to the end of the response payload.
5338 String s = Integer.toHexString(
5339 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5340 if (response.payload != null) {
5341 s = IccUtils.bytesToHexString(response.payload) + s;
5342 }
5343 return s;
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005347 }
Jake Hambye994d462014-02-03 13:10:13 -08005348
Evan Charltonc66da362014-05-16 14:06:40 -07005349 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005350 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5351 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5353 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005355 if (DBG) {
5356 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5357 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5358 }
5359 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5360 cla, command, p1, p2, p3, data);
5361 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005362
Jordan Liu4c733742019-02-28 12:03:40 -08005363 @Override
5364 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5365 int command, int p1, int p2, int p3, String data) {
5366 enforceModifyPermission();
5367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5368 if (DBG) {
5369 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5370 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5371 + " data=" + data);
5372 }
5373
5374 return iccTransmitApduBasicChannelWithPermission(
5375 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5376 p2, p3, data);
5377 }
5378
5379 // open APDU basic channel assuming the caller has sufficient permissions
5380 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5381 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 final long identity = Binder.clearCallingIdentity();
5383 try {
5384 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5385 && TextUtils.equals(ISDR_AID, data)) {
5386 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005387 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5388 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 if (bestComponent == null
5390 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5391 loge("The calling package is not allowed to select ISD-R.");
5392 throw new SecurityException(
5393 "The calling package is not allowed to select ISD-R.");
5394 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005395 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005398 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5399 null /* workSource */);
5400 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 // Append the returned status code to the end of the response payload.
5403 String s = Integer.toHexString(
5404 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5405 if (response.payload != null) {
5406 s = IccUtils.bytesToHexString(response.payload) + s;
5407 }
5408 return s;
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005411 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005412 }
5413
5414 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005415 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005416 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5418 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 if (DBG) {
5423 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5424 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5425 }
5426
5427 IccIoResult response =
5428 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5429 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5430 subId);
5431
5432 if (DBG) {
5433 log("Exchange SIM_IO [R]" + response);
5434 }
5435
5436 byte[] result = null;
5437 int length = 2;
5438 if (response.payload != null) {
5439 length = 2 + response.payload.length;
5440 result = new byte[length];
5441 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5442 } else {
5443 result = new byte[length];
5444 }
5445
5446 result[length - 1] = (byte) response.sw2;
5447 result[length - 2] = (byte) response.sw1;
5448 return result;
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005451 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005452 }
5453
Nathan Haroldb3014052017-01-25 15:57:32 -08005454 /**
5455 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5456 * on a particular subscription
5457 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005458 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5459 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005461 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005462 return null;
5463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 if (appType != TelephonyManager.APPTYPE_USIM
5468 && appType != TelephonyManager.APPTYPE_SIM) {
5469 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5470 return null;
5471 }
5472 Object response = sendRequest(
5473 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5474 if (response instanceof String[]) {
5475 return (String[]) response;
5476 }
yincheng zhao2737e882019-09-06 17:06:54 -07005477 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005479 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005482 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005483 }
5484
yincheng zhao2737e882019-09-06 17:06:54 -07005485 /**
5486 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5487 * subscription.
5488 *
5489 * @param subId the id of the subscription.
5490 * @param appType the uicc app type, must be USIM or SIM.
5491 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5492 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005493 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005494 * @return number of fplmns that is successfully written to the SIM.
5495 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005496 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5497 String callingFeatureId) {
5498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5499 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005500 if (DBG) logv("no permissions for setForbiddenplmns");
5501 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5502 }
5503 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5504 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5505 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5506 }
5507 if (fplmns == null) {
5508 throw new IllegalArgumentException("Fplmn List provided is null");
5509 }
5510 for (String fplmn : fplmns) {
5511 if (!CellIdentity.isValidPlmn(fplmn)) {
5512 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5513 }
5514 }
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 Object response = sendRequest(
5518 CMD_SET_FORBIDDEN_PLMNS,
5519 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5520 subId);
5521 return (int) response;
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
5525 }
5526
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005527 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005528 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5530 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5535 if (response.payload == null) {
5536 return "";
5537 }
Evan Charltonc66da362014-05-16 14:06:40 -07005538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 // Append the returned status code to the end of the response payload.
5540 String s = Integer.toHexString(
5541 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5542 s = IccUtils.bytesToHexString(response.payload) + s;
5543 return s;
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Evan Charltonc66da362014-05-16 14:06:40 -07005547 }
5548
Jake Hambye994d462014-02-03 13:10:13 -08005549 /**
5550 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5551 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5552 *
5553 * @param itemID the ID of the item to read
5554 * @return the NV item as a String, or null on error.
5555 */
5556 @Override
5557 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005558 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5560 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005565 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5567 return value;
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Jake Hambye994d462014-02-03 13:10:13 -08005571 }
5572
5573 /**
5574 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5575 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5576 *
5577 * @param itemID the ID of the item to read
5578 * @param itemValue the value to write, as a String
5579 * @return true on success; false on any failure
5580 */
5581 @Override
5582 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586
5587 final long identity = Binder.clearCallingIdentity();
5588 try {
5589 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5590 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5593 return success;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Jake Hambye994d462014-02-03 13:10:13 -08005597 }
5598
5599 /**
5600 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5601 * Used for device configuration by some CDMA operators.
5602 *
5603 * @param preferredRoamingList byte array containing the new PRL
5604 * @return true on success; false on any failure
5605 */
5606 @Override
5607 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5609 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5614 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5615 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5616 return success;
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jake Hambye994d462014-02-03 13:10:13 -08005620 }
5621
5622 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005623 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005624 * Used for device configuration by some CDMA operators.
5625 *
chen xu6dac5ab2018-10-26 17:39:23 -07005626 * @param slotIndex - device slot.
5627 *
Jake Hambye994d462014-02-03 13:10:13 -08005628 * @return true on success; false on any failure
5629 */
5630 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005631 public boolean resetModemConfig(int slotIndex) {
5632 Phone phone = PhoneFactory.getPhone(slotIndex);
5633 if (phone != null) {
5634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
chen xu6dac5ab2018-10-26 17:39:23 -07005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5640 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5641 return success;
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 }
chen xu6dac5ab2018-10-26 17:39:23 -07005646 return false;
5647 }
5648
5649 /**
5650 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5651 *
5652 * @param slotIndex - device slot.
5653 *
5654 * @return true on success; false on any failure
5655 */
5656 @Override
5657 public boolean rebootModem(int slotIndex) {
5658 Phone phone = PhoneFactory.getPhone(slotIndex);
5659 if (phone != null) {
5660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, phone.getSubId(), "rebootModem");
5662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5666 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5667 return success;
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
5671 }
5672 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005673 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005674
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005675 public String[] getPcscfAddress(String apnType, String callingPackage,
5676 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5679 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005680 return new String[0];
5681 }
5682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 final long identity = Binder.clearCallingIdentity();
5684 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005685 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
Wink Saville36469e72014-06-11 15:17:00 -07005689 }
5690
Brad Ebinger51f743a2017-01-23 13:50:20 -08005691 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005692 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5693 * {@link #disableIms(int)}.
5694 * @param slotIndex device slot.
5695 */
5696 public void resetIms(int slotIndex) {
5697 enforceModifyPermission();
5698
5699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 if (mImsResolver == null) {
5702 // may happen if the does not support IMS.
5703 return;
5704 }
5705 mImsResolver.disableIms(slotIndex);
5706 mImsResolver.enableIms(slotIndex);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
5710 }
5711
5712 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5714 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005715 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005716 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005717 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005722 // may happen if the device does not support IMS.
5723 return;
5724 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005725 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005729 }
5730
5731 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005732 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5733 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005734 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005735 public void disableIms(int slotId) {
5736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005740 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005741 // may happen if the device does not support IMS.
5742 return;
5743 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 }
5749
5750 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005751 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5752 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005753 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005754 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005755 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757
5758 final long identity = Binder.clearCallingIdentity();
5759 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005760 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5762 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005764 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005768 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005769 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005770 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5771 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005772 @Override
5773 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005774 enforceModifyPermission();
5775
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005779 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
5783 }
5784
5785 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005786 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005788 */
5789 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005795 // may happen if the device does not support IMS.
5796 return null;
5797 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005802 }
5803
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005804 /**
5805 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005806 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005807 */
5808 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005813 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005814 // may happen if the device does not support IMS.
5815 return null;
5816 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005821 }
5822
Brad Ebinger884c07b2018-02-15 16:17:40 -08005823 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005824 * Sets the ImsService Package Name that Telephony will bind to.
5825 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 * @param slotIndex the slot ID that the ImsService should bind for.
5827 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005828 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 * @param featureTypes An integer array of feature types associated with a packageName.
5830 * @param packageName The name of the package that the current configuration will be replaced
5831 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005832 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005833 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5835 int[] featureTypes, String packageName) {
5836 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5839 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005845 // may happen if the device does not support IMS.
5846 return false;
5847 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 Map<Integer, String> featureConfig = new HashMap<>();
5849 for (int featureType : featureTypes) {
5850 featureConfig.put(featureType, packageName);
5851 }
5852 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5853 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005857 }
5858
5859 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005860 * Clears any carrier ImsService overrides for the slot index specified that were previously
5861 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5862 *
5863 * This should only be used for testing.
5864 *
5865 * @param slotIndex the slot ID that the ImsService should bind for.
5866 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5867 */
5868 @Override
5869 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5870 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5872 "clearCarrierImsServiceOverride");
5873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5874 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5875 "clearCarrierImsServiceOverride");
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 if (mImsResolver == null) {
5880 // may happen if the device does not support IMS.
5881 return false;
5882 }
5883 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
5887 }
5888
5889 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005891 *
5892 * @param slotId The slot that the ImsService is associated with.
5893 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5894 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005896 * @return the package name of the ImsService configuration.
5897 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5899 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005900 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005902 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005903 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5904 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 final long identity = Binder.clearCallingIdentity();
5907 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005909 // may happen if the device does not support IMS.
5910 return "";
5911 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005912 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005913 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5914 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005918 }
5919
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005920 /**
5921 * Get the MmTelFeature state associated with the requested subscription id.
5922 * @param subId The subscription that the MmTelFeature is associated with.
5923 * @param callback A callback with an integer containing the
5924 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5925 */
5926 @Override
5927 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5928 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5929 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5931 "IMS not available on device.");
5932 }
5933 final long token = Binder.clearCallingIdentity();
5934 try {
5935 int slotId = getSlotIndex(subId);
5936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5937 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5938 + subId + "'");
5939 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5940 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005941 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005942 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5943 try {
5944 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5945 } catch (RemoteException e) {
5946 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5947 + "Ignore");
5948 }
5949 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005950 } catch (ImsException e) {
5951 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005952 } finally {
5953 Binder.restoreCallingIdentity(token);
5954 }
5955 }
5956
Daniel Brightbb5840b2021-01-12 15:48:18 -08005957 /**
5958 * Sets the ims registration state on all valid {@link Phone}s.
5959 */
5960 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005965 // NOTE: Before S, this method only set the default phone.
5966 for (final Phone phone : PhoneFactory.getPhones()) {
5967 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5968 phone.setImsRegistrationState(registered);
5969 }
5970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Wink Saville36469e72014-06-11 15:17:00 -07005974 }
5975
5976 /**
Stuart Scott54788802015-03-30 13:18:01 -07005977 * Set the network selection mode to automatic.
5978 *
5979 */
5980 @Override
5981 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5983 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
shilufc958392020-01-20 11:36:01 -08005987 if (!isActiveSubscription(subId)) {
5988 return;
5989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005991 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5992 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Stuart Scott54788802015-03-30 13:18:01 -07005996 }
5997
Jack Yud10cdd42020-09-28 20:28:01 -07005998 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005999 * Ask the radio to connect to the input network and change selection mode to manual.
6000 *
6001 * @param subId the id of the subscription.
6002 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6003 * the operator to attach to.
6004 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6005 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6006 * normal network selection next time.
6007 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006008 */
6009 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006010 public boolean setNetworkSelectionModeManual(
6011 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006014
6015 if (!isActiveSubscription(subId)) {
6016 return false;
6017 }
6018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006021 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006023 if (DBG) {
6024 log("setNetworkSelectionModeManual: subId: " + subId
6025 + " operator: " + operatorInfo);
6026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006031 }
shilu84f6e8b2019-12-19 13:58:01 -08006032 /**
6033 * Get the manual network selection
6034 *
6035 * @param subId the id of the subscription.
6036 *
6037 * @return the previously saved user selected PLMN
6038 */
6039 @Override
6040 public String getManualNetworkSelectionPlmn(int subId) {
6041 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006042 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006043 mApp, subId, "getManualNetworkSelectionPlmn");
6044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
6047 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006048 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006049 }
6050
6051 final Phone phone = getPhone(subId);
6052 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006053 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006054 }
6055 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6056 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6057 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
6061 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006062
6063 /**
6064 * Scans for available networks.
6065 */
6066 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006067 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6068 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6070 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006071 LocationAccessPolicy.LocationPermissionResult locationResult =
6072 LocationAccessPolicy.checkLocationPermission(mApp,
6073 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6074 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006075 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006076 .setCallingPid(Binder.getCallingPid())
6077 .setCallingUid(Binder.getCallingUid())
6078 .setMethod("getCellNetworkScanResults")
6079 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006080 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6081 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006082 .build());
6083 switch (locationResult) {
6084 case DENIED_HARD:
6085 throw new SecurityException("Not allowed to access scan results -- location");
6086 case DENIED_SOFT:
6087 return null;
6088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089
Pengquan Menga1bb6272018-09-06 09:59:22 -07006090 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 try {
6092 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006093 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006098 }
6099
6100 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006101 * Get the call forwarding info, given the call forwarding reason.
6102 */
6103 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006104 public void getCallForwarding(int subId, int callForwardingReason,
6105 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006106 enforceReadPrivilegedPermission("getCallForwarding");
6107 long identity = Binder.clearCallingIdentity();
6108 try {
6109 if (DBG) {
6110 log("getCallForwarding: subId " + subId
6111 + " callForwardingReason" + callForwardingReason);
6112 }
Hall Liu27d24262020-09-18 19:04:59 -07006113
6114 Phone phone = getPhone(subId);
6115 if (phone == null) {
6116 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006117 callback.onError(
6118 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006119 } catch (RemoteException e) {
6120 // ignore
6121 }
6122 return;
6123 }
6124
6125 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6126 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6127 @Override
6128 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6129 try {
6130 callback.onCallForwardingInfoAvailable(info);
6131 } catch (RemoteException e) {
6132 // ignore
6133 }
6134 }
6135
6136 @Override
6137 public void onError(int error) {
6138 try {
6139 callback.onError(error);
6140 } catch (RemoteException e) {
6141 // ignore
6142 }
6143 }
6144 });
6145 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148 }
6149 }
6150
6151 /**
6152 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6153 * reason, the number to forward, and the timeout before the forwarding is attempted.
6154 */
6155 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006156 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6157 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006158 enforceModifyPermission();
6159 long identity = Binder.clearCallingIdentity();
6160 try {
6161 if (DBG) {
6162 log("setCallForwarding: subId " + subId
6163 + " callForwardingInfo" + callForwardingInfo);
6164 }
Hall Liu27d24262020-09-18 19:04:59 -07006165
6166 Phone phone = getPhone(subId);
6167 if (phone == null) {
6168 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006169 callback.accept(
6170 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006171 } catch (RemoteException e) {
6172 // ignore
6173 }
6174 return;
6175 }
6176
6177 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6178 FunctionalUtils.ignoreRemoteException(callback::accept));
6179
6180 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006181 } finally {
6182 Binder.restoreCallingIdentity(identity);
6183 }
6184 }
6185
6186 /**
Hall Liu27d24262020-09-18 19:04:59 -07006187 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006188 */
6189 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006190 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006191 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006192 long identity = Binder.clearCallingIdentity();
6193 try {
Hall Liu27d24262020-09-18 19:04:59 -07006194 Phone phone = getPhone(subId);
6195 if (phone == null) {
6196 try {
6197 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6198 } catch (RemoteException e) {
6199 // ignore
6200 }
6201 return;
6202 }
SongFerngWang0e767992021-03-31 22:08:45 +08006203 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6204 PersistableBundle c = configManager.getConfigForSubId(subId);
6205 boolean requireUssd = c.getBoolean(
6206 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006207
Shuo Qian4a594052020-01-23 11:59:30 -08006208 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006209 if (requireUssd) {
6210 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6211 getSubscriptionCarrierId(subId));
6212 String newUssdCommand = "";
6213 try {
6214 newUssdCommand = carrierXmlParser.getFeature(
6215 CarrierXmlParser.FEATURE_CALL_WAITING)
6216 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6217 } catch (NullPointerException e) {
6218 loge("Failed to generate USSD number" + e);
6219 }
6220 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6221 mMainThreadHandler, callback, carrierXmlParser,
6222 CarrierXmlParser.SsEntry.SSAction.QUERY);
6223 final String ussdCommand = newUssdCommand;
6224 Executors.newSingleThreadExecutor().execute(() -> {
6225 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6226 });
6227 } else {
6228 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6229 callback::accept);
6230 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6231 }
Shuo Qian4a594052020-01-23 11:59:30 -08006232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 /**
Hall Liu27d24262020-09-18 19:04:59 -07006238 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006239 */
6240 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006241 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006242 enforceModifyPermission();
6243 long identity = Binder.clearCallingIdentity();
6244 try {
Hall Liu27d24262020-09-18 19:04:59 -07006245 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6246
6247 Phone phone = getPhone(subId);
6248 if (phone == null) {
6249 try {
6250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6251 } catch (RemoteException e) {
6252 // ignore
6253 }
6254 return;
6255 }
6256
SongFerngWang0e767992021-03-31 22:08:45 +08006257 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6258 PersistableBundle c = configManager.getConfigForSubId(subId);
6259 boolean requireUssd = c.getBoolean(
6260 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006261
SongFerngWang0e767992021-03-31 22:08:45 +08006262 if (DBG) log("getCallWaitingStatus: subId " + subId);
6263 if (requireUssd) {
6264 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6265 getSubscriptionCarrierId(subId));
6266 CarrierXmlParser.SsEntry.SSAction ssAction =
6267 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6268 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6269 String newUssdCommand = "";
6270 try {
6271 newUssdCommand = carrierXmlParser.getFeature(
6272 CarrierXmlParser.FEATURE_CALL_WAITING)
6273 .makeCommand(ssAction, null);
6274 } catch (NullPointerException e) {
6275 loge("Failed to generate USSD number" + e);
6276 }
6277 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6278 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6279 final String ussdCommand = newUssdCommand;
6280 Executors.newSingleThreadExecutor().execute(() -> {
6281 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6282 });
6283 } else {
6284 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6285 FunctionalUtils.ignoreRemoteException(callback::accept));
6286
6287 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6288 }
Shuo Qian4a594052020-01-23 11:59:30 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
6292 }
6293
6294 /**
yinxub1bed742017-04-17 11:45:04 -07006295 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006296 *
yinxub1bed742017-04-17 11:45:04 -07006297 * @param subId id of the subscription
6298 * @param request contains the radio access networks with bands/channels to scan
6299 * @param messenger callback messenger for scan results or errors
6300 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006301 * @return the id of the requested scan which can be used to stop the scan.
6302 */
6303 @Override
6304 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006305 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6307 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006308 LocationAccessPolicy.LocationPermissionResult locationResult =
6309 LocationAccessPolicy.checkLocationPermission(mApp,
6310 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6311 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006312 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006313 .setCallingPid(Binder.getCallingPid())
6314 .setCallingUid(Binder.getCallingUid())
6315 .setMethod("requestNetworkScan")
6316 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006317 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6318 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006319 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006320 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006321 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6322 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006323 if (e != null) {
6324 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6325 throw e;
6326 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006327 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006328 return TelephonyScanManager.INVALID_SCAN_ID;
6329 }
6330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 }
Hall Liu912dfd32019-04-25 14:02:26 -07006332 int callingUid = Binder.getCallingUid();
6333 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 return mNetworkScanRequestTracker.startNetworkScan(
6337 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006338 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
yinxu504e1392017-04-12 16:03:22 -07006342 }
6343
Hall Liub2ac8ef2019-02-28 15:56:23 -08006344 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006345 NetworkScanRequest request, int subId, String callingPackage) {
6346 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006347 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6348 boolean hasNetworkScanPermission =
6349 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6350 == PERMISSION_GRANTED;
6351
6352 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6353 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6354 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006355 }
6356
6357 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6358 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006359 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6360 return new SecurityException("Specific channels must not be"
6361 + " scanned without location access.");
6362 }
6363 }
6364 }
6365
Hall Liub2ac8ef2019-02-28 15:56:23 -08006366 return null;
6367 }
6368
yinxu504e1392017-04-12 16:03:22 -07006369 /**
6370 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006371 *
6372 * @param subId id of the subscription
6373 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006374 */
6375 @Override
6376 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6378 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379
Hall Liu912dfd32019-04-25 14:02:26 -07006380 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 final long identity = Binder.clearCallingIdentity();
6382 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006383 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
yinxu504e1392017-04-12 16:03:22 -07006387 }
6388
6389 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006390 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006391 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006392 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006393 */
6394 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006395 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006396 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006397 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006398 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006402 if (DBG) log("getAllowedNetworkTypesBitmask");
6403 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6404 int networkTypesBitmask = (result != null ? result[0] : -1);
6405 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6406 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006410 }
6411
6412 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006413 * Get the allowed network types for certain reason.
6414 *
6415 * @param subId the id of the subscription.
6416 * @param reason the reason the allowed network type change is taking place
6417 * @return the allowed network types.
6418 */
6419 @Override
6420 public long getAllowedNetworkTypesForReason(int subId,
6421 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006422 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006423 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006424 final long identity = Binder.clearCallingIdentity();
6425 try {
6426 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006433 * Enable/Disable E-UTRA-NR Dual Connectivity
6434 * @param subId subscription id of the sim card
6435 * @param nrDualConnectivityState expected NR dual connectivity state
6436 * This can be passed following states
6437 * <ol>
6438 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6439 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6440 * <li>Disable NR dual connectivity and force secondary cell to be released
6441 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6442 * </ol>
6443 * @return operation result.
6444 */
6445 @Override
6446 public int setNrDualConnectivityState(int subId,
6447 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6449 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006450 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006451 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6452 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6453 }
6454
Sooraj Sasindran37444802020-08-11 10:40:43 -07006455 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6456 final long identity = Binder.clearCallingIdentity();
6457 try {
6458 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6459 nrDualConnectivityState, subId,
6460 workSource);
6461 if (DBG) log("enableNRDualConnectivity result: " + result);
6462 return result;
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 /**
6469 * Is E-UTRA-NR Dual Connectivity enabled
6470 * @return true if dual connectivity is enabled else false
6471 */
6472 @Override
6473 public boolean isNrDualConnectivityEnabled(int subId) {
6474 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006475 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006476 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006477 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006478 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6479 return false;
6480 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6485 null, subId, workSource);
6486 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6487 return isEnabled;
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
6492
6493 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006494 * Set the allowed network types of the device and
6495 * provide the reason triggering the allowed network change.
6496 *
6497 * @param subId the id of the subscription.
6498 * @param reason the reason the allowed network type change is taking place
6499 * @param allowedNetworkTypes the allowed network types.
6500 * @return true on success; false on any failure.
6501 */
6502 @Override
6503 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006504 @TelephonyManager.AllowedNetworkTypesReason int reason,
6505 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6507 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006508 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006509 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6510 return false;
6511 }
6512 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6513 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006514 return false;
6515 }
6516
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006517 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6518 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6519
6520
6521 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6522 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6523 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006524 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006525
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006526 final long identity = Binder.clearCallingIdentity();
6527 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006528 Boolean success = (Boolean) sendRequest(
6529 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6530 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6531
6532 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6533 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
6537 }
6538
6539 /**
Miaoa84611c2019-03-15 09:21:10 +08006540 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006541 *
Miaoa84611c2019-03-15 09:21:10 +08006542 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006543 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006544 * @hide
6545 */
6546 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006547 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006550 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 try {
Miaoa84611c2019-03-15 09:21:10 +08006552 if (phone != null) {
6553 return phone.hasMatchedTetherApnSetting();
6554 } else {
6555 return false;
6556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006559 }
Junda Liu475951f2014-11-07 16:45:03 -08006560 }
6561
6562 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006563 * Get the user enabled state of Mobile Data.
6564 *
6565 * TODO: remove and use isUserDataEnabled.
6566 * This can't be removed now because some vendor codes
6567 * calls through ITelephony directly while they should
6568 * use TelephonyManager.
6569 *
6570 * @return true on enabled
6571 */
6572 @Override
6573 public boolean getDataEnabled(int subId) {
6574 return isUserDataEnabled(subId);
6575 }
6576
6577 /**
6578 * Get whether mobile data is enabled per user setting.
6579 *
6580 * There are other factors deciding whether mobile data is actually enabled, but they are
6581 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006582 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006583 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006584 *
6585 * @return {@code true} if data is enabled else {@code false}
6586 */
6587 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006588 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006589 try {
6590 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6591 null);
6592 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6594 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 int phoneId = mSubscriptionController.getPhoneId(subId);
6600 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6601 Phone phone = PhoneFactory.getPhone(phoneId);
6602 if (phone != null) {
6603 boolean retVal = phone.isUserDataEnabled();
6604 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6605 return retVal;
6606 } else {
6607 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6608 return false;
6609 }
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006612 }
6613 }
6614
6615 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006616 * Checks if the device is capable of mobile data by considering whether whether the
6617 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6618 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006619 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006620 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006621 */
6622 @Override
6623 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006624 try {
6625 try {
6626 mApp.enforceCallingOrSelfPermission(
6627 android.Manifest.permission.ACCESS_NETWORK_STATE,
6628 null);
6629 } catch (Exception e) {
6630 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6631 "isDataEnabled");
6632 }
6633 } catch (Exception e) {
6634 enforceReadPrivilegedPermission("isDataEnabled");
6635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 int phoneId = mSubscriptionController.getPhoneId(subId);
6640 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6641 Phone phone = PhoneFactory.getPhone(phoneId);
6642 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006643 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6645 return retVal;
6646 } else {
6647 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6648 return false;
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006652 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006653 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006654
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006655 /**
6656 * Check if data is enabled for a specific reason
6657 * @param subId Subscription index
6658 * @param reason the reason the data enable change is taking place
6659 * @return {@code true} if the overall data is enabled; {@code false} if not.
6660 */
6661 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006662 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006663 @TelephonyManager.DataEnabledReason int reason) {
6664 try {
6665 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6666 null);
6667 } catch (Exception e) {
6668 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006670 }
6671
6672
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 int phoneId = mSubscriptionController.getPhoneId(subId);
6676 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006677 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006678 + " reason=" + reason);
6679 }
6680 Phone phone = PhoneFactory.getPhone(phoneId);
6681 if (phone != null) {
6682 boolean retVal;
6683 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6684 retVal = phone.isUserDataEnabled();
6685 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006686 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006687 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006688 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006689 return retVal;
6690 } else {
6691 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006692 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006693 + subId + " retVal=false");
6694 }
6695 return false;
6696 }
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
6699 }
6700 }
6701
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006702 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006703 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006704 if (uid == Process.PHONE_UID) {
6705 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6706 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006707 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6708 }
6709
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006710 //load access rules from carrier configs, and check those as well: b/139133814
6711 SubscriptionController subController = SubscriptionController.getInstance();
6712 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6713 || subController == null) return privilegeFromSim;
6714
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006715 PackageManager pkgMgr = phone.getContext().getPackageManager();
6716 String[] packages = pkgMgr.getPackagesForUid(uid);
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006720 int subId = phone.getSubId();
6721 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6722 // A test override is in place for the privileges for this subId, so don't try to
6723 // read the subscription privileges.
6724 return privilegeFromSim;
6725 }
6726 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006727 SubscriptionManager subManager = (SubscriptionManager)
6728 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6729 for (String pkg : packages) {
6730 if (subManager.canManageSubscription(subInfo, pkg)) {
6731 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6732 }
6733 }
6734 return privilegeFromSim;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
6738 }
6739
6740 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6741 String pkgName) {
6742 //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
6747 final long identity = Binder.clearCallingIdentity();
6748 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006749 int subId = phone.getSubId();
6750 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6751 // A test override is in place for the privileges for this subId, so don't try to
6752 // read the subscription privileges.
6753 return privilegeFromSim;
6754 }
6755 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006756 SubscriptionManager subManager = (SubscriptionManager)
6757 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6758 return subManager.canManageSubscription(subInfo, pkgName)
6759 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
6763 }
6764
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006765 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006766 public int getCarrierPrivilegeStatus(int subId) {
6767 final Phone phone = getPhone(subId);
6768 if (phone == null) {
6769 loge("getCarrierPrivilegeStatus: Invalid subId");
6770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6771 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006772 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6773 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006774 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6776 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006777
6778 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006779 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006780 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006781 }
Junda Liu29340342014-07-10 15:23:27 -07006782
6783 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006784 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006785 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006786 final Phone phone = getPhone(subId);
6787 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006788 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6790 }
6791 UiccProfile profile =
6792 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6793 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006794 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6796 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006797 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006798 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006799 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006800 }
6801
6802 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006803 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006804 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006805 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006807 }
6808
6809 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006810 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6811 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006812 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6814 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006815 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006816 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006817 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006818 }
6819
6820 @Override
6821 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006822 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006823 if (TextUtils.isEmpty(pkgName))
6824 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006825 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6826 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006827 UiccPort port = UiccController.getInstance().getUiccPort(i);
6828 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006829 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006830 continue;
6831 }
6832
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006833 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006834 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006835 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006836 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6837 break;
6838 }
6839 }
6840
6841 return result;
Junda Liu29340342014-07-10 15:23:27 -07006842 }
Derek Tan89e89d42014-07-08 17:00:10 -07006843
6844 @Override
Junda Liue64de782015-04-16 17:19:16 -07006845 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006846 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006847 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6848 loge("phoneId " + phoneId + " is not valid.");
6849 return null;
6850 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006851 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6852 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006853 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006854 return null ;
6855 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006856 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006857 }
6858
Amith Yamasani6e118872016-02-19 12:53:51 -08006859 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006860 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006861 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006862 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006863 List<String> privilegedPackages = new ArrayList<>();
6864 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006865 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006866 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006867 if (port != null) {
6868 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006869 if (packages == null) {
6870 // Only check packages in user 0 for now
6871 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006872 PackageManager.MATCH_DISABLED_COMPONENTS
6873 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006874 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006875 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006876 }
6877 for (int p = packages.size() - 1; p >= 0; p--) {
6878 PackageInfo pkgInfo = packages.get(p);
6879 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006880 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006881 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006882 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006883 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006884 privilegedPackages.add(pkgInfo.packageName);
6885 }
6886 }
6887 }
6888 }
6889 return privilegedPackages;
6890 }
6891
chen xuf7e9fe82019-05-09 19:31:02 -07006892 @Override
6893 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006894 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6895
6896 final long identity = Binder.clearCallingIdentity();
6897
chen xuf7e9fe82019-05-09 19:31:02 -07006898 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006899 try {
6900 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6901 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6902 }
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006905 }
6906 return privilegedPackages;
6907 }
6908
Wink Savilleb564aae2014-10-23 10:18:09 -07006909 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006910 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006911 UiccPort port = phone == null ? null : phone.getUiccPort();
6912 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006913 return null;
6914 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006915 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006916 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006917 return null;
6918 }
6919 return iccId;
6920 }
6921
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006922 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006923 public void setCallComposerStatus(int subId, int status) {
6924 enforceModifyPermission();
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 Phone phone = getPhone(subId);
6929 if (phone != null) {
6930 Phone defaultPhone = phone.getImsPhone();
6931 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6932 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6933 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006934 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6935 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006936 }
6937 }
Shuo Qian284ae752020-12-22 19:10:14 -08006938 } catch (ImsException e) {
6939 throw new ServiceSpecificException(e.getCode());
6940 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006941 Binder.restoreCallingIdentity(identity);
6942 }
6943 }
6944
6945 @Override
6946 public int getCallComposerStatus(int subId) {
6947 enforceReadPrivilegedPermission("getCallComposerStatus");
6948
6949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 Phone phone = getPhone(subId);
6952 if (phone != null) {
6953 Phone defaultPhone = phone.getImsPhone();
6954 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6955 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6956 return imsPhone.getCallComposerStatus();
6957 }
6958 }
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
6962 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6963 }
6964
6965 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006966 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6967 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006968 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006969 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 final String iccId = getIccId(subId);
6974 final Phone phone = getPhone(subId);
6975 if (phone == null) {
6976 return false;
6977 }
6978 final String subscriberId = phone.getSubscriberId();
6979
6980 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006981 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 + subscriberId + " to " + number);
6983 }
6984
6985 if (TextUtils.isEmpty(iccId)) {
6986 return false;
6987 }
6988
6989 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6990
6991 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6992 if (alphaTag == null) {
6993 editor.remove(alphaTagPrefKey);
6994 } else {
6995 editor.putString(alphaTagPrefKey, alphaTag);
6996 }
6997
6998 // Record both the line number and IMSI for this ICCID, since we need to
6999 // track all merged IMSIs based on line number
7000 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7001 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7002 if (number == null) {
7003 editor.remove(numberPrefKey);
7004 editor.remove(subscriberPrefKey);
7005 } else {
7006 editor.putString(numberPrefKey, number);
7007 editor.putString(subscriberPrefKey, subscriberId);
7008 }
7009
7010 editor.commit();
7011 return true;
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007014 }
Derek Tan7226c842014-07-02 17:42:23 -07007015 }
7016
7017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007018 public String getLine1NumberForDisplay(int subId, String callingPackage,
7019 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007020 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007022 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007023 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007024 return null;
7025 }
Derek Tan97ebb422014-09-05 16:55:38 -07007026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 String iccId = getIccId(subId);
7030 if (iccId != null) {
7031 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7032 if (DBG_MERGE) {
7033 log("getLine1NumberForDisplay returning "
7034 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7035 }
7036 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7039 return null;
7040 } finally {
7041 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007042 }
Derek Tan7226c842014-07-02 17:42:23 -07007043 }
7044
7045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007046 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7047 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007049 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007050 return null;
7051 }
Derek Tan97ebb422014-09-05 16:55:38 -07007052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 String iccId = getIccId(subId);
7056 if (iccId != null) {
7057 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7058 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7059 }
7060 return null;
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007063 }
Derek Tan7226c842014-07-02 17:42:23 -07007064 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007065
7066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7068 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007069 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7070 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007072 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007073 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007074 return null;
7075 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007076
Jordan Liub49b04b2019-05-06 14:45:15 -07007077 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7078 // the process, where TelephonyManager was instantiated.
7079 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007080 final long identity = Binder.clearCallingIdentity();
7081 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 final TelephonyManager tele = TelephonyManager.from(context);
7084 final SubscriptionManager sub = SubscriptionManager.from(context);
7085
7086 // Figure out what subscribers are currently active
7087 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088
Jordan Liub49b04b2019-05-06 14:45:15 -07007089 // Only consider subs which match the current subId
7090 // This logic can be simplified. See b/131189269 for progress.
7091 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007092 activeSubscriberIds.add(tele.getSubscriberId(subId));
7093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094
7095 // First pass, find a number override for an active subscriber
7096 String mergeNumber = null;
7097 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7098 for (String key : prefs.keySet()) {
7099 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7100 final String subscriberId = (String) prefs.get(key);
7101 if (activeSubscriberIds.contains(subscriberId)) {
7102 final String iccId = key.substring(
7103 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7104 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7105 mergeNumber = (String) prefs.get(numberKey);
7106 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007107 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 + " for active subscriber " + subscriberId);
7109 }
7110 if (!TextUtils.isEmpty(mergeNumber)) {
7111 break;
7112 }
7113 }
7114 }
7115 }
7116
7117 // Shortcut when no active merged subscribers
7118 if (TextUtils.isEmpty(mergeNumber)) {
7119 return null;
7120 }
7121
7122 // Second pass, find all subscribers under that line override
7123 final ArraySet<String> result = new ArraySet<>();
7124 for (String key : prefs.keySet()) {
7125 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7126 final String number = (String) prefs.get(key);
7127 if (mergeNumber.equals(number)) {
7128 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7129 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7130 final String subscriberId = (String) prefs.get(subscriberKey);
7131 if (!TextUtils.isEmpty(subscriberId)) {
7132 result.add(subscriberId);
7133 }
7134 }
7135 }
7136 }
7137
7138 final String[] resultArray = result.toArray(new String[result.size()]);
7139 Arrays.sort(resultArray);
7140 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007141 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7143 }
7144 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007145 } finally {
7146 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007147 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007148 }
7149
7150 @Override
zoey chen38003472019-12-13 17:16:31 +08007151 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7152 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 final TelephonyManager telephonyManager = mApp.getSystemService(
7157 TelephonyManager.class);
7158 String subscriberId = telephonyManager.getSubscriberId(subId);
7159 if (subscriberId == null) {
7160 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007161 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007162 + subId);
7163 }
7164 return null;
7165 }
7166
7167 final SubscriptionInfo info = SubscriptionController.getInstance()
7168 .getSubscriptionInfo(subId);
7169 final ParcelUuid groupUuid = info.getGroupUuid();
7170 // If it doesn't belong to any group, return just subscriberId of itself.
7171 if (groupUuid == null) {
7172 return new String[]{subscriberId};
7173 }
7174
7175 // Get all subscriberIds from the group.
7176 final List<String> mergedSubscriberIds = new ArrayList<>();
7177 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007179 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007180 for (SubscriptionInfo subInfo : groupInfos) {
7181 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7182 if (subscriberId != null) {
7183 mergedSubscriberIds.add(subscriberId);
7184 }
7185 }
7186
7187 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190
7191 }
7192 }
7193
7194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007195 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007196 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007197 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 final Phone phone = getPhone(subId);
7202 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7203 } finally {
7204 Binder.restoreCallingIdentity(identity);
7205 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007206 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007207
7208 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007209 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007210 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7211 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007212 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7213 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 final Phone phone = getPhone(subId);
7218 if (phone == null) {
7219 return false;
7220 }
7221 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7222 cdmaNonRoamingList);
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007225 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007226 }
7227
7228 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007229 @Deprecated
7230 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7231 enforceModifyPermission();
7232
7233 int returnValue = 0;
7234 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007235 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007236 if(result.exception == null) {
7237 if (result.result != null) {
7238 byte[] responseData = (byte[])(result.result);
7239 if(responseData.length > oemResp.length) {
7240 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7241 responseData.length + "bytes. Buffer Size is " +
7242 oemResp.length + "bytes.");
7243 }
7244 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7245 returnValue = responseData.length;
7246 }
7247 } else {
7248 CommandException ex = (CommandException) result.exception;
7249 returnValue = ex.getCommandError().ordinal();
7250 if(returnValue > 0) returnValue *= -1;
7251 }
7252 } catch (RuntimeException e) {
7253 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7254 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7255 if(returnValue > 0) returnValue *= -1;
7256 }
7257
7258 return returnValue;
7259 }
7260
7261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007262 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007263 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007264 try {
7265 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007266 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007267 mApp, phone.getSubId(), "getRadioAccessFamily");
7268 } catch (SecurityException e) {
7269 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7270 throw e;
7271 }
chen xub97461a2018-10-26 14:17:57 -07007272 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007273 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007274 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276 final long identity = Binder.clearCallingIdentity();
7277 try {
chen xub97461a2018-10-26 14:17:57 -07007278 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007279 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007280 mApp, phone.getSubId(), "getRadioAccessFamily");
7281 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
chen xub97461a2018-10-26 14:17:57 -07007285 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007286 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007287
7288 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007289 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007290 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007291 try {
7292 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7293 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007294 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007295 }
7296 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007297 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007298 }
7299 RoleManager rm = mApp.getSystemService(RoleManager.class);
7300 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7301 if (!dialerRoleHolders.contains(callingPackage)) {
7302 throw new SecurityException("App must be the dialer role holder to"
7303 + " upload a call composer pic");
7304 }
7305
7306 Executors.newSingleThreadExecutor().execute(() -> {
7307 ByteArrayOutputStream output = new ByteArrayOutputStream(
7308 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7309 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7310 boolean readUntilEnd = false;
7311 int totalBytesRead = 0;
7312 byte[] buffer = new byte[16 * 1024];
7313 while (true) {
7314 int numRead;
7315 try {
7316 numRead = input.read(buffer);
7317 } catch (IOException e) {
7318 try {
7319 fd.checkError();
7320 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7321 null);
7322 } catch (IOException e1) {
7323 // This means that the other side closed explicitly with an error. If this
7324 // happens, log and ignore.
7325 loge("Remote end of call composer picture pipe closed: " + e1);
7326 }
7327 break;
7328 }
7329 if (numRead == -1) {
7330 readUntilEnd = true;
7331 break;
7332 }
7333 totalBytesRead += numRead;
7334 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7335 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7336 try {
7337 input.close();
7338 } catch (IOException e) {
7339 // ignore
7340 }
7341 break;
7342 }
7343 output.write(buffer, 0, numRead);
7344 }
7345 // Generally, the remote end will close the file descriptors. The only case where we
7346 // close is above, where the picture size is too big.
7347
7348 try {
7349 fd.checkError();
7350 } catch (IOException e) {
7351 loge("Remote end for call composer closed with an error: " + e);
7352 return;
7353 }
7354
Hall Liuaa4211e2021-01-20 15:43:39 -08007355 if (!readUntilEnd) {
7356 loge("Did not finish reading entire image; aborting");
7357 return;
7358 }
Hall Liu82694d52020-12-11 18:22:04 -08007359
Hall Liuaa4211e2021-01-20 15:43:39 -08007360 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7361 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7362 new CallComposerPictureTransfer.Factory() {},
7363 imageData,
7364 (result) -> {
7365 if (result.first != null) {
7366 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7367 Bundle outputResult = new Bundle();
7368 outputResult.putParcelable(
7369 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7370 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7371 outputResult);
7372 } else {
7373 callback.send(result.second, null);
7374 }
7375 }
7376 );
Hall Liu82694d52020-12-11 18:22:04 -08007377 });
7378 }
7379
7380 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007381 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007382 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007383 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007387 ImsManager.getInstance(defaultPhone.getContext(),
7388 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007392 }
7393
7394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007395 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007396 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7398 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007399 return false;
7400 }
Svet Ganovb320e182015-04-16 12:30:10 -07007401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 final long identity = Binder.clearCallingIdentity();
7403 try {
7404 // Check the user preference and the system-level IMS setting. Even if the user has
7405 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7406 // In the long run, we may instead need to check if there exists a connection service
7407 // which can support video calling.
7408 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007409 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 return imsManager.isVtEnabledByPlatform()
7411 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7412 && imsManager.isVtEnabledByUser();
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007416 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007417
Andrew Leea1239f22015-03-02 17:44:07 -08007418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007419 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7420 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007422 mApp, subId, callingPackage, callingFeatureId,
7423 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 return false;
7425 }
7426
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
7429 CarrierConfigManager configManager =
7430 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7433 } finally {
7434 Binder.restoreCallingIdentity(identity);
7435 }
Andrew Leea1239f22015-03-02 17:44:07 -08007436 }
7437
7438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007441 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 return false;
7443 }
7444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 CarrierConfigManager configManager =
7448 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
Andrew Leea1239f22015-03-02 17:44:07 -08007454 }
7455
Andrew Lee9431b832015-03-09 18:46:45 -07007456 @Override
7457 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007458 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007459 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007460 }
7461
7462 @Override
7463 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 final long identity = Binder.clearCallingIdentity();
7465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007466 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Andrew Lee9431b832015-03-09 18:46:45 -07007470 }
7471
Hall Liuf6668912018-10-31 17:05:23 -07007472 /**
7473 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7474 * support for the feature and device firmware support.
7475 *
7476 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7477 */
7478 @Override
7479 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007481 final Phone phone = getPhone(subscriptionId);
7482 if (phone == null) {
7483 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7484 return false;
7485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7489 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 return isCarrierSupported && isDeviceSupported;
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Hall Liu98187582018-01-22 19:15:32 -08007495 }
7496
Hall Liuf6668912018-10-31 17:05:23 -07007497 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007498 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7499 * RTT setting, will return true if the device and carrier both support RTT.
7500 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007501 */
7502 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007505 boolean isRttSupported = isRttSupported(subscriptionId);
7506 boolean isUserRttSettingOn = Settings.Secure.getInt(
7507 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7508 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7509 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7510 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 } finally {
7512 Binder.restoreCallingIdentity(identity);
7513 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007514 }
7515
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 @Deprecated
7517 @Override
7518 public String getDeviceId(String callingPackage) {
7519 return getDeviceIdWithFeature(callingPackage, null);
7520 }
7521
Sanket Padawe7310cc72015-01-14 09:53:20 -08007522 /**
7523 * Returns the unique device ID of phone, for example, the IMEI for
7524 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7525 *
7526 * <p>Requires Permission:
7527 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7528 */
7529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007531 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007532 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007533 return null;
7534 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007535 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007536 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007537 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007538 return null;
7539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540
7541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 return phone.getDeviceId();
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007547 }
7548
Ping Sunc67b7c22016-03-02 19:16:45 +08007549 /**
7550 * {@hide}
7551 * Returns the IMS Registration Status on a particular subid
7552 *
7553 * @param subId
7554 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007555 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007556 Phone phone = getPhone(subId);
7557 if (phone != null) {
7558 return phone.isImsRegistered();
7559 } else {
7560 return false;
7561 }
7562 }
7563
Santos Cordon7a1885b2015-02-03 11:15:19 -08007564 @Override
7565 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 final long identity = Binder.clearCallingIdentity();
7567 try {
7568 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007572 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007573
Tyler Gunnf70ed162019-04-03 15:28:53 -07007574 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007575 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007578 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007579 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7580 }
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
7588
7589 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007590 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007591 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007593 mApp,
7594 subscriptionId,
7595 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 Phone phone = getPhone(subscriptionId);
7599 if (phone == null) {
7600 return null;
7601 }
7602 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
7606 }
7607
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007608 /**
7609 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007610 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 Phone phone = getPhone(subId);
7615 if (phone != null) {
7616 return phone.isWifiCallingEnabled();
7617 } else {
7618 return false;
7619 }
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007622 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007623 }
7624
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007625 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007626 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007627 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007628 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 Phone phone = getPhone(subId);
7632 if (phone != null) {
7633 return phone.isVideoEnabled();
7634 } else {
7635 return false;
7636 }
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007639 }
7640 }
7641
7642 /**
7643 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7644 * defined in {@link ImsRegistrationImplBase}.
7645 */
7646 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 Phone phone = getPhone(subId);
7650 if (phone != null) {
7651 return phone.getImsRegistrationTech();
7652 } else {
7653 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7654 }
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007657 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007658 }
7659
Stuart Scott8eef64f2015-04-08 15:13:54 -07007660 @Override
7661 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007662 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007663 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7664 return;
7665 }
Kai Shif70f46f2021-03-03 13:59:46 -08007666 Phone defaultPhone = getDefaultPhone();
7667 if (defaultPhone != null) {
7668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7669 mApp, getDefaultPhone().getSubId(), "factoryReset");
7670 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007671 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007672
Svet Ganovcc087f82015-05-12 20:35:54 -07007673 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007674 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7675 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007676 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007677 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007678 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007679 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007680 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007681 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007682 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007683 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007684 // There has been issues when Sms raw table somehow stores orphan
7685 // fragments. They lead to garbled message when new fragments come
7686 // in and combined with those stale ones. In case this happens again,
7687 // user can reset all network settings which will clean up this table.
7688 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007689 // Clean up IMS settings as well here.
7690 int slotId = getSlotIndex(subId);
7691 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7692 ImsManager.getInstance(mApp, slotId).factoryReset();
7693 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007694
Kai Shif70f46f2021-03-03 13:59:46 -08007695 if (defaultPhone == null) {
7696 return;
7697 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007698 // Erase modem config if erase modem on network setting is enabled.
7699 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7700 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7701 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007702 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007703 }
Kai Shif70f46f2021-03-03 13:59:46 -08007704
7705 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007706 } finally {
7707 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007708 }
7709 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007710
SongFerngWangfd89b102021-05-27 22:44:54 +08007711 @VisibleForTesting
7712 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7713 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7714 return;
7715 }
7716 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7717 RILConstants.PREFERRED_NETWORK_MODE);
7718 SubscriptionManager.setSubscriptionProperty(subId,
7719 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7720 "user=" + defaultNetworkType);
7721 phone.loadAllowedNetworksFromSubscriptionDatabase();
7722 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7723 defaultNetworkType, null);
7724 }
7725
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007726 private void cleanUpSmsRawTable(Context context) {
7727 ContentResolver resolver = context.getContentResolver();
7728 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7729 resolver.delete(uri, null, null);
7730 }
7731
Narayan Kamath1c496c22015-04-16 14:40:19 +01007732 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007733 public String getSimLocaleForSubscriber(int subId) {
7734 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7735 final Phone phone = getPhone(subId);
7736 if (phone == null) {
7737 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007738 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
7741 try {
chen xu5d3637b2019-01-21 23:31:38 -08007742 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007743 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007744 if (info == null) {
7745 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7746 return null;
7747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 // Try and fetch the locale from the carrier properties or from the SIM language
7749 // preferences (EF-PL and EF-LI)...
7750 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007752 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7753 if (localeFromDefaultSim != null) {
7754 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7755 if (DBG) log("Using locale from subId: " + subId + " locale: "
7756 + localeFromDefaultSim);
7757 return localeFromDefaultSim.toLanguageTag();
7758 } else {
7759 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 }
7761 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 // The SIM language preferences only store a language (e.g. fr = French), not an
7764 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7765 // the SIM and carrier preferences does not include a country we add the country
7766 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007767 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007769 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 return mccLocale.toLanguageTag();
7771 }
7772
7773 if (DBG) log("No locale found - returning null");
7774 return null;
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007778 }
7779
7780 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007781 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007782 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007783 }
7784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 /**
7786 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7787 */
7788 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007789 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007790 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007791 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007792
Chenjie Yu1ba97252018-01-11 18:16:20 -08007793 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007794 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007795
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007796 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007797 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7798 * representing the state of the modem.
7799 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007800 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7801 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007802 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007803 */
7804 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007805 public void requestModemActivityInfo(ResultReceiver result) {
7806 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808
7809 final long identity = Binder.clearCallingIdentity();
7810 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007811 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 } finally {
7813 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007814 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007815 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007816
Siddharth Rayb8114062018-06-17 15:02:38 -07007817 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7818 // less than total activity duration.
7819 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7820 if (info == null) {
7821 return false;
7822 }
7823 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007824 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7825 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7826
Siddharth Rayb8114062018-06-17 15:02:38 -07007827 return (info.isValid()
7828 && (info.getSleepTimeMillis() <= activityDurationMs)
7829 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007830 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007831 && (totalTxTimeMs <= activityDurationMs));
7832 }
7833
Jack Yu85bd38a2015-11-09 11:34:32 -08007834 /**
7835 * {@hide}
7836 * Returns the service state information on specified subscription.
7837 */
7838 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007839 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7840 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007842 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007843 return null;
7844 }
7845
Hall Liuf19c44f2018-11-27 14:38:17 -08007846 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7847 LocationAccessPolicy.checkLocationPermission(mApp,
7848 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7849 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007850 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007851 .setCallingPid(Binder.getCallingPid())
7852 .setCallingUid(Binder.getCallingUid())
7853 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007854 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007855 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007856 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7857 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007858 .build());
7859
7860 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7861 LocationAccessPolicy.checkLocationPermission(mApp,
7862 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7863 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007864 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007865 .setCallingPid(Binder.getCallingPid())
7866 .setCallingUid(Binder.getCallingUid())
7867 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007868 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007869 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007870 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7871 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007872 .build());
7873 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7874 boolean hasFinePermission =
7875 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7876 boolean hasCoarsePermission =
7877 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7878
Jack Yu479f40e2020-10-27 21:29:25 -07007879 final Phone phone = getPhone(subId);
7880 if (phone == null) {
7881 return null;
7882 }
7883
Jordan Liu0f2bc442020-11-18 16:47:37 -08007884 final long identity = Binder.clearCallingIdentity();
7885
Jack Yu479f40e2020-10-27 21:29:25 -07007886 boolean isCallingPackageDataService = phone.getDataServicePackages()
7887 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007889 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7890 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7891 Rlog.d(LOG_TAG,
7892 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7893 return null;
7894 }
7895
Hall Liuf19c44f2018-11-27 14:38:17 -08007896 ServiceState ss = phone.getServiceState();
7897
7898 // Scrub out the location info in ServiceState depending on what level of access
7899 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007900 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007901 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7902 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007906 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007907
7908 /**
7909 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7910 *
7911 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7912 * voicemail ringtone.
7913 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7914 * PhoneAccount.
7915 */
7916 @Override
7917 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007918 final long identity = Binder.clearCallingIdentity();
7919 try {
7920 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7921 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007922 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7926 } finally {
7927 Binder.restoreCallingIdentity(identity);
7928 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007929 }
7930
7931 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007932 * Sets the per-account voicemail ringtone.
7933 *
7934 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7935 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7936 *
7937 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7938 * voicemail ringtone.
7939 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7940 * PhoneAccount.
7941 */
7942 @Override
7943 public void setVoicemailRingtoneUri(String callingPackage,
7944 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007945 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007947 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7948 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7950 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7951 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953
7954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7957 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007958 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 }
7960 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7961 } finally {
7962 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007963 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007964 }
7965
7966 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967 * Returns whether vibration is set for voicemail notification in Phone settings.
7968 *
7969 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7970 * voicemail vibration setting.
7971 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7972 */
7973 @Override
7974 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7978 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007979 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7983 } finally {
7984 Binder.restoreCallingIdentity(identity);
7985 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007986 }
7987
Youhan Wange64578a2016-05-02 15:32:42 -07007988 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007989 * Sets the per-account voicemail vibration.
7990 *
7991 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7992 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7993 *
7994 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7995 * voicemail vibration setting.
7996 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7997 * specific PhoneAccount.
7998 */
7999 @Override
8000 public void setVoicemailVibrationEnabled(String callingPackage,
8001 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008003 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008004 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8005 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8007 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8008 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 }
8010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8014 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008015 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 }
8017 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008020 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008021 }
8022
8023 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008024 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8025 *
8026 * @throws SecurityException if the caller does not have the required permission
8027 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008028 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008029 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008030 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008031 }
8032
8033 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008034 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8035 * permission.
8036 *
8037 * @throws SecurityException if the caller does not have the required permission
8038 */
8039 private void enforceSendSmsPermission() {
8040 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8041 }
8042
8043 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008044 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008045 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008046 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008047 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008048 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008052 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 if (componentName == null) {
8054 throw new SecurityException(
8055 "Caller not current active visual voicemail package[null]");
8056 }
8057 String vvmPackage = componentName.getPackageName();
8058 if (!callingPackage.equals(vvmPackage)) {
8059 throw new SecurityException("Caller not current active visual voicemail package["
8060 + vvmPackage + "]");
8061 }
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008064 }
8065 }
8066
8067 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008068 * Return the application ID for the app type.
8069 *
8070 * @param subId the subscription ID that this request applies to.
8071 * @param appType the uicc app type.
8072 * @return Application ID for specificied app type, or null if no uicc.
8073 */
8074 @Override
8075 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008076 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008077 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078
8079 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008080 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 if (phone == null) {
8082 return null;
8083 }
8084 String aid = null;
8085 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008086 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 .getApplicationByType(appType).getAid();
8088 } catch (Exception e) {
8089 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8090 }
8091 return aid;
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008094 }
Youhan Wange64578a2016-05-02 15:32:42 -07008095 }
8096
Youhan Wang4001d252016-05-11 10:29:41 -07008097 /**
8098 * Return the Electronic Serial Number.
8099 *
8100 * @param subId the subscription ID that this request applies to.
8101 * @return ESN or null if error.
8102 */
8103 @Override
8104 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008105 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008106 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107
8108 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008109 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 if (phone == null) {
8111 return null;
8112 }
8113 String esn = null;
8114 try {
8115 esn = phone.getEsn();
8116 } catch (Exception e) {
8117 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8118 }
8119 return esn;
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008122 }
Youhan Wang4001d252016-05-11 10:29:41 -07008123 }
8124
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008125 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008126 * Return the Preferred Roaming List Version.
8127 *
8128 * @param subId the subscription ID that this request applies to.
8129 * @return PRLVersion or null if error.
8130 */
8131 @Override
8132 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008133 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008134 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135
8136 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008137 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 if (phone == null) {
8139 return null;
8140 }
8141 String cdmaPrlVersion = null;
8142 try {
8143 cdmaPrlVersion = phone.getCdmaPrlVersion();
8144 } catch (Exception e) {
8145 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8146 }
8147 return cdmaPrlVersion;
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008150 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008151 }
8152
8153 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008154 * Get snapshot of Telephony histograms
8155 * @return List of Telephony histograms
8156 * @hide
8157 */
8158 @Override
8159 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8161 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162
8163 final long identity = Binder.clearCallingIdentity();
8164 try {
8165 return RIL.getTelephonyRILTimingHistograms();
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008169 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008170
8171 /**
8172 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008173 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8174 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008175 * Require system privileges. In the future we may add this to carrier APIs.
8176 *
Michele Berionne482f8202018-11-27 18:57:59 -08008177 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178 */
8179 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008180 @TelephonyManager.SetCarrierRestrictionResult
8181 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008182 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008184
Michele Berionne482f8202018-11-27 18:57:59 -08008185 if (carrierRestrictionRules == null) {
8186 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008187 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 final long identity = Binder.clearCallingIdentity();
8190 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008191 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008192 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 } finally {
8194 Binder.restoreCallingIdentity(identity);
8195 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008196 }
8197
8198 /**
8199 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008200 * Get the allowed carrier list and the excluded carrier list, including the priority between
8201 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008202 * Require system privileges. In the future we may add this to carrier APIs.
8203 *
Michele Berionne482f8202018-11-27 18:57:59 -08008204 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008205 */
8206 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008207 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008208 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210
8211 final long identity = Binder.clearCallingIdentity();
8212 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008213 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8214 if (response instanceof CarrierRestrictionRules) {
8215 return (CarrierRestrictionRules) response;
8216 }
8217 // Response is an Exception of some kind,
8218 // which is signalled to the user as a NULL retval
8219 return null;
8220 } catch (Exception e) {
8221 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8222 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 } finally {
8224 Binder.restoreCallingIdentity(identity);
8225 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226 }
8227
fionaxu59545b42016-05-25 15:53:37 -07008228 /**
fionaxu59545b42016-05-25 15:53:37 -07008229 * Action set from carrier signalling broadcast receivers to enable/disable radio
8230 * @param subId the subscription ID that this action applies to.
8231 * @param enabled control enable or disable radio.
8232 * {@hide}
8233 */
8234 @Override
8235 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8236 enforceModifyPermission();
8237 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238
8239 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008240 if (phone == null) {
8241 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8242 return;
8243 }
8244 try {
8245 phone.carrierActionSetRadioEnabled(enabled);
8246 } catch (Exception e) {
8247 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 } finally {
8249 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008250 }
8251 }
8252
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008253 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008254 * Enable or disable Voice over NR (VoNR)
8255 * @param subId the subscription ID that this action applies to.
8256 * @param enabled enable or disable VoNR.
8257 * @return operation result.
8258 */
8259 @Override
8260 public int setVoNrEnabled(int subId, boolean enabled) {
8261 enforceModifyPermission();
8262 final Phone phone = getPhone(subId);
8263
8264 final long identity = Binder.clearCallingIdentity();
8265 if (phone == null) {
8266 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8267 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8268 }
8269
8270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8271 try {
8272 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8273 workSource);
8274 if (DBG) log("setVoNrEnabled result: " + result);
8275 return result;
8276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
8279 }
8280
8281 /**
8282 * Is voice over NR enabled
8283 * @return true if VoNR is enabled else false
8284 */
8285 @Override
8286 public boolean isVoNrEnabled(int subId) {
8287 enforceReadPrivilegedPermission("isVoNrEnabled");
8288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8289 final long identity = Binder.clearCallingIdentity();
8290 try {
8291 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8292 null, subId, workSource);
8293 if (DBG) log("isVoNrEnabled: " + isEnabled);
8294 return isEnabled;
8295 } finally {
8296 Binder.restoreCallingIdentity(identity);
8297 }
8298 }
8299
8300 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008301 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8302 * network status based on which carrier apps could apply actions accordingly,
8303 * enable/disable default url handler for example.
8304 *
8305 * @param subId the subscription ID that this action applies to.
8306 * @param report control start/stop reporting the default network status.
8307 * {@hide}
8308 */
8309 @Override
8310 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8311 enforceModifyPermission();
8312 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313
8314 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008315 if (phone == null) {
8316 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8317 return;
8318 }
8319 try {
8320 phone.carrierActionReportDefaultNetworkStatus(report);
8321 } catch (Exception e) {
8322 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 } finally {
8324 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008325 }
8326 }
8327
8328 /**
fionaxud9622282017-07-17 17:51:30 -07008329 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8330 * @param subId the subscription ID that this action applies to.
8331 * {@hide}
8332 */
8333 @Override
8334 public void carrierActionResetAll(int subId) {
8335 enforceModifyPermission();
8336 final Phone phone = getPhone(subId);
8337 if (phone == null) {
8338 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8339 return;
8340 }
8341 try {
8342 phone.carrierActionResetAll();
8343 } catch (Exception e) {
8344 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8345 }
8346 }
8347
8348 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008349 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8350 * bug report is being generated.
8351 */
8352 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008353 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008354 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8355 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008356 writer.println("Permission Denial: can't dump Phone from pid="
8357 + Binder.getCallingPid()
8358 + ", uid=" + Binder.getCallingUid()
8359 + "without permission "
8360 + android.Manifest.permission.DUMP);
8361 return;
8362 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008363 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008364 }
Jack Yueb89b242016-06-22 13:27:47 -07008365
Brad Ebingerdac2f002018-04-03 15:17:52 -07008366 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008367 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8368 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8369 @NonNull String[] args) {
8370 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8371 this, in.getFileDescriptor(), out.getFileDescriptor(),
8372 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008373 }
8374
Jack Yueb89b242016-06-22 13:27:47 -07008375 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008376 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008377 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008378 * @param reason the reason the data enable change is taking place
8379 * @param enabled True if enabling the data, otherwise disabling.
8380 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008381 */
8382 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008383 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008384 boolean enabled) {
8385 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8386 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8387 try {
8388 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008389 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008390 } catch (SecurityException se) {
8391 enforceModifyPermission();
8392 }
8393 } else {
8394 enforceModifyPermission();
8395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396
8397 final long identity = Binder.clearCallingIdentity();
8398 try {
8399 Phone phone = getPhone(subId);
8400 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008401 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8402 phone.carrierActionSetMeteredApnsEnabled(enabled);
8403 } else {
8404 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 }
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008409 }
8410 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008411
8412 /**
8413 * Get Client request stats
8414 * @return List of Client Request Stats
8415 * @hide
8416 */
8417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008418 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8419 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008421 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008422 return null;
8423 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008424 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426 final long identity = Binder.clearCallingIdentity();
8427 try {
8428 if (phone != null) {
8429 return phone.getClientRequestStats();
8430 }
8431
8432 return null;
8433 } finally {
8434 Binder.restoreCallingIdentity(identity);
8435 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008436 }
8437
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008438 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008439 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008440 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008441 }
Jack Yueb4124c2017-02-16 15:32:43 -08008442
8443 /**
Grace Chen70990072017-03-24 17:21:30 -07008444 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008445 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008446 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008447 * @param state State of SIM (power down, power up, pass through)
8448 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8449 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8450 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008451 *
8452 **/
8453 @Override
Grace Chen70990072017-03-24 17:21:30 -07008454 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008455 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008456 Phone phone = PhoneFactory.getPhone(slotIndex);
8457
vagdeviaf9a5b92018-08-15 16:01:53 -07008458 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008463 phone.setSimPowerState(state, null, workSource);
8464 }
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 }
8469
8470 /**
8471 * Set SIM card power state.
8472 *
8473 * @param slotIndex SIM slot id.
8474 * @param state State of SIM (power down, power up, pass through)
8475 * @param callback callback to trigger after success or failure
8476 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8477 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8478 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8479 *
8480 **/
8481 @Override
8482 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8483 IIntegerConsumer callback) {
8484 enforceModifyPermission();
8485 Phone phone = PhoneFactory.getPhone(slotIndex);
8486
8487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8488
8489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 if (phone != null) {
8492 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8493 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 }
8495 } finally {
8496 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008497 }
8498 }
Shuo Qiandd210312017-04-12 22:11:33 +00008499
Tyler Gunn65d45c22017-06-05 11:22:26 -07008500 private boolean isUssdApiAllowed(int subId) {
8501 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008502 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008503 if (configManager == null) {
8504 return false;
8505 }
8506 PersistableBundle pb = configManager.getConfigForSubId(subId);
8507 if (pb == null) {
8508 return false;
8509 }
8510 return pb.getBoolean(
8511 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8512 }
8513
Shuo Qiandd210312017-04-12 22:11:33 +00008514 /**
8515 * Check if phone is in emergency callback mode
8516 * @return true if phone is in emergency callback mode
8517 * @param subId sub id
8518 */
goneil9c5f4872017-12-05 14:07:56 -08008519 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008520 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008521 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008522 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523
8524 final long identity = Binder.clearCallingIdentity();
8525 try {
8526 if (phone != null) {
8527 return phone.isInEcm();
8528 } else {
8529 return false;
8530 }
8531 } finally {
8532 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008533 }
8534 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008535
8536 /**
8537 * Get the current signal strength information for the given subscription.
8538 * Because this information is not updated when the device is in a low power state
8539 * it should not be relied-upon to be current.
8540 * @param subId Subscription index
8541 * @return the most recent cached signal strength info from the modem
8542 */
8543 @Override
8544 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545 final long identity = Binder.clearCallingIdentity();
8546 try {
8547 Phone p = getPhone(subId);
8548 if (p == null) {
8549 return null;
8550 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008552 return p.getSignalStrength();
8553 } finally {
8554 Binder.restoreCallingIdentity(identity);
8555 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008556 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008557
Pengquan Meng77b7f132018-08-22 14:49:57 -07008558 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008559 * Get the current modem radio state for the given slot.
8560 * @param slotIndex slot index.
8561 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008562 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008563 * @return the current radio power state from the modem
8564 */
8565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008566 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008567 Phone phone = PhoneFactory.getPhone(slotIndex);
8568 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8570 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008571 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8572 }
8573
8574 final long identity = Binder.clearCallingIdentity();
8575 try {
8576 return phone.getRadioPowerState();
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
8580 }
8581 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8582 }
8583
8584 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008585 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8586 *
8587 * <p>Requires one of the following permissions:
8588 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8589 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8590 * privileges.
8591 *
8592 * @param subId subscription id
8593 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8594 * {@code false}.
8595 */
8596 @Override
8597 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008598 try {
8599 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8600 null);
8601 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008602 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008603 mApp, subId, "isDataRoamingEnabled");
8604 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008605
Pengquan Menga1bb6272018-09-06 09:59:22 -07008606 boolean isEnabled = false;
8607 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008608 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008609 Phone phone = getPhone(subId);
8610 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008611 } finally {
8612 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008613 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008614 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008615 }
8616
8617
8618 /**
8619 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8620 *
8621 * <p> Requires permission:
8622 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8623 * privileges.
8624 *
8625 * @param subId subscription id
8626 * @param isEnabled {@code true} means enable, {@code false} means disable.
8627 */
8628 @Override
8629 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8631 mApp, subId, "setDataRoamingEnabled");
8632
Pengquan Menga1bb6272018-09-06 09:59:22 -07008633 final long identity = Binder.clearCallingIdentity();
8634 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008635 Phone phone = getPhone(subId);
8636 if (phone != null) {
8637 phone.setDataRoamingEnabled(isEnabled);
8638 }
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008641 }
8642 }
8643
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008644 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008645 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008646 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008648 mApp, subId, "isManualNetworkSelectionAllowed");
8649
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008650 boolean isAllowed = true;
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008653 Phone phone = getPhone(subId);
8654 if (phone != null) {
8655 isAllowed = phone.isCspPlmnEnabled();
8656 }
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 return isAllowed;
8661 }
8662
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008663 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8664 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8665 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8666 // Update each UiccPort object based on privilege access
8667 UiccPort[] uiccPorts = card.getUiccPortList();
8668 for (UiccPort port : uiccPorts) {
8669 UiccProfile profile = port.getUiccProfile();
8670 if (profile == null ||
8671 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8672 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8673 return false;
8674 }
8675 }
8676 return true;
8677 }
8678
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008679 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008680 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008681 // Verify that tha callingPackage belongs to the calling UID
8682 mApp.getSystemService(AppOpsManager.class)
8683 .checkPackage(Binder.getCallingUid(), callingPackage);
8684
Jordan Liu1e142fc2019-04-22 15:10:43 -07008685 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008686 try {
8687 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008688 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008689 } catch (SecurityException e) {
8690 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8691 // has carrier privileges on an active UICC
8692 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8693 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008694 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008695 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008696 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008697
8698 final long identity = Binder.clearCallingIdentity();
8699 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008700 UiccController uiccController = UiccController.getInstance();
8701 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008702 if (hasReadPermission) {
8703 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008704 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008705
8706 // Remove private info if the caller doesn't have access
8707 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8708 for (UiccCardInfo cardInfo : cardInfos) {
8709 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8710 // is available
8711 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008712 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8713 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8714 if (card == null || card.getUiccPortList().length == 0) {
8715 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008716 filteredInfos.add(cardInfo.getUnprivileged());
8717 continue;
8718 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008719
8720 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 filteredInfos.add(cardInfo);
8722 } else {
8723 filteredInfos.add(cardInfo.getUnprivileged());
8724 }
8725 }
8726 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008727 } finally {
8728 Binder.restoreCallingIdentity(identity);
8729 }
8730 }
8731
8732 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008733 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008734 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008736 final long identity = Binder.clearCallingIdentity();
8737 try {
8738 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8739 if (slots == null) {
8740 Rlog.i(LOG_TAG, "slots is null.");
8741 return null;
8742 }
8743
8744 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8745 for (int i = 0; i < slots.length; i++) {
8746 UiccSlot slot = slots[i];
8747 if (slot == null) {
8748 continue;
8749 }
8750
Jordan Liu7be7e652019-05-06 18:55:02 +00008751 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752 UiccCard card = slot.getUiccCard();
8753 if (card != null) {
8754 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008755 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008756 cardId = slot.getEid();
8757 if (TextUtils.isEmpty(cardId)) {
8758 cardId = slot.getIccId();
8759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008760 }
8761
Jordan Liu857451f2019-05-09 16:35:35 -07008762 if (cardId != null) {
8763 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8764 // if cardId is an EID, it's all digits so this is fine
8765 cardId = IccUtils.stripTrailingFs(cardId);
8766 }
8767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008768 int cardState = 0;
8769 switch (slot.getCardState()) {
8770 case CARDSTATE_ABSENT:
8771 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8772 break;
8773 case CARDSTATE_PRESENT:
8774 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8775 break;
8776 case CARDSTATE_ERROR:
8777 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8778 break;
8779 case CARDSTATE_RESTRICTED:
8780 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8781 break;
8782 default:
8783 break;
8784
8785 }
8786
8787 infos[i] = new UiccSlotInfo(
8788 slot.isActive(),
8789 slot.isEuicc(),
8790 cardId,
8791 cardState,
8792 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008793 slot.isExtendedApduSupported(),
8794 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008795 }
8796 return infos;
8797 } finally {
8798 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008799 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008800 }
8801
8802 @Override
8803 public boolean switchSlots(int[] physicalSlots) {
8804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008805
8806 final long identity = Binder.clearCallingIdentity();
8807 try {
8808 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8809 } finally {
8810 Binder.restoreCallingIdentity(identity);
8811 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008812 }
Jack Yu4c988042018-02-27 15:30:01 -08008813
8814 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008815 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008816 final long identity = Binder.clearCallingIdentity();
8817 try {
8818 return UiccController.getInstance().getCardIdForDefaultEuicc();
8819 } finally {
8820 Binder.restoreCallingIdentity(identity);
8821 }
8822 }
8823
Pengquan Meng85728fb2018-03-12 16:31:21 -07008824 /**
goneil47ffb6e2018-04-06 15:40:58 -07008825 * A test API to reload the UICC profile.
8826 *
8827 * <p>Requires that the calling app has permission
8828 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8829 * @hide
8830 */
8831 @Override
8832 public void refreshUiccProfile(int subId) {
8833 enforceModifyPermission();
8834
8835 final long identity = Binder.clearCallingIdentity();
8836 try {
8837 Phone phone = getPhone(subId);
8838 if (phone == null) {
8839 return;
8840 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008841 UiccPort uiccPort = phone.getUiccPort();
8842 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008843 return;
8844 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008845 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008846 if (uiccProfile == null) {
8847 return;
8848 }
8849 uiccProfile.refresh();
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
8852 }
8853 }
8854
8855 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008856 * Returns false if the mobile data is disabled by default, otherwise return true.
8857 */
8858 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008859 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008860 }
8861
8862 /**
8863 * Returns true if the data roaming is enabled by default, i.e the system property
8864 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8865 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8866 */
8867 private boolean getDefaultDataRoamingEnabled(int subId) {
8868 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008869 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008870 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008871 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8872 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8873 return isDataRoamingEnabled;
8874 }
8875
8876 /**
8877 * Returns the default network type for the given {@code subId}, if the default network type is
8878 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8879 */
8880 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008881 List<Integer> list = TelephonyProperties.default_network();
8882 int phoneId = mSubscriptionController.getPhoneId(subId);
8883 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8884 return list.get(phoneId);
8885 }
8886 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008887 }
fionaxua13278b2018-03-21 00:08:13 -07008888
8889 @Override
8890 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008891 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893
8894 final long identity = Binder.clearCallingIdentity();
8895 try {
8896 final Phone phone = getPhone(subId);
8897 if (phone == null) {
8898 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8899 return;
8900 }
chen xueaba88a2019-03-15 13:15:10 -07008901 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8902 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008903 if (carrierPrivilegeRules == null) {
8904 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8905 } else {
8906 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 } finally {
8909 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008910 }
fionaxua13278b2018-03-21 00:08:13 -07008911 }
8912
8913 @Override
8914 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008915 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916
8917 final long identity = Binder.clearCallingIdentity();
8918 try {
8919 final Phone phone = getPhone(subId);
8920 if (phone == null) {
8921 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8922 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8923 }
8924 return phone.getCarrierIdListVersion();
8925 } finally {
8926 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008927 }
fionaxua13278b2018-03-21 00:08:13 -07008928 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008929
8930 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008931 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8932 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008934 mApp, subId, callingPackage, callingFeatureId,
8935 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008936 return -1;
8937 }
8938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008946
8947 @Override
8948 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008949 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008950 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008951 mApp, subId, "getCdmaRoamingMode");
8952
8953 final long identity = Binder.clearCallingIdentity();
8954 try {
8955 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8956 } finally {
8957 Binder.restoreCallingIdentity(identity);
8958 }
8959 }
8960
8961 @Override
8962 public boolean setCdmaRoamingMode(int subId, int mode) {
8963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8964 mApp, subId, "setCdmaRoamingMode");
8965
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8969 } finally {
8970 Binder.restoreCallingIdentity(identity);
8971 }
8972 }
8973
8974 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008975 public int getCdmaSubscriptionMode(int subId) {
8976 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008977 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008978 mApp, subId, "getCdmaSubscriptionMode");
8979
8980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
8988 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008989 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8991 mApp, subId, "setCdmaSubscriptionMode");
8992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009000
sqianc5eccab2018-10-19 18:46:41 -07009001 @Override
sqian8c685422019-02-22 15:55:18 -08009002 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009003 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009005 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9006 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009007 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9008 }
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
sqian854d44b2018-12-12 16:48:18 -08009011 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9012 for (Phone phone: PhoneFactory.getPhones()) {
9013 if (phone.getEmergencyNumberTracker() != null
9014 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9015 emergencyNumberListInternal.put(
9016 phone.getSubId(),
9017 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9018 }
sqian11b7a0e2018-12-05 18:48:28 -08009019 }
sqian854d44b2018-12-12 16:48:18 -08009020 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
sqianc5eccab2018-10-19 18:46:41 -07009024 }
9025
9026 @Override
sqian8c685422019-02-22 15:55:18 -08009027 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009028 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009029 if (!exactMatch) {
9030 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009031 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009032 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009033 }
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
sqian854d44b2018-12-12 16:48:18 -08009036 for (Phone phone: PhoneFactory.getPhones()) {
9037 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009038 && phone.getEmergencyNumberTracker()
9039 .isEmergencyNumber(number, exactMatch)) {
9040 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009041 }
sqian11b7a0e2018-12-05 18:48:28 -08009042 }
9043 return false;
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
9047 }
9048
sqianf4ca7ed2019-01-15 18:32:07 -08009049 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009050 * Start emergency callback mode for GsmCdmaPhone for testing.
9051 */
9052 @Override
9053 public void startEmergencyCallbackMode() {
9054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9055 "startEmergencyCallbackMode");
9056 enforceModifyPermission();
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 for (Phone phone : PhoneFactory.getPhones()) {
9060 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9061 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9062 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9063 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9064 gsmCdmaPhone.obtainMessage(
9065 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9066 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9067 }
9068 }
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
9074 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009075 * Update emergency number list for test mode.
9076 */
9077 @Override
9078 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9080 "updateEmergencyNumberListTestMode");
9081
9082 final long identity = Binder.clearCallingIdentity();
9083 try {
9084 for (Phone phone: PhoneFactory.getPhones()) {
9085 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9086 if (tracker != null) {
9087 tracker.executeEmergencyNumberTestModeCommand(action, num);
9088 }
9089 }
9090 } finally {
9091 Binder.restoreCallingIdentity(identity);
9092 }
9093 }
9094
9095 /**
9096 * Get the full emergency number list for test mode.
9097 */
9098 @Override
9099 public List<String> getEmergencyNumberListTestMode() {
9100 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9101 "getEmergencyNumberListTestMode");
9102
9103 final long identity = Binder.clearCallingIdentity();
9104 try {
9105 Set<String> emergencyNumbers = new HashSet<>();
9106 for (Phone phone: PhoneFactory.getPhones()) {
9107 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9108 if (tracker != null) {
9109 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9110 emergencyNumbers.add(num.getNumber());
9111 }
9112 }
9113 }
9114 return new ArrayList<>(emergencyNumbers);
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
9117 }
9118 }
9119
chen xud6b45bd2018-10-30 22:27:10 -07009120 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009121 public int getEmergencyNumberDbVersion(int subId) {
9122 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9123
9124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 final Phone phone = getPhone(subId);
9127 if (phone == null) {
9128 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9129 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9130 }
9131 return phone.getEmergencyNumberDbVersion();
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @Override
9138 public void notifyOtaEmergencyNumberDbInstalled() {
9139 enforceModifyPermission();
9140
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
9143 for (Phone phone: PhoneFactory.getPhones()) {
9144 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9145 if (tracker != null) {
9146 tracker.updateOtaEmergencyNumberDatabase();
9147 }
9148 }
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
9153
9154 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009155 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009156 enforceActiveEmergencySessionPermission();
9157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 for (Phone phone: PhoneFactory.getPhones()) {
9161 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9162 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009163 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9164 }
9165 }
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
9170
9171 @Override
9172 public void resetOtaEmergencyNumberDbFilePath() {
9173 enforceActiveEmergencySessionPermission();
9174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 for (Phone phone: PhoneFactory.getPhones()) {
9178 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9179 if (tracker != null) {
9180 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009181 }
9182 }
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
9188 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009189 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9190 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9191 Phone phone = getPhone(subId);
9192 if (phone == null) {
9193 return null;
9194 }
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 UiccProfile profile = UiccController.getInstance()
9198 .getUiccProfileForPhone(phone.getPhoneId());
9199 if (profile != null) {
9200 return profile.getCertsFromCarrierPrivilegeAccessRules();
9201 }
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 return null;
9206 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009207
9208 /**
9209 * Enable or disable a modem stack.
9210 */
9211 @Override
9212 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9213 enforceModifyPermission();
9214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
9217 Phone phone = PhoneFactory.getPhone(slotIndex);
9218 if (phone == null) {
9219 return false;
9220 } else {
9221 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9222 }
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
9226 }
Michelecea4cf22018-12-21 15:00:11 -08009227
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009228 /**
9229 * Whether a modem stack is enabled or not.
9230 */
9231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009232 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9233 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009234 Phone phone = PhoneFactory.getPhone(slotIndex);
9235 if (phone == null) return false;
9236
9237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009238 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9239 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009240 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9241 }
9242
9243 final long identity = Binder.clearCallingIdentity();
9244 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009245 try {
9246 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9247 } catch (NoSuchElementException ex) {
9248 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9249 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
9253 }
9254
Michelecea4cf22018-12-21 15:00:11 -08009255 @Override
Michele0ea7d782019-03-19 14:58:42 -07009256 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009257 enforceModifyPermission();
9258
9259 final long identity = Binder.clearCallingIdentity();
9260 try {
9261 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009262 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009263 .commit();
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
9268
9269 @Override
Michele0ea7d782019-03-19 14:58:42 -07009270 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009271 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009273 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9274 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009275 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009276 }
Michelecea4cf22018-12-21 15:00:11 -08009277
9278 final long identity = Binder.clearCallingIdentity();
9279 try {
Michele0ea7d782019-03-19 14:58:42 -07009280 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009285
Michele0ea7d782019-03-19 14:58:42 -07009286 @TelephonyManager.IsMultiSimSupportedResult
9287 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009288 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9289 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9290 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009291 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9292 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009293 }
9294 // Check if the hardware supports multisim functionality. If usage of multisim is not
9295 // supported by the modem, indicate that it is restricted.
9296 PhoneCapability staticCapability =
9297 mPhoneConfigurationManager.getStaticPhoneCapability();
9298 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009299 loge("isMultiSimSupportedInternal: no static configuration available");
9300 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009301 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009302 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009303 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9304 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009305 }
9306 // Check if support of multiple SIMs is restricted by carrier
9307 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009308 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009309 }
9310
Michele0ea7d782019-03-19 14:58:42 -07009311 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009312 }
9313
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009314 /**
9315 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009316 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9317 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9318 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009319 * @param numOfSims number of active sims we want to switch to
9320 */
9321 @Override
9322 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009323 if (numOfSims == 1) {
9324 enforceModifyPermission();
9325 } else {
9326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9327 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9328 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009329 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009330
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009331 try {
Michele30b57b22019-03-01 12:01:14 -08009332 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009333 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009334 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9335 return;
9336 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009337 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
9340 }
9341 }
9342
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009343 @Override
9344 public boolean isApplicationOnUicc(int subId, int appType) {
9345 enforceReadPrivilegedPermission("isApplicationOnUicc");
9346 Phone phone = getPhone(subId);
9347 if (phone == null) {
9348 return false;
9349 }
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009352 UiccPort uiccPort = phone.getUiccPort();
9353 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009354 return false;
9355 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009356 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009357 if (uiccProfile == null) {
9358 return false;
9359 }
9360 if (TelephonyManager.APPTYPE_SIM <= appType
9361 && appType <= TelephonyManager.APPTYPE_ISIM) {
9362 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9363 }
9364 return false;
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
9369
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009370 /**
chen xub4baa772019-04-03 10:23:41 -07009371 * Get whether making changes to modem configurations will trigger reboot.
9372 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009373 */
9374 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009375 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9376 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009378 mApp, subId, callingPackage, callingFeatureId,
9379 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009380 return false;
9381 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009382 final long identity = Binder.clearCallingIdentity();
9383 try {
9384 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9385 } finally {
9386 Binder.restoreCallingIdentity(identity);
9387 }
9388 }
9389
Nathan Harold29f5f052019-02-15 13:41:57 -08009390 private void updateModemStateMetrics() {
9391 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9392 // TODO: check the state for each modem if the api is ready.
9393 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9394 }
9395
Pengquan Meng3889a572019-01-23 11:16:29 -08009396 @Override
9397 public int[] getSlotsMapping() {
9398 enforceReadPrivilegedPermission("getSlotsMapping");
9399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9403 // All logical slots should have a mapping to a physical slot.
9404 int[] logicalSlotsMapping = new int[phoneCount];
9405 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9406 for (int i = 0; i < slotInfos.length; i++) {
9407 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9408 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9409 }
9410 }
9411 return logicalSlotsMapping;
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009416
9417 /**
9418 * Get the IRadio HAL Version
9419 */
9420 @Override
9421 public int getRadioHalVersion() {
9422 Phone phone = getDefaultPhone();
9423 if (phone == null) return -1;
9424 HalVersion hv = phone.getHalVersion();
9425 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9426 return hv.major * 100 + hv.minor;
9427 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009428
9429 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009430 * Get the current calling package name.
9431 * @return the current calling package name
9432 */
9433 @Override
9434 public String getCurrentPackageName() {
9435 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9436 }
9437
9438 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009439 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9440 * corresponding network requests on a subId.
9441 *
9442 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009443 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009444 * 2) APN is un-metered for this subscription, or
9445 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009446 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009447 *
9448 * @return whether data is allowed for a apn type.
9449 *
9450 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009451 */
9452 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009453 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009454 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9455 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009456
9457 // Now that all security checks passes, perform the operation as ourselves.
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 Phone phone = getPhone(subId);
9461 if (phone == null) return false;
9462
Jack Yu41407ee2019-05-13 16:54:09 -07009463 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009464 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9465 } finally {
9466 Binder.restoreCallingIdentity(identity);
9467 }
9468 }
9469
9470 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009471 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009472 enforceReadPrivilegedPermission("isApnMetered");
9473
9474 // Now that all security checks passes, perform the operation as ourselves.
9475 final long identity = Binder.clearCallingIdentity();
9476 try {
9477 Phone phone = getPhone(subId);
9478 if (phone == null) return true; // By default return true.
9479
Jack Yu41407ee2019-05-13 16:54:09 -07009480 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009481 } finally {
9482 Binder.restoreCallingIdentity(identity);
9483 }
9484 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009485
9486 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009487 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9488 int subscriptionId, IBooleanConsumer resultCallback) {
9489 enforceModifyPermission();
9490 long token = Binder.clearCallingIdentity();
9491 try {
9492 Phone phone = getPhone(subscriptionId);
9493 if (phone == null) {
9494 try {
9495 if (resultCallback != null) {
9496 resultCallback.accept(false);
9497 }
9498 } catch (RemoteException e) {
9499 // ignore
9500 }
9501 return;
9502 }
9503 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9504 Pair.create(specifiers, (x) -> {
9505 try {
9506 if (resultCallback != null) {
9507 resultCallback.accept(x);
9508 }
9509 } catch (RemoteException e) {
9510 // ignore
9511 }
9512 });
9513 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9514 } finally {
9515 Binder.restoreCallingIdentity(token);
9516 }
9517 }
9518
9519 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009520 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9521 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009522 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009523 mApp, subId, "getSystemSelectionChannels");
9524 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9525 final long identity = Binder.clearCallingIdentity();
9526 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009527 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9528 if (result instanceof IllegalStateException) {
9529 throw (IllegalStateException) result;
9530 }
9531 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009532 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9533 return specifiers;
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
9538
9539 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009540 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009541 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009542 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9543 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9544 if (iccRecords == null) {
9545 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9546 return false;
9547 }
9548 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9549 }
9550
9551 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009552 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9553 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009554 if (callingPackage == null) {
9555 callingPackage = getCurrentPackageName();
9556 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009557 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9558 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009559 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9560 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009561 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9562 }
9563 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9564 Intent intent = new Intent();
9565 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9566 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9567 // Bring up choose default SMS subscription dialog right now
9568 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9569 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9570 mApp.startActivity(intent);
9571 }
chen xud5ca2d52019-05-28 15:20:57 -07009572
9573 @Override
9574 public String getMmsUAProfUrl(int subId) {
9575 //TODO investigate if this API should require proper permission check in R b/133791609
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009578 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9579 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9580 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9581 return carrierUAProfUrl;
9582 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009583 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9584 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
9589
9590 @Override
9591 public String getMmsUserAgent(int subId) {
9592 //TODO investigate if this API should require proper permission check in R b/133791609
9593 final long identity = Binder.clearCallingIdentity();
9594 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009595 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9596 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9597 if (!TextUtils.isEmpty(carrierUserAgent)) {
9598 return carrierUserAgent;
9599 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009600 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9601 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009602 } finally {
9603 Binder.restoreCallingIdentity(identity);
9604 }
9605 }
Jack Yub07d4972019-05-28 16:12:25 -07009606
9607 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009608 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9609 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009610
Jack Yub07d4972019-05-28 16:12:25 -07009611 final long identity = Binder.clearCallingIdentity();
9612 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009613 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009614 if (phone == null) return false;
9615
Hall Liua62f5da2020-09-25 10:42:19 -07009616 switch (policy) {
9617 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9618 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9619 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9620 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9621 default:
9622 throw new IllegalArgumentException(policy + " is not a valid policy");
9623 }
Jack Yub07d4972019-05-28 16:12:25 -07009624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627 }
9628
9629 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009630 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009631 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009632 enforceModifyPermission();
9633
changbettyd5c246e2019-12-24 15:40:37 +08009634 final long identity = Binder.clearCallingIdentity();
9635 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009636 Phone phone = getPhone(subscriptionId);
9637 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009638
Hall Liua62f5da2020-09-25 10:42:19 -07009639 switch (policy) {
9640 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9641 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9642 break;
9643 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9644 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9645 break;
9646 default:
9647 throw new IllegalArgumentException(policy + " is not a valid policy");
9648 }
changbettyd5c246e2019-12-24 15:40:37 +08009649 } finally {
9650 Binder.restoreCallingIdentity(identity);
9651 }
9652 }
9653
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009654 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009655 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009656 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9657 * otherwise.
9658 */
9659 @Override
9660 public void setCepEnabled(boolean isCepEnabled) {
9661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9662
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
9665 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9666 for (Phone phone : PhoneFactory.getPhones()) {
9667 Phone defaultPhone = phone.getImsPhone();
9668 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9669 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9670 ImsPhoneCallTracker imsPhoneCallTracker =
9671 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9672 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9673 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9674 + imsPhone.getMsisdn());
9675 }
9676 }
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
9679 }
9680 }
allenwtsu46dcc572020-01-08 18:24:03 +08009681
9682 /**
9683 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9684 *
9685 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9686 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9687 * before being read.
9688 */
9689 @Override
9690 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9691 isCompressed) {
9692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9693 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9695 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9696 }
9697 if (!isImsAvailableOnDevice()) {
9698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9699 "IMS not available on device.");
9700 }
9701
9702 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009703 try {
Hui Wang761a6682020-10-31 05:12:53 +00009704 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9705 } finally {
9706 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009707 }
9708 }
zoey chene02881a2019-12-30 16:11:23 +08009709
9710 @Override
9711 public boolean isIccLockEnabled(int subId) {
9712 enforceReadPrivilegedPermission("isIccLockEnabled");
9713
9714 // Now that all security checks passes, perform the operation as ourselves.
9715 final long identity = Binder.clearCallingIdentity();
9716 try {
9717 Phone phone = getPhone(subId);
9718 if (phone != null && phone.getIccCard() != null) {
9719 return phone.getIccCard().getIccLockEnabled();
9720 } else {
9721 return false;
9722 }
9723 } finally {
9724 Binder.restoreCallingIdentity(identity);
9725 }
9726 }
9727
9728 /**
9729 * Set the ICC pin lock enabled or disabled.
9730 *
9731 * @return an integer representing the status of IccLock enabled or disabled in the following
9732 * three cases:
9733 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9734 * successfully.
9735 * - Positive number and zero for remaining password attempts.
9736 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9737 *
9738 */
9739 @Override
9740 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9741 enforceModifyPermission();
9742
9743 Phone phone = getPhone(subId);
9744 if (phone == null) {
9745 return 0;
9746 }
9747 // Now that all security checks passes, perform the operation as ourselves.
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9751 new Pair<Boolean, String>(enabled, password), phone, null);
9752 return attemptsRemaining;
9753
9754 } catch (Exception e) {
9755 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
9759 return 0;
9760 }
9761
9762 /**
9763 * Change the ICC password used in ICC pin lock.
9764 *
9765 * @return an integer representing the status of IccLock changed in the following three cases:
9766 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9767 * - Positive number and zero for remaining password attempts.
9768 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9769 *
9770 */
9771 @Override
9772 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9773 enforceModifyPermission();
9774
9775 Phone phone = getPhone(subId);
9776 if (phone == null) {
9777 return 0;
9778 }
9779 // Now that all security checks passes, perform the operation as ourselves.
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9783 new Pair<String, String>(oldPassword, newPassword), phone, null);
9784 return attemptsRemaining;
9785
9786 } catch (Exception e) {
9787 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 return 0;
9792 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009793
9794 /**
9795 * Request for receiving user activity notification
9796 */
9797 @Override
9798 public void requestUserActivityNotification() {
9799 if (!mNotifyUserActivity.get()
9800 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9801 mNotifyUserActivity.set(true);
9802 }
9803 }
9804
9805 /**
9806 * Called when userActivity is signalled in the power manager.
9807 * This is safe to call from any thread, with any window manager locks held or not.
9808 */
9809 @Override
9810 public void userActivity() {
9811 // ***************************************
9812 // * Inherited from PhoneWindowManager *
9813 // ***************************************
9814 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9815 // WITH ITS LOCKS HELD.
9816 //
9817 // This code must be VERY careful about the locks
9818 // it acquires.
9819 // In fact, the current code acquires way too many,
9820 // and probably has lurking deadlocks.
9821
9822 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9823 throw new SecurityException("Only the OS may call notifyUserActivity()");
9824 }
9825
9826 if (mNotifyUserActivity.getAndSet(false)) {
9827 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9828 USER_ACTIVITY_NOTIFICATION_DELAY);
9829 }
9830 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009831
9832 @Override
9833 public boolean canConnectTo5GInDsdsMode() {
9834 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9835 }
Jack Yud10cdd42020-09-28 20:28:01 -07009836
9837 @Override
9838 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9839 String callingFeatureId) {
9840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9841 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9842 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9843 }
9844
9845 Phone phone = getPhone(subId);
9846 if (phone == null) {
9847 throw new RuntimeException("phone is not available");
9848 }
9849 // Now that all security checks passes, perform the operation as ourselves.
9850 final long identity = Binder.clearCallingIdentity();
9851 try {
9852 return phone.getEquivalentHomePlmns();
9853 } finally {
9854 Binder.restoreCallingIdentity(identity);
9855 }
9856 }
Daniel Bright59e67312020-11-13 11:49:37 -08009857
9858 @Override
9859 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009860 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9861 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009862 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009863 if (radioInterfaceCapabilities == null) {
9864 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009865 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009866 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009867 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009868
Hui Wang641e81c2020-10-12 12:14:23 -07009869 @Override
9870 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9871 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009872 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9873 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9874 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9875 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9876 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009877 if (DBG) {
9878 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9879 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9880 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9881 }
9882
9883 if (!SubscriptionManager.isValidSubscriptionId(subId)
9884 || appType < TelephonyManager.APPTYPE_UNKNOWN
9885 || appType > TelephonyManager.APPTYPE_ISIM
9886 || nafUrl == null || securityProtocol == null || callback == null) {
9887 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9888 if (callback != null) {
9889 try {
9890 callback.onAuthenticationFailure(
9891 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9892 } catch (RemoteException exception) {
9893 log("Fail to notify onAuthenticationFailure due to " + exception);
9894 }
9895 return;
9896 }
9897 }
9898
9899 final long token = Binder.clearCallingIdentity();
9900 try {
9901 getGbaManager(subId).bootstrapAuthenticationRequest(
9902 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9903 forceBootStrapping, callback));
9904 } finally {
9905 Binder.restoreCallingIdentity(token);
9906 }
9907 }
9908
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009909 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009910 * Attempts to set the radio power state for all phones for thermal reason.
9911 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009912 * requested radio power state will actually be set. See {@link
9913 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9914 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009915 * @param enable {@code true} if trying to turn radio on.
9916 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9917 * false}.
9918 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009919 private boolean setRadioPowerForThermal(boolean enable) {
9920 boolean isPhoneAvailable = false;
9921 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9922 Phone phone = PhoneFactory.getPhone(i);
9923 if (phone != null) {
9924 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9925 isPhoneAvailable = true;
9926 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009927 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009928
9929 // return true if successfully informed the phone object about the thermal radio power
9930 // request.
9931 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009932 }
9933
9934 private int handleDataThrottlingRequest(int subId,
9935 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009936 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9937 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9938 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9939 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9940 throw new IllegalArgumentException("modem does not support data throttling");
9941 }
9942
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009943 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9944 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009945 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009946 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9947 }
9948
9949 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9950
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009951 if (isDataThrottlingSupported) {
9952 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009953 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009954 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9955 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9956 } else if (thermalMitigationResult
9957 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009958 log("Modem likely does not support data throttling on secondary carrier. Data " +
9959 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9960 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009961 }
9962 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009963 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009964
9965 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009966 }
9967
Jack Nudelman644b91a2021-03-12 14:09:48 -08009968 private static List<String> getThermalMitigationAllowlist(Context context) {
9969 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9970 for (String pckg : context.getResources()
9971 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9972 sThermalMitigationAllowlistedPackages.add(pckg);
9973 }
9974 }
9975
9976 return sThermalMitigationAllowlistedPackages;
9977 }
9978
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009979 private boolean isAnyPhoneInEmergencyState() {
9980 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9981 if (tm.isInEmergencyCall()) {
9982 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9983 return true;
9984 }
9985 for (Phone phone : PhoneFactory.getPhones()) {
9986 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9987 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9988 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9989 + phone.isInEcm());
9990 return true;
9991 }
9992 }
9993
9994 return false;
9995 }
9996
Jack Nudelman644b91a2021-03-12 14:09:48 -08009997 /**
9998 * Used by shell commands to add an authorized package name for thermal mitigation.
9999 * @param packageName name of package to be allowlisted
10000 * @param context
10001 */
10002 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10003 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10004 sThermalMitigationAllowlistedPackages.add(packageName);
10005 }
10006
10007 /**
10008 * Used by shell commands to remove an authorized package name for thermal mitigation.
10009 * @param packageName name of package to remove from allowlist
10010 * @param context
10011 */
10012 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10013 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10014 sThermalMitigationAllowlistedPackages.remove(packageName);
10015 }
10016
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010017 /**
10018 * Thermal mitigation request to control functionalities at modem.
10019 *
10020 * @param subId the id of the subscription.
10021 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010022 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010023 *
10024 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10025 */
10026 @Override
10027 @ThermalMitigationResult
10028 public int sendThermalMitigationRequest(
10029 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010030 ThermalMitigationRequest thermalMitigationRequest,
10031 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010032 enforceModifyPermission();
10033
Jack Nudelman644b91a2021-03-12 14:09:48 -080010034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10035 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10036 .contains(callingPackage)) {
10037 throw new SecurityException("Calling package must be configured in the device config. "
10038 + "calling package: " + callingPackage);
10039 }
10040
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010041 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10042 final long identity = Binder.clearCallingIdentity();
10043
10044 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10045 try {
10046 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10047 switch (thermalMitigationAction) {
10048 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10049 thermalMitigationResult =
10050 handleDataThrottlingRequest(subId,
10051 thermalMitigationRequest.getDataThrottlingRequest());
10052 break;
10053 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10054 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10055 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10056 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10057 }
10058
10059 // Ensure that radio is on. If not able to power on due to phone being
10060 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010061 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010062 thermalMitigationResult =
10063 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10064 break;
10065 }
10066
10067 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10068 false);
10069 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10070 break;
10071 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10072 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10073 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10074 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10075 }
10076
10077 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10078 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010079 Phone phone = getPhone(subId);
10080 if (phone == null) {
10081 thermalMitigationResult =
10082 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10083 break;
10084 }
10085
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010086 TelephonyConnectionService service =
10087 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010088 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010089 Log.e(LOG_TAG, "An emergency call is pending");
10090 thermalMitigationResult =
10091 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10092 break;
10093 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010094 thermalMitigationResult =
10095 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10096 break;
10097 }
10098 } else {
10099 thermalMitigationResult =
10100 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10101 break;
10102 }
10103
10104 // Turn radio off. If not able to power off due to phone being unavailable,
10105 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010106 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 thermalMitigationResult =
10108 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10109 break;
10110 }
10111 thermalMitigationResult =
10112 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10113 break;
10114 default:
10115 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10116 + "not exist. Requested action: " + thermalMitigationAction);
10117 }
10118 } catch (IllegalArgumentException e) {
10119 throw e;
10120 } catch (Exception e) {
10121 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10122 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10123 } finally {
10124 Binder.restoreCallingIdentity(identity);
10125 }
10126
10127 if (DBG) {
10128 log("thermalMitigationRequest returning with thermalMitigationResult: "
10129 + thermalMitigationResult);
10130 }
10131
10132 return thermalMitigationResult;
10133 }
Hui Wang641e81c2020-10-12 12:14:23 -070010134
10135 /**
10136 * Set the GbaService Package Name that Telephony will bind to.
10137 *
10138 * @param subId The sim that the GbaService is associated with.
10139 * @param packageName The name of the package to be replaced with.
10140 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10141 */
10142 @Override
10143 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10144 enforceModifyPermission();
10145
10146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 return getGbaManager(subId).overrideServicePackage(packageName);
10149 } finally {
10150 Binder.restoreCallingIdentity(identity);
10151 }
10152 }
10153
10154 /**
10155 * Return the package name of the currently bound GbaService.
10156 *
10157 * @param subId The sim that the GbaService is associated with.
10158 * @return the package name of the GbaService configuration, null if GBA is not supported.
10159 */
10160 @Override
10161 public String getBoundGbaService(int subId) {
10162 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10163
10164 final long identity = Binder.clearCallingIdentity();
10165 try {
10166 return getGbaManager(subId).getServicePackage();
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 }
10171
10172 /**
10173 * Set the release time for telephony to unbind GbaService.
10174 *
10175 * @param subId The sim that the GbaService is associated with.
10176 * @param interval The release time to unbind GbaService by millisecond.
10177 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10178 */
10179 @Override
10180 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10181 enforceModifyPermission();
10182
10183 final long identity = Binder.clearCallingIdentity();
10184 try {
10185 return getGbaManager(subId).overrideReleaseTime(interval);
10186 } finally {
10187 Binder.restoreCallingIdentity(identity);
10188 }
10189 }
10190
10191 /**
10192 * Return the release time for telephony to unbind GbaService.
10193 *
10194 * @param subId The sim that the GbaService is associated with.
10195 * @return The release time to unbind GbaService by millisecond.
10196 */
10197 @Override
10198 public int getGbaReleaseTime(int subId) {
10199 enforceReadPrivilegedPermission("getGbaReleaseTime");
10200
10201 final long identity = Binder.clearCallingIdentity();
10202 try {
10203 return getGbaManager(subId).getReleaseTime();
10204 } finally {
10205 Binder.restoreCallingIdentity(identity);
10206 }
10207 }
10208
10209 private GbaManager getGbaManager(int subId) {
10210 GbaManager instance = GbaManager.getInstance(subId);
10211 if (instance == null) {
10212 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10213 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10214 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10215 }
10216 return instance;
10217 }
Hui Wang761a6682020-10-31 05:12:53 +000010218
10219 /**
10220 * indicate whether the device and the carrier can support
10221 * RCS VoLTE single registration.
10222 */
10223 @Override
10224 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010225 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10226 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10227 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10228 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010229
10230 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10231 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10232 }
10233
10234 final long identity = Binder.clearCallingIdentity();
10235 try {
10236 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10237 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010238 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10239 if (isCapable != null) {
10240 return isCapable;
10241 }
Hui Wang761a6682020-10-31 05:12:53 +000010242 }
Hui Wang67af90e2021-06-04 16:57:15 -070010243 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10244 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010245 } finally {
10246 Binder.restoreCallingIdentity(identity);
10247 }
10248 }
10249
10250 /**
10251 * Register RCS provisioning callback.
10252 */
10253 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010254 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010255 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010256 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010257 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010258 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10259 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010260
10261 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10262 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10263 }
10264 if (!isImsAvailableOnDevice()) {
10265 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10266 "IMS not available on device.");
10267 }
10268
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010271 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010272 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010273 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10274 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010275 }
Hui Wang761a6682020-10-31 05:12:53 +000010276 } finally {
10277 Binder.restoreCallingIdentity(identity);
10278 }
10279 }
10280
10281 /**
10282 * Unregister RCS provisioning callback.
10283 */
10284 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010285 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010286 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010287 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010288 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010289 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10290 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010291
10292 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10293 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10294 }
10295 if (!isImsAvailableOnDevice()) {
10296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10297 "IMS not available on device.");
10298 }
10299
10300 final long identity = Binder.clearCallingIdentity();
10301 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010302 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010303 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010304 } finally {
10305 Binder.restoreCallingIdentity(identity);
10306 }
10307 }
10308
10309 /**
10310 * trigger RCS reconfiguration.
10311 */
10312 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010313 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10314 "triggerRcsReconfiguration",
10315 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010316
10317 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10318 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10319 }
10320 if (!isImsAvailableOnDevice()) {
10321 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10322 "IMS not available on device.");
10323 }
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
10332
10333 /**
10334 * Provide the client configuration parameters of the RCS application.
10335 */
10336 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010337 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10338 "setRcsClientConfiguration",
10339 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010340
10341 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10342 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10343 }
10344 if (!isImsAvailableOnDevice()) {
10345 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10346 "IMS not available on device.");
10347 }
10348
10349 final long identity = Binder.clearCallingIdentity();
10350
10351 try {
10352 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10353 if (configBinder == null) {
10354 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010355 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10356 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010357 } else {
10358 configBinder.setRcsClientConfiguration(rcc);
10359 }
joonhunshin35f64142021-09-17 06:33:39 +000010360
10361 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10362 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010363 } catch (RemoteException e) {
10364 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010365 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10366 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
10371
10372 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010373 * Enables or disables the test mode for RCS VoLTE single registration.
10374 */
10375 @Override
10376 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10378 "setRcsSingleRegistrationTestModeEnabled");
10379
10380 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10381 }
10382
10383 /**
10384 * Gets the test mode for RCS VoLTE single registration.
10385 */
10386 @Override
10387 public boolean getRcsSingleRegistrationTestModeEnabled() {
10388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10389 "getRcsSingleRegistrationTestModeEnabled");
10390
10391 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10392 }
10393
10394 /**
Hui Wang761a6682020-10-31 05:12:53 +000010395 * Overrides the config of RCS VoLTE single registration enabled for the device.
10396 */
10397 @Override
10398 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10399 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10400 "setDeviceSingleRegistrationEnabledOverride");
10401 enforceModifyPermission();
10402
10403 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10404 : Boolean.parseBoolean(enabledStr);
10405 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010406 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010407 }
10408
10409 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010410 * Sends a device to device communication message. Only usable via shell.
10411 * @param message message to send.
10412 * @param value message value.
10413 */
10414 @Override
10415 public void sendDeviceToDeviceMessage(int message, int value) {
10416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010417 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010418 enforceModifyPermission();
10419
10420 final long identity = Binder.clearCallingIdentity();
10421 try {
10422 TelephonyConnectionService service =
10423 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10424 if (service == null) {
10425 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10426 return;
10427 }
10428 service.sendTestDeviceToDeviceMessage(message, value);
10429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 }
10433
Tyler Gunnbabbda02021-02-10 11:05:02 -080010434 /**
10435 * Sets the specified device to device transport active.
10436 * @param transport The transport to set active.
10437 */
10438 @Override
10439 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10440 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10441 "setActiveDeviceToDeviceTransport");
10442 enforceModifyPermission();
10443
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
10446 TelephonyConnectionService service =
10447 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10448 if (service == null) {
10449 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10450 return;
10451 }
10452 service.setActiveDeviceToDeviceTransport(transport);
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
Tyler Gunn92479152021-01-20 16:30:10 -080010457
Tyler Gunnd4575212021-05-03 14:46:49 -070010458 @Override
10459 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10460 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10461 "setDeviceToDeviceForceEnabled");
10462
10463 final long identity = Binder.clearCallingIdentity();
10464 try {
10465 Arrays.stream(PhoneFactory.getPhones()).forEach(
10466 p -> {
10467 Phone thePhone = p.getImsPhone();
10468 if (thePhone != null && thePhone instanceof ImsPhone) {
10469 ImsPhone imsPhone = (ImsPhone) thePhone;
10470 CallTracker tracker = imsPhone.getCallTracker();
10471 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10472 ImsPhoneCallTracker imsPhoneCallTracker =
10473 (ImsPhoneCallTracker) tracker;
10474 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10475 }
10476 }
10477 }
10478 );
10479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
10483
Tyler Gunn92479152021-01-20 16:30:10 -080010484 /**
Hui Wang761a6682020-10-31 05:12:53 +000010485 * Gets the config of RCS VoLTE single registration enabled for the device.
10486 */
10487 @Override
10488 public boolean getDeviceSingleRegistrationEnabled() {
10489 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10490 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10491 }
10492
10493 /**
10494 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10495 */
10496 @Override
10497 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10498 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10499 "setCarrierSingleRegistrationEnabledOverride");
10500 enforceModifyPermission();
10501
10502 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10503 : Boolean.parseBoolean(enabledStr);
10504 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10505 subId, enabled);
10506 }
10507
10508 /**
10509 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10510 */
10511 @Override
10512 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10513 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10514 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10515 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010516
10517 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010518 * Overrides the ims feature validation result
10519 */
10520 @Override
10521 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10523 "setImsFeatureValidationOverride");
10524
10525 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10526 : Boolean.parseBoolean(enabledStr);
10527 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10528 subId, enabled);
10529 }
10530
10531 /**
10532 * Gets the ims feature validation override value
10533 */
10534 @Override
10535 public boolean getImsFeatureValidationOverride(int subId) {
10536 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10537 "getImsFeatureValidationOverride");
10538 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10539 }
10540
10541 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010542 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10543 * their mobile plan.
10544 */
10545 @Override
10546 public String getMobileProvisioningUrl() {
10547 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10548 final long identity = Binder.clearCallingIdentity();
10549 try {
10550 return getDefaultPhone().getMobileProvisioningUrl();
10551 } finally {
10552 Binder.restoreCallingIdentity(identity);
10553 }
10554 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010555
James.cf Linbcdf8b32021-01-14 16:44:13 +080010556 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010557 * Get the EAB contact from the EAB database.
10558 */
10559 @Override
10560 public String getContactFromEab(String contact) {
10561 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10562 enforceModifyPermission();
10563 final long identity = Binder.clearCallingIdentity();
10564 try {
10565 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10566 } finally {
10567 Binder.restoreCallingIdentity(identity);
10568 }
10569 }
10570
10571 /**
Calvin Pana1434322021-07-01 19:27:01 +080010572 * Get the EAB capability from the EAB database.
10573 */
10574 @Override
10575 public String getCapabilityFromEab(String contact) {
10576 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10577 enforceModifyPermission();
10578 final long identity = Binder.clearCallingIdentity();
10579 try {
10580 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10581 } finally {
10582 Binder.restoreCallingIdentity(identity);
10583 }
10584 }
10585
10586 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010587 * Remove the EAB contacts from the EAB database.
10588 */
10589 @Override
10590 public int removeContactFromEab(int subId, String contacts) {
10591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10592 enforceModifyPermission();
10593 final long identity = Binder.clearCallingIdentity();
10594 try {
10595 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
10600
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010601 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010602 public boolean getDeviceUceEnabled() {
10603 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 return mApp.getDeviceUceEnabled();
10607 } finally {
10608 Binder.restoreCallingIdentity(identity);
10609 }
10610 }
10611
10612 @Override
10613 public void setDeviceUceEnabled(boolean isEnabled) {
10614 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10615 final long identity = Binder.clearCallingIdentity();
10616 try {
10617 mApp.setDeviceUceEnabled(isEnabled);
10618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
10622
Brad Ebinger14d467f2021-02-12 06:18:28 +000010623 /**
10624 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10625 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10626 */
10627 // Used for SHELL command only right now.
10628 @Override
10629 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10630 List<String> featureTags) {
10631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10632 "addUceRegistrationOverrideShell");
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10636 new ArraySet<>(featureTags));
10637 } catch (ImsException e) {
10638 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10639 } finally {
10640 Binder.restoreCallingIdentity(identity);
10641 }
10642 }
10643
10644 /**
10645 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10646 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10647 */
10648 // Used for SHELL command only right now.
10649 @Override
10650 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10651 List<String> featureTags) {
10652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10653 "removeUceRegistrationOverrideShell");
10654 final long identity = Binder.clearCallingIdentity();
10655 try {
10656 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10657 new ArraySet<>(featureTags));
10658 } catch (ImsException e) {
10659 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
10664
10665 /**
10666 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10667 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10668 */
10669 // Used for SHELL command only right now.
10670 @Override
10671 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10673 "clearUceRegistrationOverrideShell");
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
10676 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10677 } catch (ImsException e) {
10678 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
10683
10684 /**
10685 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10686 */
10687 // Used for SHELL command only right now.
10688 @Override
10689 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10691 "getLatestRcsContactUceCapabilityShell");
10692 final long identity = Binder.clearCallingIdentity();
10693 try {
10694 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10695 } catch (ImsException e) {
10696 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10697 } finally {
10698 Binder.restoreCallingIdentity(identity);
10699 }
10700 }
10701
10702 /**
10703 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10704 * device does not have an active PUBLISH.
10705 */
10706 // Used for SHELL command only right now.
10707 @Override
10708 public String getLastUcePidfXmlShell(int subId) {
10709 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10710 final long identity = Binder.clearCallingIdentity();
10711 try {
10712 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10713 } catch (ImsException e) {
10714 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10715 } finally {
10716 Binder.restoreCallingIdentity(identity);
10717 }
10718 }
10719
James.cf Line8713a42021-04-29 16:04:26 +080010720 /**
10721 * Remove UCE requests cannot be sent to the network status.
10722 */
10723 // Used for SHELL command only right now.
10724 @Override
10725 public boolean removeUceRequestDisallowedStatus(int subId) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10727 final long identity = Binder.clearCallingIdentity();
10728 try {
10729 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10730 } catch (ImsException e) {
10731 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
James.cf Lin0fc71b02021-05-25 01:37:38 +080010737 /**
10738 * Remove UCE requests cannot be sent to the network status.
10739 */
10740 // Used for SHELL command only.
10741 @Override
10742 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10744 final long identity = Binder.clearCallingIdentity();
10745 try {
10746 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10747 } catch (ImsException e) {
10748 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10749 } finally {
10750 Binder.restoreCallingIdentity(identity);
10751 }
10752 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010753
James.cf Lin4b784aa2021-01-31 03:25:15 +080010754 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010755 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10756 String callingPackage) {
10757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10758 mApp, subId, "setSignalStrengthUpdateRequest");
10759
10760 final int callingUid = Binder.getCallingUid();
10761 // Verify that tha callingPackage belongs to the calling UID
10762 mApp.getSystemService(AppOpsManager.class)
10763 .checkPackage(callingUid, callingPackage);
10764
Rambo Wang3607f502021-02-01 21:51:40 -080010765 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10770 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10771
10772 if (result instanceof IllegalStateException) {
10773 throw (IllegalStateException) result;
10774 }
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
10780 @Override
10781 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10782 String callingPackage) {
10783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10784 mApp, subId, "clearSignalStrengthUpdateRequest");
10785
10786 final int callingUid = Binder.getCallingUid();
10787 // Verify that tha callingPackage belongs to the calling UID
10788 mApp.getSystemService(AppOpsManager.class)
10789 .checkPackage(callingUid, callingPackage);
10790
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10794 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10795
10796 if (result instanceof IllegalStateException) {
10797 throw (IllegalStateException) result;
10798 }
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
Rambo Wang3607f502021-02-01 21:51:40 -080010804 private static void validateSignalStrengthUpdateRequest(Context context,
10805 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010806 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10807 // phone/system process do not have further restriction on request
10808 return;
10809 }
10810
10811 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010812 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010813 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010814 context.enforceCallingOrSelfPermission(
10815 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10816 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010817 }
10818
10819 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10820 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10821 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10822 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10823 || info.isEnabled()) {
10824 throw new IllegalArgumentException(
10825 "Only system can set hide fields in SignalThresholdInfo");
10826 }
10827
10828 // Thresholds length for each RAN need in range. This has been validated in
10829 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10830 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10831 final int[] thresholds = info.getThresholds();
10832 Objects.requireNonNull(thresholds);
10833 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10834 || thresholds.length
10835 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10836 throw new IllegalArgumentException(
10837 "thresholds length is out of range: " + thresholds.length);
10838 }
10839 }
10840 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010841
10842 /**
10843 * Gets the current phone capability.
10844 *
10845 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10846 * @return the PhoneCapability which describes the data connection capability of modem.
10847 * It's used to evaluate possible phone config change, for example from single
10848 * SIM device to multi-SIM device.
10849 */
10850 @Override
10851 public PhoneCapability getPhoneCapability() {
10852 enforceReadPrivilegedPermission("getPhoneCapability");
10853 final long identity = Binder.clearCallingIdentity();
10854 try {
10855 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
Michele Berionne5e411512020-11-13 02:36:59 +000010860
10861 /**
10862 * Prepare TelephonyManager for an unattended reboot. The reboot is
10863 * required to be done shortly after the API is invoked.
10864 */
10865 @Override
10866 @TelephonyManager.PrepareUnattendedRebootResult
10867 public int prepareForUnattendedReboot() {
10868 enforceRebootPermission();
10869
10870 final long identity = Binder.clearCallingIdentity();
10871 try {
10872 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010877
10878 /**
10879 * Request to get the current slicing configuration including URSP rules and
10880 * NSSAIs (configured, allowed and rejected).
10881 *
10882 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10883 */
10884 @Override
10885 public void getSlicingConfig(ResultReceiver callback) {
10886 enforceReadPrivilegedPermission("getSlicingConfig");
10887
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 Phone phone = getDefaultPhone();
10891 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010896
10897 /**
10898 * Register an IMS connection state callback
10899 */
10900 @Override
10901 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10902 String callingPackage) {
10903 if (feature == ImsFeature.FEATURE_MMTEL) {
10904 // ImsMmTelManager
10905 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10906 TelephonyPermissions
10907 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10908 mApp, subId, "registerImsStateCallback");
10909 } else if (feature == ImsFeature.FEATURE_RCS) {
10910 // ImsRcsManager or SipDelegateManager
10911 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10912 Binder.getCallingUid(), "registerImsStateCallback",
10913 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10914 Manifest.permission.READ_PRECISE_PHONE_STATE,
10915 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10916 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10917 }
10918
10919 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10920 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10921 "IMS not available on device.");
10922 }
10923
10924 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
10925 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
10926 }
10927
10928 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10929 if (controller == null) {
10930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10931 "IMS not available on device.");
10932 }
10933
10934 if (callingPackage == null) {
10935 callingPackage = getCurrentPackageName();
10936 }
10937
10938 final long token = Binder.clearCallingIdentity();
10939 try {
10940 int slotId = getSlotIndexOrException(subId);
10941 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
10942 } catch (ImsException e) {
10943 throw new ServiceSpecificException(e.getCode());
10944 } finally {
10945 Binder.restoreCallingIdentity(token);
10946 }
10947 }
10948
10949 /**
10950 * Unregister an IMS connection state callback
10951 */
10952 @Override
10953 public void unregisterImsStateCallback(IImsStateCallback cb) {
10954 final long token = Binder.clearCallingIdentity();
10955 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10956 if (controller == null) {
10957 return;
10958 }
10959 try {
10960 controller.unregisterImsStateCallback(cb);
10961 } finally {
10962 Binder.restoreCallingIdentity(token);
10963 }
10964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010965}