blob: e5d60d8a18f149494a8bff543d08885c47f3e33a [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;
joonhunshin3e154242021-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 Gunnd4339262021-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;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700156import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800157import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800159import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700160import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700161import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700162import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700164import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800165import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700166import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700167import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700168import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700169import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800170import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800171import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700172import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700173import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800175import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800176import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800177import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700178import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700180import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800181import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700182import com.android.internal.telephony.imsphone.ImsPhone;
183import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000184import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800185import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700186import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800188import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.uicc.IccUtils;
Grace Jia59437e82021-09-21 15:47:32 -0700190import com.android.internal.telephony.uicc.PinStorage;
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;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800195import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000196import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800197import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700198import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700199import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800200import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800201import com.android.phone.callcomposer.CallComposerPictureManager;
202import com.android.phone.callcomposer.CallComposerPictureTransfer;
203import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700204import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700205import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800206import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700207import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700208import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800209import com.android.services.telephony.TelecomAccountRegistry;
210import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800211import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800212
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800215import java.io.IOException;
216import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700217import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800220import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800221import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800222import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100223import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700225import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800227import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800228import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800229import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800230import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231
232/**
233 * Implementation of the ITelephony interface.
234 */
Santos Cordon117fee72014-05-16 17:56:12 -0700235public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 private static final String LOG_TAG = "PhoneInterfaceManager";
237 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
238 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241 // Message codes used with mMainThreadHandler
242 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700243 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
244 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700245 private static final int CMD_OPEN_CHANNEL = 9;
246 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
247 private static final int CMD_CLOSE_CHANNEL = 11;
248 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800249 private static final int CMD_NV_READ_ITEM = 13;
250 private static final int EVENT_NV_READ_ITEM_DONE = 14;
251 private static final int CMD_NV_WRITE_ITEM = 15;
252 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
253 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
254 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_RESET_MODEM_CONFIG = 19;
256 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800257 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
258 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800259 private static final int CMD_SEND_ENVELOPE = 25;
260 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000261 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
262 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700263 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
264 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
265 private static final int CMD_EXCHANGE_SIM_IO = 31;
266 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800267 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
268 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700269 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
270 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700271 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
272 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700273 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
274 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
275 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
276 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700277 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
278 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
279 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
280 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700281 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800282 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
283 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000284 private static final int CMD_SWITCH_SLOTS = 50;
285 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700286 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
287 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
288 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
289 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
290 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
291 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
292 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
293 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700294 private static final int CMD_GET_ALL_CELL_INFO = 60;
295 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
296 private static final int CMD_GET_CELL_LOCATION = 62;
297 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700298 private static final int CMD_MODEM_REBOOT = 64;
299 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700300 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
301 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800302 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
303 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700304 private static final int CMD_GET_MODEM_STATUS = 70;
305 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700306 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
307 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700308 private static final int CMD_ERASE_MODEM_CONFIG = 74;
309 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800310 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
311 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
312 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
313 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800314 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
315 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800316 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800317 private static final int CMD_GET_CALL_FORWARDING = 83;
318 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
319 private static final int CMD_SET_CALL_FORWARDING = 85;
320 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
321 private static final int CMD_GET_CALL_WAITING = 87;
322 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
323 private static final int CMD_SET_CALL_WAITING = 89;
324 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700325 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
326 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
327 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
328 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700329 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
330 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800331 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
332 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800333 private static final int CMD_SET_DATA_THROTTLING = 99;
334 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800335 private static final int CMD_SET_SIM_POWER = 101;
336 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800337 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
338 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
339 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
340 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800341 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
342 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000343 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800344 private static final int CMD_GET_SLICING_CONFIG = 110;
345 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800346 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700347 private static final int CMD_ENABLE_VONR = 113;
348 private static final int EVENT_ENABLE_VONR_DONE = 114;
349 private static final int CMD_IS_VONR_ENABLED = 115;
350 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800352 // Parameters of select command.
353 private static final int SELECT_COMMAND = 0xA4;
354 private static final int SELECT_P1 = 0x04;
355 private static final int SELECT_P2 = 0;
356 private static final int SELECT_P3 = 0x10;
357
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 /** The singleton instance. */
359 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800360 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800364 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700365 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800366 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700367 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800369 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700371 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800372 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 /** User Activity */
375 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800376 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
377
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700378 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
379
Derek Tan97ebb422014-09-05 16:55:38 -0700380 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
381 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800382 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800383 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700384
Michelecea4cf22018-12-21 15:00:11 -0800385 // String to store multi SIM allowed
386 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
387
Derek Tan740e1672017-06-27 14:56:27 -0700388 // The AID of ISD-R.
389 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
390
yinxub1bed742017-04-17 11:45:04 -0700391 private NetworkScanRequestTracker mNetworkScanRequestTracker;
392
David Kelly5e06a7f2018-03-12 14:10:59 +0000393 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
394 private static final int MANUFACTURER_CODE_LENGTH = 8;
395
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800396 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800397 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800398
Derek Tan89e89d42014-07-08 17:00:10 -0700399 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700400 * Experiment flag to enable erase modem config on reset network, default value is false
401 */
402 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
403 "reset_network_erase_modem_config_enabled";
404
Rambo Wang0f050d82021-02-12 11:43:36 -0800405 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
406
Naina Nallurid63128d2019-09-17 14:10:30 -0700407 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700408 * A request object to use for transmitting data to an ICC.
409 */
410 private static final class IccAPDUArgument {
411 public int channel, cla, command, p1, p2, p3;
412 public String data;
413
414 public IccAPDUArgument(int channel, int cla, int command,
415 int p1, int p2, int p3, String data) {
416 this.channel = channel;
417 this.cla = cla;
418 this.command = command;
419 this.p1 = p1;
420 this.p2 = p2;
421 this.p3 = p3;
422 this.data = data;
423 }
424 }
425
426 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700427 * A request object to use for transmitting data to an ICC.
428 */
429 private static final class ManualNetworkSelectionArgument {
430 public OperatorInfo operatorInfo;
431 public boolean persistSelection;
432
433 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
434 this.operatorInfo = operatorInfo;
435 this.persistSelection = persistSelection;
436 }
437 }
438
439 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
441 * request after sending. The main thread will notify the request when it is complete.
442 */
443 private static final class MainThreadRequest {
444 /** The argument to use for the request */
445 public Object argument;
446 /** The result of the request that is run on the main thread */
447 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800448 // The subscriber id that this request applies to. Defaults to
449 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
450 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451
Nathan Harold92bed182018-10-12 18:16:49 -0700452 // In cases where subId is unavailable, the caller needs to specify the phone.
453 public Phone phone;
454
vagdeviaf9a5b92018-08-15 16:01:53 -0700455 public WorkSource workSource;
456
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 public MainThreadRequest(Object argument) {
458 this.argument = argument;
459 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800460
Nathan Harold92bed182018-10-12 18:16:49 -0700461 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
462 this.argument = argument;
463 if (phone != null) {
464 this.phone = phone;
465 }
466 this.workSource = workSource;
467 }
468
vagdeviaf9a5b92018-08-15 16:01:53 -0700469 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800470 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800471 if (subId != null) {
472 this.subId = subId;
473 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700474 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 }
477
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800478 private static final class IncomingThirdPartyCallArgs {
479 public final ComponentName component;
480 public final String callId;
481 public final String callerDisplayName;
482
483 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
484 String callerDisplayName) {
485 this.component = component;
486 this.callId = callId;
487 this.callerDisplayName = callerDisplayName;
488 }
489 }
490
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 /**
492 * A handler that processes messages on the main thread in the phone process. Since many
493 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
494 * inbound binder threads to the main thread in the phone process. The Binder thread
495 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
496 * on, which will be notified when the operation completes and will contain the result of the
497 * request.
498 *
499 * <p>If a MainThreadRequest object is provided in the msg.obj field,
500 * note that request.result must be set to something non-null for the calling thread to
501 * unblock.
502 */
503 private final class MainThreadHandler extends Handler {
504 @Override
505 public void handleMessage(Message msg) {
506 MainThreadRequest request;
507 Message onCompleted;
508 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800509 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800511 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512
513 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 case CMD_HANDLE_USSD_REQUEST: {
515 request = (MainThreadRequest) msg.obj;
516 final Phone phone = getPhoneFromRequest(request);
517 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
518 String ussdRequest = ussdObject.first;
519 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700520
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 if (!isUssdApiAllowed(request.subId)) {
522 // Carrier does not support use of this API, return failure.
523 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
524 UssdResponse response = new UssdResponse(ussdRequest, null);
525 Bundle returnData = new Bundle();
526 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
527 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700528
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 request.result = true;
530 notifyRequester(request);
531 return;
532 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700533
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 try {
535 request.result = phone != null
536 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
537 } catch (CallStateException cse) {
538 request.result = false;
539 }
540 // Wake up the requesting thread
541 notifyRequester(request);
542 break;
pkanwar32d516d2016-10-14 19:37:38 -0700543 }
544
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700547 final Phone phone = getPhoneFromRequest(request);
548 request.result = phone != null ?
549 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
550 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800559 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 if (uiccCard == null) {
561 loge("iccTransmitApduLogicalChannel: No UICC");
562 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
566 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 iccArgument.channel, iccArgument.cla, iccArgument.command,
569 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 break;
573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 ar = (AsyncResult) msg.obj;
576 request = (MainThreadRequest) ar.userObj;
577 if (ar.exception == null && ar.result != null) {
578 request.result = ar.result;
579 } else {
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
581 if (ar.result == null) {
582 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800583 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800585 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 } else {
587 loge("iccTransmitApduLogicalChannel: Unknown exception");
588 }
589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 break;
592
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
594 request = (MainThreadRequest) msg.obj;
595 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 if (uiccCard == null) {
598 loge("iccTransmitApduBasicChannel: No UICC");
599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
603 request);
604 uiccCard.iccTransmitApduBasicChannel(
605 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
606 iccArgument.p3, iccArgument.data, onCompleted);
607 }
608 break;
609
610 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
613 if (ar.exception == null && ar.result != null) {
614 request.result = ar.result;
615 } else {
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
617 if (ar.result == null) {
618 loge("iccTransmitApduBasicChannel: Empty response");
619 } else if (ar.exception instanceof CommandException) {
620 loge("iccTransmitApduBasicChannel: CommandException: " +
621 ar.exception);
622 } else {
623 loge("iccTransmitApduBasicChannel: Unknown exception");
624 }
625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 break;
628
629 case CMD_EXCHANGE_SIM_IO:
630 request = (MainThreadRequest) msg.obj;
631 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800632 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 if (uiccCard == null) {
634 loge("iccExchangeSimIO: No UICC");
635 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 } else {
638 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
639 request);
640 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
641 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
642 iccArgument.data, onCompleted);
643 }
644 break;
645
646 case EVENT_EXCHANGE_SIM_IO_DONE:
647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result;
651 } else {
652 request.result = new IccIoResult(0x6f, 0, (byte[])null);
653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 break;
656
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 case CMD_SEND_ENVELOPE:
658 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800659 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 if (uiccCard == null) {
661 loge("sendEnvelopeWithStatus: No UICC");
662 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
665 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
666 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
667 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 break;
669
670 case EVENT_SEND_ENVELOPE_DONE:
671 ar = (AsyncResult) msg.obj;
672 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700673 if (ar.exception == null && ar.result != null) {
674 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700676 request.result = new IccIoResult(0x6F, 0, (byte[])null);
677 if (ar.result == null) {
678 loge("sendEnvelopeWithStatus: Empty response");
679 } else if (ar.exception instanceof CommandException) {
680 loge("sendEnvelopeWithStatus: CommandException: " +
681 ar.exception);
682 } else {
683 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
684 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 break;
688
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 case CMD_OPEN_CHANNEL:
690 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800691 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800692 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 if (uiccCard == null) {
694 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800695 request.result = new IccOpenLogicalChannelResponse(-1,
696 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700697 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700698 } else {
699 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800700 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
701 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700702 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 break;
704
705 case EVENT_OPEN_CHANNEL_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 int[] result = (int[]) ar.result;
711 int channelId = result[0];
712 byte[] selectResponse = null;
713 if (result.length > 1) {
714 selectResponse = new byte[result.length - 1];
715 for (int i = 1; i < result.length; ++i) {
716 selectResponse[i - 1] = (byte) result[i];
717 }
718 }
719 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700720 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 if (ar.result == null) {
723 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 if (ar.exception != null) {
726 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
727 }
728
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700729 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700730 if (ar.exception instanceof CommandException) {
731 CommandException.Error error =
732 ((CommandException) (ar.exception)).getCommandError();
733 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700734 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700735 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700736 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 }
738 }
739 openChannelResp = new IccOpenLogicalChannelResponse(
740 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700742 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 break;
745
746 case CMD_CLOSE_CHANNEL:
747 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800748 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 if (uiccCard == null) {
750 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900751 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700753 } else {
754 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
755 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
756 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 break;
758
759 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800760 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
761 break;
762
763 case CMD_NV_READ_ITEM:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
767 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800768 break;
769
770 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 ar = (AsyncResult) msg.obj;
772 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800773 if (ar.exception == null && ar.result != null) {
774 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800776 request.result = "";
777 if (ar.result == null) {
778 loge("nvReadItem: Empty response");
779 } else if (ar.exception instanceof CommandException) {
780 loge("nvReadItem: CommandException: " +
781 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800783 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 }
785 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 break;
788
Jake Hambye994d462014-02-03 13:10:13 -0800789 case CMD_NV_WRITE_ITEM:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
792 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700794 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800795 break;
796
797 case EVENT_NV_WRITE_ITEM_DONE:
798 handleNullReturnEvent(msg, "nvWriteItem");
799 break;
800
801 case CMD_NV_WRITE_CDMA_PRL:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800804 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800805 break;
806
807 case EVENT_NV_WRITE_CDMA_PRL_DONE:
808 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
809 break;
810
chen xu6dac5ab2018-10-26 17:39:23 -0700811 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800812 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700813 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800814 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800815 break;
816
chen xu6dac5ab2018-10-26 17:39:23 -0700817 case EVENT_RESET_MODEM_CONFIG_DONE:
818 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800819 break;
820
Sooraj Sasindran37444802020-08-11 10:40:43 -0700821 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
822 request = (MainThreadRequest) msg.obj;
823 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
824 request);
825 Phone phone = getPhoneFromRequest(request);
826 if (phone != null) {
827 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
828 } else {
829 loge("isNRDualConnectivityEnabled: No phone object");
830 request.result = false;
831 notifyRequester(request);
832 }
833 break;
834 }
835
836 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result;
841 } else {
842 // request.result must be set to something non-null
843 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700844 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700845 request.result = ar.result;
846 } else {
847 request.result = false;
848 }
849 if (ar.result == null) {
850 loge("isNRDualConnectivityEnabled: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("isNRDualConnectivityEnabled: CommandException: "
853 + ar.exception);
854 } else {
855 loge("isNRDualConnectivityEnabled: Unknown exception");
856 }
857 }
858 notifyRequester(request);
859 break;
860
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700861 case CMD_IS_VONR_ENABLED: {
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
864 request);
865 Phone phone = getPhoneFromRequest(request);
866 if (phone != null) {
867 phone.isVoNrEnabled(onCompleted, request.workSource);
868 } else {
869 loge("isVoNrEnabled: No phone object");
870 request.result = false;
871 notifyRequester(request);
872 }
873 break;
874 }
875
876 case EVENT_IS_VONR_ENABLED_DONE:
877 ar = (AsyncResult) msg.obj;
878 request = (MainThreadRequest) ar.userObj;
879 if (ar.exception == null && ar.result != null) {
880 request.result = ar.result;
881 } else {
882 // request.result must be set to something non-null
883 // for the calling thread to unblock
884 if (ar.result != null) {
885 request.result = ar.result;
886 } else {
887 request.result = false;
888 }
889 if (ar.result == null) {
890 loge("isVoNrEnabled: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("isVoNrEnabled: CommandException: "
893 + ar.exception);
894 } else {
895 loge("isVoNrEnabled: Unknown exception");
896 }
897 }
898 notifyRequester(request);
899 break;
900
Sooraj Sasindran37444802020-08-11 10:40:43 -0700901 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
902 request = (MainThreadRequest) msg.obj;
903 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
904 Phone phone = getPhoneFromRequest(request);
905 if (phone != null) {
906 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
907 request.workSource);
908 } else {
909 loge("enableNrDualConnectivity: No phone object");
910 request.result =
911 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
912 notifyRequester(request);
913 }
914 break;
915 }
916
917 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
918 ar = (AsyncResult) msg.obj;
919 request = (MainThreadRequest) ar.userObj;
920 if (ar.exception == null) {
921 request.result =
922 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
923 } else {
924 request.result =
925 TelephonyManager
926 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
927 if (ar.exception instanceof CommandException) {
928 CommandException.Error error =
929 ((CommandException) (ar.exception)).getCommandError();
930 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
931 request.result =
932 TelephonyManager
933 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000934 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
935 request.result =
936 TelephonyManager
937 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700938 }
939 loge("enableNrDualConnectivity" + ": CommandException: "
940 + ar.exception);
941 } else {
942 loge("enableNrDualConnectivity" + ": Unknown exception");
943 }
944 }
945 notifyRequester(request);
946 break;
947 }
948
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700949 case CMD_ENABLE_VONR: {
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
952 Phone phone = getPhoneFromRequest(request);
953 if (phone != null) {
954 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
955 request.workSource);
956 } else {
957 loge("setVoNrEnabled: No phone object");
958 request.result =
959 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
960 notifyRequester(request);
961 }
962 break;
963 }
964
965 case EVENT_ENABLE_VONR_DONE: {
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 if (ar.exception == null) {
969 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
970 } else {
971 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
972 if (ar.exception instanceof CommandException) {
973 CommandException.Error error =
974 ((CommandException) (ar.exception)).getCommandError();
975 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
976 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
977 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
978 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
979 } else {
980 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
981 }
982 loge("setVoNrEnabled" + ": CommandException: "
983 + ar.exception);
984 } else {
985 loge("setVoNrEnabled" + ": Unknown exception");
986 }
987 }
988 notifyRequester(request);
989 break;
990 }
991
SongFerngWang3ef3e072020-12-21 16:41:52 +0800992 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800993 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800994 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
995 request);
996 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800997 break;
998
SongFerngWang3ef3e072020-12-21 16:41:52 +0800999 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception == null && ar.result != null) {
1003 request.result = ar.result; // Integer
1004 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301005 // request.result must be set to something non-null
1006 // for the calling thread to unblock
1007 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001008 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 loge("getAllowedNetworkTypesBitmask: CommandException: "
1012 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001014 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 }
1016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 break;
1019
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001021 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001022 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1023 request);
1024 Pair<Integer, Long> reasonWithNetworkTypes =
1025 (Pair<Integer, Long>) request.argument;
1026 getPhoneFromRequest(request).setAllowedNetworkTypes(
1027 reasonWithNetworkTypes.first,
1028 reasonWithNetworkTypes.second,
1029 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001030 break;
1031
SongFerngWang3ef3e072020-12-21 16:41:52 +08001032 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1033 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 break;
1035
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001036 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1037 request = (MainThreadRequest)msg.obj;
1038 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001039 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001040 break;
1041
1042 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1043 ar = (AsyncResult)msg.obj;
1044 request = (MainThreadRequest)ar.userObj;
1045 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001046 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001047 break;
1048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001049 case CMD_SET_VOICEMAIL_NUMBER:
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1052 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001053 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1054 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001055 break;
1056
1057 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1058 handleNullReturnEvent(msg, "setVoicemailNumber");
1059 break;
1060
Stuart Scott54788802015-03-30 13:18:01 -07001061 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1062 request = (MainThreadRequest) msg.obj;
1063 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1064 request);
1065 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1066 break;
1067
1068 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1069 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1070 break;
1071
Shishir Agrawal302c8692015-06-19 13:49:39 -07001072 case CMD_PERFORM_NETWORK_SCAN:
1073 request = (MainThreadRequest) msg.obj;
1074 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1075 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1076 break;
1077
Hall Liu27d24262020-09-18 19:04:59 -07001078 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001081 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1082 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1083 request.argument;
1084 int callForwardingReason = args.first;
1085 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001086 break;
Hall Liu27d24262020-09-18 19:04:59 -07001087 }
1088 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001091 TelephonyManager.CallForwardingInfoCallback callback =
1092 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1093 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001095 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001096 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1097 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1098 // Service Class is a bit mask per 3gpp 27.007. Search for
1099 // any service for voice call.
1100 if ((callForwardInfo.serviceClass
1101 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001102 callForwardingInfo = new CallForwardingInfo(true,
1103 callForwardInfo.reason,
1104 callForwardInfo.number,
1105 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001106 break;
1107 }
1108 }
1109 // Didn't find a call forward info for voice call.
1110 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001111 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1112 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001113 }
Hall Liu27d24262020-09-18 19:04:59 -07001114 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001115 } else {
1116 if (ar.result == null) {
1117 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1118 }
1119 if (ar.exception != null) {
1120 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1121 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001122 int errorCode = TelephonyManager
1123 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001128 errorCode = TelephonyManager
1129 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001130 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001131 errorCode = TelephonyManager
1132 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
1134 }
Hall Liu27d24262020-09-18 19:04:59 -07001135 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137 break;
Hall Liu27d24262020-09-18 19:04:59 -07001138 }
Shuo Qian4a594052020-01-23 11:59:30 -08001139
Hall Liu27d24262020-09-18 19:04:59 -07001140 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 request = (MainThreadRequest) msg.obj;
1142 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001143 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001144 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001145 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1146 request.argument).first;
1147 request.phone.setCallForwardingOption(
1148 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001149 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001150 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001151 callForwardingInfoToSet.getReason(),
1152 callForwardingInfoToSet.getNumber(),
1153 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1154 break;
Hall Liu27d24262020-09-18 19:04:59 -07001155 }
Shuo Qian4a594052020-01-23 11:59:30 -08001156
Hall Liu27d24262020-09-18 19:04:59 -07001157 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001160 Consumer<Integer> callback =
1161 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1162 request.argument).second;
1163 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001164 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001165 int errorCode = TelephonyManager.CallForwardingInfoCallback
1166 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001167 if (ar.exception instanceof CommandException) {
1168 CommandException.Error error =
1169 ((CommandException) (ar.exception)).getCommandError();
1170 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001171 errorCode = TelephonyManager.CallForwardingInfoCallback
1172 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001173 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001174 errorCode = TelephonyManager.CallForwardingInfoCallback
1175 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001176 }
1177 }
1178 callback.accept(errorCode);
1179 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001180 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 }
Shuo Qian4a594052020-01-23 11:59:30 -08001182 break;
Hall Liu27d24262020-09-18 19:04:59 -07001183 }
Shuo Qian4a594052020-01-23 11:59:30 -08001184
Hall Liu27d24262020-09-18 19:04:59 -07001185 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1188 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1189 break;
Hall Liu27d24262020-09-18 19:04:59 -07001190 }
Shuo Qian4a594052020-01-23 11:59:30 -08001191
Hall Liu27d24262020-09-18 19:04:59 -07001192 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001195 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1197 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001198 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 // Service Class is a bit mask per 3gpp 27.007.
1200 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 if (callForwardResults.length > 1
1202 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001203 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001204 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001205 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1206 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001208 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 }
1210 } else {
1211 if (ar.result == null) {
1212 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1213 }
1214 if (ar.exception != null) {
1215 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1216 }
1217 if (ar.exception instanceof CommandException) {
1218 CommandException.Error error =
1219 ((CommandException) (ar.exception)).getCommandError();
1220 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1221 callForwardingStatus =
1222 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1223 }
1224 }
1225 }
Hall Liu27d24262020-09-18 19:04:59 -07001226 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001227 break;
Hall Liu27d24262020-09-18 19:04:59 -07001228 }
Shuo Qian4a594052020-01-23 11:59:30 -08001229
Hall Liu27d24262020-09-18 19:04:59 -07001230 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001231 request = (MainThreadRequest) msg.obj;
1232 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001233 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1234 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 break;
Hall Liu27d24262020-09-18 19:04:59 -07001236 }
Shuo Qian4a594052020-01-23 11:59:30 -08001237
Hall Liu27d24262020-09-18 19:04:59 -07001238 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001239 ar = (AsyncResult) msg.obj;
1240 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001241 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1242 Consumer<Integer> callback =
1243 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1244 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001245 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001246 if (ar.exception instanceof CommandException) {
1247 CommandException.Error error =
1248 ((CommandException) (ar.exception)).getCommandError();
1249 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1251 } else {
1252 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1253 }
1254 } else {
1255 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1256 }
1257 } else {
1258 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1259 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001263 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1264 ar = (AsyncResult) msg.obj;
1265 request = (MainThreadRequest) ar.userObj;
1266 CellNetworkScanResult cellScanResult;
1267 if (ar.exception == null && ar.result != null) {
1268 cellScanResult = new CellNetworkScanResult(
1269 CellNetworkScanResult.STATUS_SUCCESS,
1270 (List<OperatorInfo>) ar.result);
1271 } else {
1272 if (ar.result == null) {
1273 loge("getCellNetworkScanResults: Empty response");
1274 }
1275 if (ar.exception != null) {
1276 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1277 }
1278 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1279 if (ar.exception instanceof CommandException) {
1280 CommandException.Error error =
1281 ((CommandException) (ar.exception)).getCommandError();
1282 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1283 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1284 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1285 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1286 }
1287 }
1288 cellScanResult = new CellNetworkScanResult(errorCode, null);
1289 }
1290 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001291 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001292 break;
1293
1294 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1295 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001296 ManualNetworkSelectionArgument selArg =
1297 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001298 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1299 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001300 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1301 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001302 break;
1303
1304 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
1307 if (ar.exception == null) {
1308 request.result = true;
1309 } else {
1310 request.result = false;
1311 loge("setNetworkSelectionModeManual " + ar.exception);
1312 }
1313 notifyRequester(request);
1314 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001315 break;
1316
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001317 case CMD_GET_MODEM_ACTIVITY_INFO:
1318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001320 if (defaultPhone != null) {
1321 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001322 } else {
1323 ResultReceiver result = (ResultReceiver) request.argument;
1324 Bundle bundle = new Bundle();
1325 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001326 new ModemActivityInfo(0, 0, 0,
1327 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001328 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001329 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001330 break;
1331
Hall Liud0f208c2020-10-14 16:54:44 -07001332 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001335 ResultReceiver result = (ResultReceiver) request.argument;
1336
Hall Liud0f208c2020-10-14 16:54:44 -07001337 ModemActivityInfo ret = null;
1338 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001339 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001340 // Update the last modem activity info and the result of the request.
1341 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1342 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001343 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001344 int[] txTimeMs = info.getTransmitTimeMillis();
1345 int[] lastModemTxTimeMs = mLastModemActivityInfo
1346 .getTransmitTimeMillis();
1347 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1348 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1349 }
Hall Liu49656c02020-10-09 19:00:11 -07001350 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001351 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1352 + mLastModemActivityInfo.getSleepTimeMillis());
1353 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1354 + mLastModemActivityInfo.getIdleTimeMillis());
1355 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1356 mLastModemActivityInfo.setReceiveTimeMillis(
1357 info.getReceiveTimeMillis()
1358 + mLastModemActivityInfo.getReceiveTimeMillis());
1359 }
Hall Liu49656c02020-10-09 19:00:11 -07001360 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001361 mLastModemActivityInfo.getSleepTimeMillis(),
1362 mLastModemActivityInfo.getIdleTimeMillis(),
1363 mLastModemActivityInfo.getTransmitTimeMillis(),
1364 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001365 } else {
1366 if (ar.result == null) {
1367 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001368 error = TelephonyManager.ModemActivityInfoException
1369 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001370 } else if (ar.exception instanceof CommandException) {
1371 loge("queryModemActivityInfo: CommandException: " +
1372 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001373 error = TelephonyManager.ModemActivityInfoException
1374 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001375 } else {
1376 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001377 error = TelephonyManager.ModemActivityInfoException
1378 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001379 }
1380 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001381 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001382 if (ret != null) {
1383 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1384 } else {
1385 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1386 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001387 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001390 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001391
Meng Wang1a7c35a2016-05-05 20:56:15 -07001392 case CMD_SET_ALLOWED_CARRIERS:
1393 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001394 CarrierRestrictionRules argument =
1395 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001396 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001397 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001398 break;
1399
1400 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 if (ar.exception == null && ar.result != null) {
1404 request.result = ar.result;
1405 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001406 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1407 if (ar.exception instanceof CommandException) {
1408 loge("setAllowedCarriers: CommandException: " + ar.exception);
1409 CommandException.Error error =
1410 ((CommandException) (ar.exception)).getCommandError();
1411 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1412 request.result =
1413 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1414 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 } else {
1416 loge("setAllowedCarriers: Unknown exception");
1417 }
1418 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001419 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001420 break;
1421
1422 case CMD_GET_ALLOWED_CARRIERS:
1423 request = (MainThreadRequest) msg.obj;
1424 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001425 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001426 break;
1427
1428 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 if (ar.exception == null && ar.result != null) {
1432 request.result = ar.result;
1433 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001434 request.result = new IllegalStateException(
1435 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001436 if (ar.result == null) {
1437 loge("getAllowedCarriers: Empty response");
1438 } else if (ar.exception instanceof CommandException) {
1439 loge("getAllowedCarriers: CommandException: " +
1440 ar.exception);
1441 } else {
1442 loge("getAllowedCarriers: Unknown exception");
1443 }
1444 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001446 break;
1447
Nathan Haroldb3014052017-01-25 15:57:32 -08001448 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null && ar.result != null) {
1452 request.result = ar.result;
1453 } else {
1454 request.result = new IllegalArgumentException(
1455 "Failed to retrieve Forbidden Plmns");
1456 if (ar.result == null) {
1457 loge("getForbiddenPlmns: Empty response");
1458 } else {
1459 loge("getForbiddenPlmns: Unknown exception");
1460 }
1461 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001462 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001463 break;
1464
1465 case CMD_GET_FORBIDDEN_PLMNS:
1466 request = (MainThreadRequest) msg.obj;
1467 uiccCard = getUiccCardFromRequest(request);
1468 if (uiccCard == null) {
1469 loge("getForbiddenPlmns() UiccCard is null");
1470 request.result = new IllegalArgumentException(
1471 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001472 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001473 break;
1474 }
1475 Integer appType = (Integer) request.argument;
1476 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1477 if (uiccApp == null) {
1478 loge("getForbiddenPlmns() no app with specified type -- "
1479 + appType);
1480 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001482 break;
1483 } else {
1484 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1485 + " specified type -- " + appType);
1486 }
1487 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1488 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1489 onCompleted);
1490 break;
1491
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001492 case CMD_SWITCH_SLOTS:
1493 request = (MainThreadRequest) msg.obj;
1494 int[] physicalSlots = (int[]) request.argument;
1495 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1496 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1497 break;
1498
1499 case EVENT_SWITCH_SLOTS_DONE:
1500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 notifyRequester(request);
1504 break;
1505 case CMD_GET_NETWORK_SELECTION_MODE:
1506 request = (MainThreadRequest) msg.obj;
1507 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1508 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1509 break;
1510
1511 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 if (ar.exception != null) {
1515 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1516 } else {
1517 int mode = ((int[]) ar.result)[0];
1518 if (mode == 0) {
1519 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1520 } else {
1521 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1522 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
1525 break;
1526 case CMD_GET_CDMA_ROAMING_MODE:
1527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1529 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1530 break;
1531 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception != null) {
1535 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1536 } else {
1537 request.result = ((int[]) ar.result)[0];
1538 }
1539 notifyRequester(request);
1540 break;
1541 case CMD_SET_CDMA_ROAMING_MODE:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1544 int mode = (int) request.argument;
1545 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1546 break;
1547 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 request.result = ar.exception == null;
1551 notifyRequester(request);
1552 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001553 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1554 request = (MainThreadRequest) msg.obj;
1555 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1556 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1557 break;
1558 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 if (ar.exception != null) {
1562 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1563 } else {
1564 request.result = ((int[]) ar.result)[0];
1565 }
1566 notifyRequester(request);
1567 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1569 request = (MainThreadRequest) msg.obj;
1570 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1571 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001572 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1573 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001574 break;
1575 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 request.result = ar.exception == null;
1579 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001580 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001581 case CMD_GET_ALL_CELL_INFO:
1582 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001584 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001585 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001586 case EVENT_GET_ALL_CELL_INFO_DONE:
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001589 // If a timeout occurs, the response will be null
1590 request.result = (ar.exception == null && ar.result != null)
1591 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001592 synchronized (request) {
1593 request.notifyAll();
1594 }
1595 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001596 case CMD_REQUEST_CELL_INFO_UPDATE:
1597 request = (MainThreadRequest) msg.obj;
1598 request.phone.requestCellInfoUpdate(request.workSource,
1599 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1600 break;
1601 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1605 try {
1606 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001607 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001608 cb.onError(
1609 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1610 ar.exception.getClass().getName(),
1611 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001614 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001615 } else {
1616 // use the result as returned
1617 cb.onCellInfo((List<CellInfo>) ar.result);
1618 }
1619 } catch (RemoteException re) {
1620 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1621 }
1622 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001623 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001624 request = (MainThreadRequest) msg.obj;
1625 WorkSource ws = (WorkSource) request.argument;
1626 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001627 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001628 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001629 }
1630 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null) {
1634 request.result = ar.result;
1635 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001636 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001637 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001638 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001639 }
1640
1641 synchronized (request) {
1642 request.notifyAll();
1643 }
1644 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001645 }
chen xu6dac5ab2018-10-26 17:39:23 -07001646 case CMD_MODEM_REBOOT:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001649 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001650 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001651 case EVENT_CMD_MODEM_REBOOT_DONE:
1652 handleNullReturnEvent(msg, "rebootModem");
1653 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001654 case CMD_REQUEST_ENABLE_MODEM:
1655 request = (MainThreadRequest) msg.obj;
1656 boolean enable = (boolean) request.argument;
1657 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001658 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001659 PhoneConfigurationManager.getInstance()
1660 .enablePhone(request.phone, enable, onCompleted);
1661 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001662 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001666 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001667 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001668 if ((boolean) request.result) {
1669 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1670 updateModemStateMetrics();
1671 } else {
1672 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1673 + ar.exception);
1674 }
1675 notifyRequester(request);
1676 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001677 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001678 case CMD_GET_MODEM_STATUS:
1679 request = (MainThreadRequest) msg.obj;
1680 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1681 PhoneConfigurationManager.getInstance()
1682 .getPhoneStatusFromModem(request.phone, onCompleted);
1683 break;
1684 case EVENT_GET_MODEM_STATUS_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 int id = request.phone.getPhoneId();
1688 if (ar.exception == null && ar.result != null) {
1689 request.result = ar.result;
1690 //update the cache as modem status has changed
1691 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1692 (boolean) request.result);
1693 } else {
1694 // Return true if modem status cannot be retrieved. For most cases,
1695 // modem status is on. And for older version modems, GET_MODEM_STATUS
1696 // and disable modem are not supported. Modem is always on.
1697 // TODO: this should be fixed in R to support a third
1698 // status UNKNOWN b/131631629
1699 request.result = true;
1700 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1701 + ar.exception);
1702 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001703 notifyRequester(request);
1704 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001705 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1708 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1709 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1710 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1711 break;
1712 }
1713 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1717 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1718 args.second.accept(ar.exception == null);
1719 notifyRequester(request);
1720 break;
1721 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1725 Phone phone = getPhoneFromRequest(request);
1726 if (phone != null) {
1727 phone.getSystemSelectionChannels(onCompleted);
1728 } else {
1729 loge("getSystemSelectionChannels: No phone object");
1730 request.result = new ArrayList<RadioAccessSpecifier>();
1731 notifyRequester(request);
1732 }
1733 break;
1734 }
1735 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 if (ar.exception == null && ar.result != null) {
1739 request.result = ar.result;
1740 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001741 request.result = new IllegalStateException(
1742 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001743 if (ar.result == null) {
1744 loge("getSystemSelectionChannels: Empty response");
1745 } else {
1746 loge("getSystemSelectionChannels: Unknown exception");
1747 }
1748 }
1749 notifyRequester(request);
1750 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001751 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 if (ar.exception == null && ar.result != null) {
1755 request.result = ar.result;
1756 } else {
1757 request.result = -1;
1758 loge("Failed to set Forbidden Plmns");
1759 if (ar.result == null) {
1760 loge("setForbidenPlmns: Empty response");
1761 } else if (ar.exception != null) {
1762 loge("setForbiddenPlmns: Exception: " + ar.exception);
1763 request.result = -1;
1764 } else {
1765 loge("setForbiddenPlmns: Unknown exception");
1766 }
1767 }
1768 notifyRequester(request);
1769 break;
1770 case CMD_SET_FORBIDDEN_PLMNS:
1771 request = (MainThreadRequest) msg.obj;
1772 uiccCard = getUiccCardFromRequest(request);
1773 if (uiccCard == null) {
1774 loge("setForbiddenPlmns: UiccCard is null");
1775 request.result = -1;
1776 notifyRequester(request);
1777 break;
1778 }
1779 Pair<Integer, List<String>> setFplmnsArgs =
1780 (Pair<Integer, List<String>>) request.argument;
1781 appType = setFplmnsArgs.first;
1782 List<String> fplmns = setFplmnsArgs.second;
1783 uiccApp = uiccCard.getApplicationByType(appType);
1784 if (uiccApp == null) {
1785 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1786 request.result = -1;
1787 loge("Failed to get UICC App");
1788 notifyRequester(request);
1789 } else {
1790 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1791 ((SIMRecords) uiccApp.getIccRecords())
1792 .setForbiddenPlmns(onCompleted, fplmns);
1793 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001794 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001795 case CMD_ERASE_MODEM_CONFIG:
1796 request = (MainThreadRequest) msg.obj;
1797 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1798 defaultPhone.eraseModemConfig(onCompleted);
1799 break;
1800 case EVENT_ERASE_MODEM_CONFIG_DONE:
1801 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001802 break;
zoey chene02881a2019-12-30 16:11:23 +08001803
Kai Shif70f46f2021-03-03 13:59:46 -08001804 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1805 request = (MainThreadRequest) msg.obj;
1806 request.result = defaultPhone.eraseDataInSharedPreferences();
1807 notifyRequester(request);
1808 break;
1809
zoey chene02881a2019-12-30 16:11:23 +08001810 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1811 request = (MainThreadRequest) msg.obj;
1812 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1813 Pair<String, String> changed = (Pair<String, String>) request.argument;
1814 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1815 changed.first, changed.second, onCompleted);
1816 break;
1817 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null) {
1821 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001822 // If the operation is successful, update the PIN storage
1823 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1824 int phoneId = getPhoneFromRequest(request).getPhoneId();
Grace Jia59437e82021-09-21 15:47:32 -07001825 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1826 pinStorage.storePin(passwords.second, phoneId,
1827 pinStorage.getIccid(phoneId));
zoey chene02881a2019-12-30 16:11:23 +08001828 } else {
1829 request.result = msg.arg1;
1830 }
1831 notifyRequester(request);
1832 break;
1833
Michele Berionne5e411512020-11-13 02:36:59 +00001834 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001835 request = (MainThreadRequest) msg.obj;
1836 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1837 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1838 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1839 enabled.first, enabled.second, onCompleted);
1840 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001841 }
zoey chene02881a2019-12-30 16:11:23 +08001842 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 if (ar.exception == null) {
1846 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001847 // If the operation is successful, update the PIN storage
1848 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1849 int phoneId = getPhoneFromRequest(request).getPhoneId();
1850 if (enabled.first) {
Grace Jia59437e82021-09-21 15:47:32 -07001851 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1852 pinStorage.storePin(enabled.second, phoneId,
1853 pinStorage.getIccid(phoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00001854 } else {
1855 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1856 }
zoey chene02881a2019-12-30 16:11:23 +08001857 } else {
1858 request.result = msg.arg1;
1859 }
Michele Berionne5e411512020-11-13 02:36:59 +00001860
1861
zoey chene02881a2019-12-30 16:11:23 +08001862 notifyRequester(request);
1863 break;
1864
Peter Wangdafb9ac2020-01-15 14:13:38 -08001865 case MSG_NOTIFY_USER_ACTIVITY:
1866 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001867 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001868 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1869 getDefaultPhone().getContext().sendBroadcastAsUser(
1870 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1871 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001872
1873 case CMD_SET_DATA_THROTTLING: {
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1876 DataThrottlingRequest dataThrottlingRequest =
1877 (DataThrottlingRequest) request.argument;
1878 Phone phone = getPhoneFromRequest(request);
1879 if (phone != null) {
1880 phone.setDataThrottling(onCompleted,
1881 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1882 dataThrottlingRequest.getCompletionDurationMillis());
1883 } else {
1884 loge("setDataThrottling: No phone object");
1885 request.result =
1886 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1887 notifyRequester(request);
1888 }
1889
1890 break;
1891 }
1892 case EVENT_SET_DATA_THROTTLING_DONE:
1893 ar = (AsyncResult) msg.obj;
1894 request = (MainThreadRequest) ar.userObj;
1895
1896 if (ar.exception == null) {
1897 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1898 } else if (ar.exception instanceof CommandException) {
1899 loge("setDataThrottling: CommandException: " + ar.exception);
1900 CommandException.Error error =
1901 ((CommandException) (ar.exception)).getCommandError();
1902
1903 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1904 request.result = TelephonyManager
1905 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1906 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1907 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001908 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1909 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001910 } else {
1911 request.result =
1912 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1913 }
1914 } else {
1915 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1916 }
1917 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1918 notifyRequester(request);
1919 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001920
1921 case CMD_SET_SIM_POWER: {
1922 request = (MainThreadRequest) msg.obj;
1923 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1924 request = (MainThreadRequest) msg.obj;
1925 int stateToSet =
1926 ((Pair<Integer, IIntegerConsumer>)
1927 request.argument).first;
1928 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1929 break;
1930 }
1931 case EVENT_SET_SIM_POWER_DONE: {
1932 ar = (AsyncResult) msg.obj;
1933 request = (MainThreadRequest) ar.userObj;
1934 IIntegerConsumer callback =
1935 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1936 if (ar.exception != null) {
1937 loge("setSimPower exception: " + ar.exception);
1938 int errorCode = TelephonyManager.CallForwardingInfoCallback
1939 .RESULT_ERROR_UNKNOWN;
1940 if (ar.exception instanceof CommandException) {
1941 CommandException.Error error =
1942 ((CommandException) (ar.exception)).getCommandError();
1943 if (error == CommandException.Error.SIM_ERR) {
1944 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1945 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1946 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1947 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1948 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1949 } else {
1950 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1951 }
1952 }
1953 try {
1954 callback.accept(errorCode);
1955 } catch (RemoteException e) {
1956 // Ignore if the remote process is no longer available to call back.
1957 Log.w(LOG_TAG, "setSimPower: callback not available.");
1958 }
1959 } else {
1960 try {
1961 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1962 } catch (RemoteException e) {
1963 // Ignore if the remote process is no longer available to call back.
1964 Log.w(LOG_TAG, "setSimPower: callback not available.");
1965 }
1966 }
1967 break;
1968 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001969 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1970 request = (MainThreadRequest) msg.obj;
1971
1972 final Phone phone = getPhoneFromRequest(request);
1973 if (phone == null || phone.getServiceStateTracker() == null) {
1974 request.result = new IllegalStateException("Phone or SST is null");
1975 notifyRequester(request);
1976 break;
1977 }
1978
1979 Pair<Integer, SignalStrengthUpdateRequest> pair =
1980 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1981 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1982 request);
1983 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1984 request.subId, pair.first /*callingUid*/,
1985 pair.second /*request*/, onCompleted);
1986 break;
1987 }
1988 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1989 ar = (AsyncResult) msg.obj;
1990 request = (MainThreadRequest) ar.userObj;
1991 // request.result will be the exception of ar if present, true otherwise.
1992 // Be cautious not to leave result null which will wait() forever
1993 request.result = ar.exception != null ? ar.exception : true;
1994 notifyRequester(request);
1995 break;
1996 }
1997 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1998 request = (MainThreadRequest) msg.obj;
1999
2000 Phone phone = getPhoneFromRequest(request);
2001 if (phone == null || phone.getServiceStateTracker() == null) {
2002 request.result = new IllegalStateException("Phone or SST is null");
2003 notifyRequester(request);
2004 break;
2005 }
2006
2007 Pair<Integer, SignalStrengthUpdateRequest> pair =
2008 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2009 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2010 request);
2011 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2012 request.subId, pair.first /*callingUid*/,
2013 pair.second /*request*/, onCompleted);
2014 break;
2015 }
2016 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2017 ar = (AsyncResult) msg.obj;
2018 request = (MainThreadRequest) ar.userObj;
2019 request.result = ar.exception != null ? ar.exception : true;
2020 notifyRequester(request);
2021 break;
2022 }
Jordan Liu109698e2020-11-24 14:50:34 -08002023
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002024 case CMD_GET_SLICING_CONFIG: {
2025 request = (MainThreadRequest) msg.obj;
2026 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2027 request.phone.getSlicingConfig(onCompleted);
2028 break;
2029 }
2030 case EVENT_GET_SLICING_CONFIG_DONE: {
2031 ar = (AsyncResult) msg.obj;
2032 request = (MainThreadRequest) ar.userObj;
2033 ResultReceiver result = (ResultReceiver) request.argument;
2034
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002035 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002036 Bundle bundle = new Bundle();
2037 int resultCode = 0;
2038 if (ar.exception != null) {
2039 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2040 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002041 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002042 } else if (ar.result == null) {
2043 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002044 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002045 } else {
2046 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002047 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2048 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002049 }
2050
2051 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002052 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002053 }
2054 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2055 result.send(resultCode, bundle);
2056 notifyRequester(request);
2057 break;
2058 }
2059
Michele Berionne5e411512020-11-13 02:36:59 +00002060 case CMD_PREPARE_UNATTENDED_REBOOT:
2061 request = (MainThreadRequest) msg.obj;
2062 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002063 UiccController.getInstance().getPinStorage()
2064 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002065 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
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002304 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2305 Phone phone = getPhoneFromRequest(request);
2306 return phone == null ? null :
2307 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2308 }
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) {
Grace Jia59437e82021-09-21 15:47:32 -07002553 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2554 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00002555 }
2556
Wink Saville9de0f752013-10-22 19:04:03 -07002557 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 }
2559 }
2560
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002561 /**
2562 * This method has been removed due to privacy and stability concerns.
2563 */
2564 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002566 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2567 return;
Wink Saville36469e72014-06-11 15:17:00 -07002568 }
2569
Nathan Harold1f889d82020-06-04 17:05:26 -07002570 @Override
2571 public void updateServiceLocationWithPackageName(String callingPackage) {
2572 mApp.getSystemService(AppOpsManager.class)
2573 .checkPackage(Binder.getCallingUid(), callingPackage);
2574
Nathan Haroldf096d982020-11-18 17:18:06 -08002575 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002576 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2577 // Callers targeting S have no business invoking this method.
2578 return;
2579 }
2580
2581 LocationAccessPolicy.LocationPermissionResult locationResult =
2582 LocationAccessPolicy.checkLocationPermission(mApp,
2583 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2584 .setCallingPackage(callingPackage)
2585 .setCallingFeatureId(null)
2586 .setCallingPid(Binder.getCallingPid())
2587 .setCallingUid(Binder.getCallingUid())
2588 .setMethod("updateServiceLocation")
2589 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2590 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2591 .build());
2592 // Apps that lack location permission have no business calling this method;
2593 // however, because no permission was declared in the public API, denials must
2594 // all be "soft".
2595 switch (locationResult) {
2596 case DENIED_HARD: /* fall through */
2597 case DENIED_SOFT:
2598 return;
2599 }
2600
2601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002604 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002606 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002613 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002614 @Override
2615 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002616 return isRadioOnWithFeature(callingPackage, null);
2617 }
2618
2619
2620 @Override
2621 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2622 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2623 callingFeatureId);
2624 }
2625
2626 @Deprecated
2627 @Override
2628 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2629 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002630 }
2631
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002633 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2634 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002636 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002637 return false;
2638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 return isRadioOnForSubscriber(subId);
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
2645 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002646 }
2647
2648 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
2652 if (phone != null) {
2653 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2654 } else {
2655 return false;
2656 }
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
2661
2662 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002663 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
Wink Saville36469e72014-06-11 15:17:00 -07002665
Wink Savilleb564aae2014-10-23 10:18:09 -07002666 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 final Phone phone = getPhone(subId);
2672 if (phone != null) {
2673 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Wink Saville36469e72014-06-11 15:17:00 -07002678 }
2679
2680 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002681 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002682 }
2683
Wink Savilleb564aae2014-10-23 10:18:09 -07002684 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone == null) {
2691 return false;
2692 }
2693 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2694 toggleRadioOnOffForSubscriber(subId);
2695 }
2696 return true;
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
Wink Saville36469e72014-06-11 15:17:00 -07002701
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002702 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002703 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002704 /*
2705 * If any of the Radios are available, it will need to be
2706 * shutdown. So return true if any Radio is available.
2707 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2711 Phone phone = PhoneFactory.getPhone(i);
2712 if (phone != null && phone.isRadioAvailable()) return true;
2713 }
2714 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2715 return false;
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002719 }
2720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002722 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 enforceModifyPermission();
2724
2725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2728 logv("Shutting down Phone " + i);
2729 shutdownRadioUsingPhoneId(i);
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 }
2734 }
2735
2736 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002737 Phone phone = PhoneFactory.getPhone(phoneId);
2738 if (phone != null && phone.isRadioAvailable()) {
2739 phone.shutdownRadio();
2740 }
2741 }
2742
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2749 if (defaultPhone != null) {
2750 defaultPhone.setRadioPower(turnOn);
2751 return true;
2752 } else {
2753 loge("There's no default phone.");
2754 return false;
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002758 }
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
Wink Savilleb564aae2014-10-23 10:18:09 -07002761 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone phone = getPhone(subId);
2767 if (phone != null) {
2768 phone.setRadioPower(turnOn);
2769 return true;
2770 } else {
2771 return false;
2772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777
Wink Saville36469e72014-06-11 15:17:00 -07002778 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 public boolean enableDataConnectivity() {
2781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 int subId = mSubscriptionController.getDefaultDataSubId();
2786 final Phone phone = getPhone(subId);
2787 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002788 phone.getDataEnabledSettings().setDataEnabled(
2789 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 return true;
2791 } else {
2792 return false;
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798
Wink Saville36469e72014-06-11 15:17:00 -07002799 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002800 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 public boolean disableDataConnectivity() {
2802 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 int subId = mSubscriptionController.getDefaultDataSubId();
2807 final Phone phone = getPhone(subId);
2808 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002809 phone.getDataEnabledSettings().setDataEnabled(
2810 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 return true;
2812 } else {
2813 return false;
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002821 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002826 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 } else {
2828 return false;
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 }
2834
2835 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002836 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
pkanwarae03a6b2016-11-06 20:37:09 -08002839 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840 enforceCallPermission();
2841
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2845 return;
2846 }
2847 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2848 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
pkanwar32d516d2016-10-14 19:37:38 -07002852 };
2853
Wink Savilleb564aae2014-10-23 10:18:09 -07002854 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2860 return false;
2861 }
2862 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
2867
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002868 /**
2869 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2870 * tag on getCallState Binder call.
2871 */
2872 @Deprecated
2873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002875 if (CompatChanges.isChangeEnabled(
2876 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2877 Binder.getCallingUid())) {
2878 // Do not allow this API to be called on API version 31+, it should only be
2879 // called on old apps using this Binder call directly.
2880 throw new SecurityException("This method can only be used for applications "
2881 + "targeting API version 30 or less.");
2882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 final long identity = Binder.clearCallingIdentity();
2884 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002885 Phone phone = getPhone(getDefaultSubscription());
2886 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2887 PhoneConstantConversions.convertCallState(phone.getState());
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
2890 }
2891 }
2892
2893 @Override
2894 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2895 if (CompatChanges.isChangeEnabled(
2896 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2897 Binder.getCallingUid())) {
2898 // Check READ_PHONE_STATE for API version 31+
2899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2900 featureId, "getCallStateForSubscription")) {
2901 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2902 + "targeting API level 31+.");
2903 }
2904 }
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2909 PhoneConstantConversions.convertCallState(phone.getState());
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002916 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002917 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2918 }
2919
2920 @Override
2921 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002924 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 if (phone != null) {
2926 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2927 } else {
2928 return PhoneConstantConversions.convertDataState(
2929 PhoneConstants.DataState.DISCONNECTED);
2930 }
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
2935
Sanket Padawe356d7632015-06-22 14:03:32 -07002936 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002937 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2939 }
2940
2941 @Override
2942 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 final long identity = Binder.clearCallingIdentity();
2944 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002945 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 if (phone != null) {
2947 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2948 } else {
2949 return TelephonyManager.DATA_ACTIVITY_NONE;
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
2956 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002957 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002958 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002959 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002960
2961 LocationAccessPolicy.LocationPermissionResult locationResult =
2962 LocationAccessPolicy.checkLocationPermission(mApp,
2963 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2964 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002965 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 .setCallingPid(Binder.getCallingPid())
2967 .setCallingUid(Binder.getCallingUid())
2968 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002969 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002970 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2971 .build());
2972 switch (locationResult) {
2973 case DENIED_HARD:
2974 throw new SecurityException("Not allowed to access cell location");
2975 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002976 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2977 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002978 }
2979
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002984 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002985 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Svetoslav64fad262015-04-14 14:35:21 -07002989 }
2990
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002992 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002993 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2994 // registered cell info, so return a NULL country instead.
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002997 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2998 // Get default phone in this case.
2999 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3000 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003001 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003003 if (phone == null) return "";
3004 ServiceStateTracker sst = phone.getServiceStateTracker();
3005 if (sst == null) return "";
3006 LocaleTracker lt = sst.getLocaleTracker();
3007 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003008 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003012 }
3013
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003014 /**
3015 * This method was removed due to potential issues caused by performing partial
3016 * updates of service state, and lack of a credible use case.
3017 *
3018 * This has the ability to break the telephony implementation by disabling notification of
3019 * changes in device connectivity. DO NOT USE THIS!
3020 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003021 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003022 public void enableLocationUpdates() {
3023 mApp.enforceCallingOrSelfPermission(
3024 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 }
3026
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003027 /**
3028 * This method was removed due to potential issues caused by performing partial
3029 * updates of service state, and lack of a credible use case.
3030 *
3031 * This has the ability to break the telephony implementation by disabling notification of
3032 * changes in device connectivity. DO NOT USE THIS!
3033 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 @Override
3035 public void disableLocationUpdates() {
3036 mApp.enforceCallingOrSelfPermission(
3037 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 }
3039
3040 @Override
3041 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003042 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3043 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003044 try {
3045 mApp.getSystemService(AppOpsManager.class)
3046 .checkPackage(Binder.getCallingUid(), callingPackage);
3047 } catch (SecurityException e) {
3048 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3049 throw e;
3050 }
3051
Nathan Haroldf096d982020-11-18 17:18:06 -08003052 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003053 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3054 throw new SecurityException(
3055 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3056 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003057
Jordan Liu1617b712019-07-10 15:06:26 -07003058 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3060 return null;
3061 }
Svetoslav64fad262015-04-14 14:35:21 -07003062
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003063 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003065 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003066 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067
Nathan Haroldf180aac2018-06-01 18:43:55 -07003068 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3069 for (CellInfo ci : info) {
3070 if (ci instanceof CellInfoGsm) {
3071 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3072 } else if (ci instanceof CellInfoWcdma) {
3073 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003076 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 }
3078
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003079 private List<CellInfo> getCachedCellInfo() {
3080 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3081 for (Phone phone : PhoneFactory.getPhones()) {
3082 List<CellInfo> info = phone.getAllCellInfo();
3083 if (info != null) cellInfos.addAll(info);
3084 }
3085 return cellInfos;
3086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087
3088 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003089 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003092
3093 LocationAccessPolicy.LocationPermissionResult locationResult =
3094 LocationAccessPolicy.checkLocationPermission(mApp,
3095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003098 .setCallingPid(Binder.getCallingPid())
3099 .setCallingUid(Binder.getCallingUid())
3100 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3103 .build());
3104 switch (locationResult) {
3105 case DENIED_HARD:
3106 throw new SecurityException("Not allowed to access cell info");
3107 case DENIED_SOFT:
3108 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Nathan Haroldf096d982020-11-18 17:18:06 -08003111 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003112 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3113 return getCachedCellInfo();
3114 }
3115
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003116 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003117 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3121 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003122 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003123 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 if (info != null) cellInfos.addAll(info);
3125 }
3126 return cellInfos;
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 }
3130 }
3131
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003132 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003133 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3134 String callingFeatureId) {
3135 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3136 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 }
3138
3139 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003140 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3141 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003142 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 }
3145
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3147 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003149 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003150
3151 LocationAccessPolicy.LocationPermissionResult locationResult =
3152 LocationAccessPolicy.checkLocationPermission(mApp,
3153 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3154 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003155 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003156 .setCallingPid(Binder.getCallingPid())
3157 .setCallingUid(Binder.getCallingUid())
3158 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003159 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3160 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003161 .build());
3162 switch (locationResult) {
3163 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003164 if (TelephonyPermissions
3165 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003166 // Safetynet logging for b/154934934
3167 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3168 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003169 throw new SecurityException("Not allowed to access cell info");
3170 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003171 if (TelephonyPermissions
3172 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003173 // Safetynet logging for b/154934934
3174 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3175 }
Nathan Harold5320c422019-05-09 10:26:08 -07003176 try {
3177 cb.onCellInfo(new ArrayList<CellInfo>());
3178 } catch (RemoteException re) {
3179 // Drop without consequences
3180 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003182 }
3183
Nathan Harolda939a962019-05-09 10:13:47 -07003184
3185 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003186 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3187
3188 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3189 }
3190
3191 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003193 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003194 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003198 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 }
3203
Shishir Agrawala9f32182016-04-12 12:00:16 -07003204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003205 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003206 Phone phone = PhoneFactory.getPhone(slotIndex);
3207 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003208 return null;
3209 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003210 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003211 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003212 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003213 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003214 return null;
3215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 return phone.getImei();
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003223 }
3224
3225 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003226 public String getTypeAllocationCodeForSlot(int slotIndex) {
3227 Phone phone = PhoneFactory.getPhone(slotIndex);
3228 String tac = null;
3229 if (phone != null) {
3230 String imei = phone.getImei();
3231 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3232 }
3233 return tac;
3234 }
3235
3236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003238 try {
3239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3240 } catch (SecurityException se) {
3241 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3242 throw new SecurityException("Package " + callingPackage + " does not belong to "
3243 + Binder.getCallingUid());
3244 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003245 Phone phone = PhoneFactory.getPhone(slotIndex);
3246 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003247 return null;
3248 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249
Jeff Davidson913390f2018-02-23 17:11:49 -08003250 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003251 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003252 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003253 return null;
3254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 return phone.getMeid();
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
Jack Yu2af8d712017-03-15 17:14:14 -07003262 }
3263
3264 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003265 public String getManufacturerCodeForSlot(int slotIndex) {
3266 Phone phone = PhoneFactory.getPhone(slotIndex);
3267 String manufacturerCode = null;
3268 if (phone != null) {
3269 String meid = phone.getMeid();
3270 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3271 }
3272 return manufacturerCode;
3273 }
3274
3275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003276 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3277 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003278 Phone phone = PhoneFactory.getPhone(slotIndex);
3279 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003280 return null;
3281 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 int subId = phone.getSubId();
3283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003284 mApp, subId, callingPackage, callingFeatureId,
3285 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 return null;
3287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 return phone.getDeviceSvn();
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003295 }
3296
fionaxu43304da2017-11-27 22:51:16 -08003297 @Override
3298 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 final Phone phone = getPhone(subId);
3302 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
fionaxu43304da2017-11-27 22:51:16 -08003306 }
3307
3308 @Override
3309 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 final Phone phone = getPhone(subId);
3313 return phone == null ? null : phone.getCarrierName();
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
fionaxu43304da2017-11-27 22:51:16 -08003317 }
3318
calvinpanffe225e2018-11-01 19:43:06 +08003319 @Override
chen xu0026ca62019-03-06 15:28:50 -08003320 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 final Phone phone = getPhone(subId);
3324 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003325 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
3329 }
3330
3331 @Override
chen xu0026ca62019-03-06 15:28:50 -08003332 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003336 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
chen xu651eec72018-11-11 19:03:44 -08003342 @Override
chen xu864e11c2018-12-06 22:10:03 -08003343 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3344 if (!isSubscriptionMccMnc) {
3345 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3346 }
chen xu651eec72018-11-11 19:03:44 -08003347 final Phone phone = PhoneFactory.getPhone(slotIndex);
3348 if (phone == null) {
3349 return TelephonyManager.UNKNOWN_CARRIER_ID;
3350 }
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
3357 }
3358
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003359 //
3360 // Internal helper methods.
3361 //
3362
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003363 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003364 * Make sure the caller is the calling package itself
3365 *
3366 * @throws SecurityException if the caller is not the calling package
3367 */
3368 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3369 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003370 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3371 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003372 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003373 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003374 } catch (PackageManager.NameNotFoundException e) {
3375 // packageUid is -1
3376 }
3377 if (packageUid != callingUid) {
3378 throw new SecurityException(message + ": Package " + callingPackage
3379 + " does not belong to " + callingUid);
3380 }
3381 }
3382
3383 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3385 *
3386 * @throws SecurityException if the caller does not have the required permission
3387 */
3388 private void enforceModifyPermission() {
3389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3390 }
3391
Shuo Qiancd19c462020-01-16 20:51:11 -08003392 /**
3393 * Make sure the caller is system.
3394 *
3395 * @throws SecurityException if the caller is not system.
3396 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003397 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003398 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3399 throw new SecurityException("Caller must be system");
3400 }
3401 }
3402
Shuo Qian3b6ee772019-11-13 17:43:31 -08003403 private void enforceActiveEmergencySessionPermission() {
3404 mApp.enforceCallingOrSelfPermission(
3405 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3406 }
3407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 /**
3409 * Make sure the caller has the CALL_PHONE permission.
3410 *
3411 * @throws SecurityException if the caller does not have the required permission
3412 */
3413 private void enforceCallPermission() {
3414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3415 }
3416
paulhu5a773602019-08-23 19:17:33 +08003417 private void enforceSettingsPermission() {
3418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003419 }
3420
Michele Berionne5e411512020-11-13 02:36:59 +00003421 private void enforceRebootPermission() {
3422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3423 }
3424
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 private String createTelUrl(String number) {
3426 if (TextUtils.isEmpty(number)) {
3427 return null;
3428 }
3429
Jake Hambye994d462014-02-03 13:10:13 -08003430 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
Ihab Awadf9e92732013-12-05 18:02:52 -08003433 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3435 }
3436
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003437 private static void logv(String msg) {
3438 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3439 }
3440
Ihab Awadf9e92732013-12-05 18:02:52 -08003441 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3443 }
3444
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003445 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003447 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003448 }
3449
Sanket Padawe356d7632015-06-22 14:03:32 -07003450 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003451 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 final Phone phone = PhoneFactory.getPhone(slotIndex);
3455 if (phone == null) {
3456 return PhoneConstants.PHONE_TYPE_NONE;
3457 } else {
3458 return phone.getPhoneType();
3459 }
3460 } finally {
3461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 }
3464
3465 /**
3466 * Returns the CDMA ERI icon index to display
3467 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003469 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3470 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3471 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003472 }
3473
Sanket Padawe356d7632015-06-22 14:03:32 -07003474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003475 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3476 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 mApp, subId, callingPackage, callingFeatureId,
3479 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003480 return -1;
3481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 final Phone phone = getPhone(subId);
3486 if (phone != null) {
3487 return phone.getCdmaEriIconIndex();
3488 } else {
3489 return -1;
3490 }
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494 }
3495
3496 /**
3497 * Returns the CDMA ERI icon mode,
3498 * 0 - ON
3499 * 1 - FLASHING
3500 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003502 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3503 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3504 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003505 }
3506
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3509 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 mApp, subId, callingPackage, callingFeatureId,
3512 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003513 return -1;
3514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 final Phone phone = getPhone(subId);
3519 if (phone != null) {
3520 return phone.getCdmaEriIconMode();
3521 } else {
3522 return -1;
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 }
3528
3529 /**
3530 * Returns the CDMA ERI text,
3531 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003533 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3534 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3535 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003536 }
3537
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003539 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3540 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 mApp, subId, callingPackage, callingFeatureId,
3543 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return null;
3545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone != null) {
3551 return phone.getCdmaEriText();
3552 } else {
3553 return null;
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
3560 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003561 * Returns the CDMA MDN.
3562 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003564 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3566 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 return phone.getLine1Number();
3573 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 return null;
3576 }
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003579 }
3580 }
3581
3582 /**
3583 * Returns the CDMA MIN.
3584 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003585 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003586 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3588 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 final Phone phone = getPhone(subId);
3593 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3594 return phone.getCdmaMin();
3595 } else {
3596 return null;
3597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003600 }
3601 }
3602
Hall Liud892bec2018-11-30 14:51:45 -08003603 @Override
3604 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3605 INumberVerificationCallback callback, String callingPackage) {
3606 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3607 != PERMISSION_GRANTED) {
3608 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3609 }
3610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3611
3612 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3613 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003614 throw new SecurityException("Calling package must be configured in the device config: "
3615 + "calling package: " + callingPackage
3616 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003617 }
3618
3619 if (range == null) {
3620 throw new NullPointerException("Range must be non-null");
3621 }
3622
3623 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003624 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003625
3626 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3627 }
3628
Junda Liuca05d5d2014-08-14 22:36:34 -07003629 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003630 * Returns true if CDMA provisioning needs to run.
3631 */
3632 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 final long identity = Binder.clearCallingIdentity();
3634 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 }
3640
3641 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003642 * Sets the voice mail number of a given subId.
3643 */
3644 @Override
3645 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003646 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3647 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3652 new Pair<String, String>(alphaTag, number), new Integer(subId));
3653 return success;
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003657 }
3658
Ta-wei Yen87c49842016-05-13 21:19:52 -07003659 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003660 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003662 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3663 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003664 if (!TextUtils.equals(callingPackage, systemDialer)) {
3665 throw new SecurityException("caller must be system dialer");
3666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3671 if (phoneAccountHandle == null) {
3672 return null;
3673 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003677 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003678 }
3679
3680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003681 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3682 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003685 mApp, subId, callingPackage, callingFeatureId,
3686 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003687 return null;
3688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003690 final long identity = Binder.clearCallingIdentity();
3691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003696 }
3697
3698 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003699 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3700 VisualVoicemailSmsFilterSettings settings) {
3701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003710 }
3711
3712 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003713 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003723 }
3724
3725 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003726 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3727 String callingPackage, int subId) {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 }
3738
3739 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003740 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003750 }
3751
3752 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003753 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3754 String callingAttributionTag, int subId, String number, int port, String text,
3755 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003757 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003758 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003759 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003760 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3761 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003762 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003763
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003764 /**
fionaxu0152e512016-11-14 13:36:14 -08003765 * Sets the voice activation state of a given subId.
3766 */
3767 @Override
3768 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3770 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771
3772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 final Phone phone = getPhone(subId);
3775 if (phone != null) {
3776 phone.setVoiceActivationState(activationState);
3777 } else {
3778 loge("setVoiceActivationState fails with invalid subId: " + subId);
3779 }
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003782 }
3783 }
3784
3785 /**
3786 * Sets the data activation state of a given subId.
3787 */
3788 @Override
3789 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 final Phone phone = getPhone(subId);
3796 if (phone != null) {
3797 phone.setDataActivationState(activationState);
3798 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003799 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003803 }
3804 }
3805
3806 /**
3807 * Returns the voice activation state of a given subId.
3808 */
3809 @Override
3810 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
fionaxu0152e512016-11-14 13:36:14 -08003813 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 if (phone != null) {
3817 return phone.getVoiceActivationState();
3818 } else {
3819 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003823 }
3824 }
3825
3826 /**
3827 * Returns the data activation state of a given subId.
3828 */
3829 @Override
3830 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832
fionaxu0152e512016-11-14 13:36:14 -08003833 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 if (phone != null) {
3837 return phone.getDataActivationState();
3838 } else {
3839 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003843 }
3844 }
3845
3846 /**
Wink Saville36469e72014-06-11 15:17:00 -07003847 * Returns the unread count of voicemails for a subId
3848 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3851 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 mApp, subId, callingPackage, callingFeatureId,
3854 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003855 return 0;
3856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
3860 if (phone != null) {
3861 return phone.getVoiceMessageCount();
3862 } else {
3863 return 0;
3864 }
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 }
3869
3870 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003871 * returns true, if the device is in a state where both voice and data
3872 * are supported simultaneously. This can change based on location or network condition.
3873 */
3874 @Override
3875 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003883 }
3884
3885 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003886 * Send the dialer code if called from the current default dialer or the caller has
3887 * carrier privilege.
3888 * @param inputCode The dialer code to send
3889 */
3890 @Override
3891 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003892 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003894 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3895 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003896 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003897 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003898 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003903 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
3906 }
fionaxu235cc5e2017-03-06 22:25:57 -08003907 }
3908
Pengquan Menga1bb6272018-09-06 09:59:22 -07003909 @Override
3910 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003911 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003912 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003913 mApp, subId, "getNetworkSelectionMode");
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 if (!isActiveSubscription(subId)) {
3917 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3918 }
3919 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003923 }
3924
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003926 public boolean isInEmergencySmsMode() {
3927 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 for (Phone phone : PhoneFactory.getPhones()) {
3931 if (phone.isInEmergencySmsMode()) {
3932 return true;
3933 }
3934 }
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
3937 }
3938 return false;
3939 }
3940
shilu366312e2019-12-17 09:28:10 -08003941 /**
3942 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3943 * @param subId The subscription to use to check the configuration.
3944 * @param c The callback that will be used to send the result.
3945 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003947 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3948 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003949 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003950 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003951
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003952 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3953 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3954 "IMS not available on device.");
3955 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 final long token = Binder.clearCallingIdentity();
3957 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003958 int slotId = getSlotIndexOrException(subId);
3959 verifyImsMmTelConfiguredOrThrow(slotId);
3960 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003961 } catch (ImsException e) {
3962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 } finally {
3964 Binder.restoreCallingIdentity(token);
3965 }
3966 }
3967
shilu366312e2019-12-17 09:28:10 -08003968 /**
3969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3970 * @param subId The subscription to use to check the configuration.
3971 * @param c The callback that will be used to send the result.
3972 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003974 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003976 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003977 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3978 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3979 }
Meng Wangafbc5852019-09-19 17:37:13 -07003980 final long token = Binder.clearCallingIdentity();
3981 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3983 .removeRegistrationCallbackForSubscription(c, subId);
3984 } catch (ImsException e) {
3985 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3986 + "is inactive, ignoring unregister.");
3987 // If the subscription is no longer active, just return, since the callback
3988 // will already have been removed internally.
3989 } finally {
3990 Binder.restoreCallingIdentity(token);
3991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 }
3993
Brad Ebingera34a6c22019-10-22 17:36:18 -07003994 /**
3995 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3996 */
3997 @Override
3998 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3999 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4000 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4001 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4002 "IMS not available on device.");
4003 }
4004 final long token = Binder.clearCallingIdentity();
4005 try {
4006 Phone phone = getPhone(subId);
4007 if (phone == null) {
4008 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4009 + subId + "'");
4010 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4011 }
4012 phone.getImsRegistrationState(regState -> {
4013 try {
4014 consumer.accept((regState == null)
4015 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4016 } catch (RemoteException e) {
4017 // Ignore if the remote process is no longer available to call back.
4018 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4019 }
4020 });
4021 } finally {
4022 Binder.restoreCallingIdentity(token);
4023 }
4024 }
4025
4026 /**
4027 * Get the transport type for the IMS service registration state.
4028 */
4029 @Override
4030 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004031 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004032 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004033 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4034 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4035 "IMS not available on device.");
4036 }
4037 final long token = Binder.clearCallingIdentity();
4038 try {
4039 Phone phone = getPhone(subId);
4040 if (phone == null) {
4041 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4042 + subId + "'");
4043 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4044 }
4045 phone.getImsRegistrationTech(regTech -> {
4046 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4047 int regTechConverted = (regTech == null)
4048 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4049 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4050 regTechConverted);
4051 try {
4052 consumer.accept(regTechConverted);
4053 } catch (RemoteException e) {
4054 // Ignore if the remote process is no longer available to call back.
4055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4056 }
4057 });
4058 } finally {
4059 Binder.restoreCallingIdentity(token);
4060 }
4061 }
4062
shilu366312e2019-12-17 09:28:10 -08004063 /**
4064 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4065 * @param subId The subscription to use to check the configuration.
4066 * @param c The callback that will be used to send the result.
4067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004069 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4070 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004071 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004072 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004073 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4074 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4075 "IMS not available on device.");
4076 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 final long token = Binder.clearCallingIdentity();
4078 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004079 int slotId = getSlotIndexOrException(subId);
4080 verifyImsMmTelConfiguredOrThrow(slotId);
4081 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004082 } catch (ImsException e) {
4083 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 } finally {
4085 Binder.restoreCallingIdentity(token);
4086 }
4087 }
4088
shilu366312e2019-12-17 09:28:10 -08004089 /**
4090 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4091 * @param subId The subscription to use to check the configuration.
4092 * @param c The callback that will be used to send the result.
4093 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004095 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004096 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004097 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004098 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4099 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4100 }
Meng Wangafbc5852019-09-19 17:37:13 -07004101
4102 final long token = Binder.clearCallingIdentity();
4103 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004104 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004105 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004106 } catch (ImsException e) {
4107 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4108 + "is inactive, ignoring unregister.");
4109 // If the subscription is no longer active, just return, since the callback
4110 // will already have been removed internally.
4111 } finally {
4112 Binder.restoreCallingIdentity(token);
4113 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 }
4115
4116 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004117 public boolean isCapable(int subId, int capability, int regTech) {
4118 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long token = Binder.clearCallingIdentity();
4120 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004121 int slotId = getSlotIndexOrException(subId);
4122 verifyImsMmTelConfiguredOrThrow(slotId);
4123 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4126 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004127 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004128 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4129 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 } finally {
4131 Binder.restoreCallingIdentity(token);
4132 }
4133 }
4134
4135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004136 public boolean isAvailable(int subId, int capability, int regTech) {
4137 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long token = Binder.clearCallingIdentity();
4139 try {
4140 Phone phone = getPhone(subId);
4141 if (phone == null) return false;
4142 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004143 } catch (com.android.ims.ImsException e) {
4144 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4145 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 } finally {
4147 Binder.restoreCallingIdentity(token);
4148 }
4149 }
4150
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004151 /**
4152 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4153 * subscription.
4154 * @param subId The subscription to use to check the configuration.
4155 * @param callback The callback that will be used to send the result.
4156 * @param capability The MmTelFeature capability that will be used to send the result.
4157 * @param transportType The transport type of the MmTelFeature capability.
4158 */
4159 @Override
4160 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4161 int transportType) {
4162 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4165 "IMS not available on device.");
4166 }
4167 final long token = Binder.clearCallingIdentity();
4168 try {
4169 int slotId = getSlotIndex(subId);
4170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4171 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4172 + subId + "'");
4173 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4174 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004175 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004176 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4177 transportType, aBoolean -> {
4178 try {
4179 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4180 } catch (RemoteException e) {
4181 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4182 + "running. Ignore");
4183 }
4184 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 } catch (ImsException e) {
4186 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
4190 }
4191
shilu366312e2019-12-17 09:28:10 -08004192 /**
4193 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4194 * @param subId The subscription to use to check the configuration.
4195 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 @Override
4197 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004198 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004199 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004200
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 final long token = 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004205 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
4213 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004214 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004216 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 final long identity = Binder.clearCallingIdentity();
4218 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004220 // This setting doesn't require an active ImsService connection, so do not verify. The
4221 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
4228 }
4229
shilu366312e2019-12-17 09:28:10 -08004230 /**
4231 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4232 * @param subId The subscription to use to check the configuration.
4233 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004235 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004236 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004237 mApp, subId, "isVtSettingEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 } catch (ImsException e) {
4244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
4248 }
4249
4250 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004251 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004253 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 final long identity = Binder.clearCallingIdentity();
4255 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004256 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004257 // This setting doesn't require an active ImsService connection, so do not verify. The
4258 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
shilu366312e2019-12-17 09:28:10 -08004267 /**
4268 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4269 * @param subId The subscription to use to check the configuration.
4270 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 @Override
4272 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004273 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004274 mApp, subId, "isVoWiFiSettingEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
4285 }
4286
4287 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004288 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004290 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 final long identity = Binder.clearCallingIdentity();
4292 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004294 // This setting doesn't require an active ImsService connection, so do not verify. The
4295 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
shilu366312e2019-12-17 09:28:10 -08004304 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004305 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4306 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4307 * @param subId The subscription to use to check the configuration.
4308 */
4309 @Override
4310 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004311 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004312 mApp, subId, "isCrossSimCallingEnabledByUser");
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004316 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
4325 /**
4326 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4327 * Requires MODIFY_PHONE_STATE permission.
4328 * @param subId The subscription to use to check the configuration.
4329 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4330 * false otherwise
4331 */
4332 @Override
4333 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4335 "setCrossSimCallingEnabled");
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004339 // This setting doesn't require an active ImsService connection, so do not verify. The
4340 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004341 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004342 } catch (ImsException e) {
4343 throw new ServiceSpecificException(e.getCode());
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
4347 }
4348
4349 /**
shilu366312e2019-12-17 09:28:10 -08004350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4351 * @param subId The subscription to use to check the configuration.
4352 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004354
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004357 mApp, subId, "isVoWiFiRoamingSettingEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004373 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004377 // This setting doesn't require an active ImsService connection, so do not verify. The
4378 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
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
4387 @Override
4388 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4390 "setVoWiFiNonPersistent");
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004396 } catch (ImsException e) {
4397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
shilu366312e2019-12-17 09:28:10 -08004403 /**
4404 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4405 * @param subId The subscription to use to check the configuration.
4406 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004407 @Override
4408 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004409 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004410 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004415 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004416 } catch (ImsException e) {
4417 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
4421 }
4422
4423 @Override
4424 public void setVoWiFiModeSetting(int subId, int mode) {
4425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4426 "setVoWiFiModeSetting");
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. The
4431 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004433 } catch (ImsException e) {
4434 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
4440 @Override
4441 public int getVoWiFiRoamingModeSetting(int subId) {
4442 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004447 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (ImsException e) {
4449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
4455 @Override
4456 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 "setVoWiFiRoamingModeSetting");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004462 // This setting doesn't require an active ImsService connection, so do not verify. The
4463 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (ImsException e) {
4466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4475 "setRttCapabilityEnabled");
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004479 // This setting doesn't require an active ImsService connection, so do not verify. The
4480 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
shilu366312e2019-12-17 09:28:10 -08004489 /**
4490 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4491 * @param subId The subscription to use to check the configuration.
4492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 @Override
4494 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004495 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004496 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 final long identity = Binder.clearCallingIdentity();
4498 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004500 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004501 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (ImsException e) {
4503 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004509 @Override
4510 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4511 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004514 if (!isImsAvailableOnDevice()) {
4515 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4516 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004517 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
4519 verifyImsMmTelConfiguredOrThrow(slotId);
4520 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004521 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4531 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4532 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004533 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4534 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4535 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004537 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004538 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004540 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4541 + "is inactive, ignoring unregister.");
4542 // If the subscription is no longer active, just return, since the callback will already
4543 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
allenwtsu99c623b2020-01-03 18:24:23 +08004549
4550 private void checkModifyPhoneStatePermission(int subId, String message) {
4551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4552 message);
4553 }
4554
4555 private boolean isImsProvisioningRequired(int subId, int capability,
4556 boolean isMmtelCapability) {
4557 Phone phone = getPhone(subId);
4558 if (phone == null) {
4559 loge("phone instance null for subid " + subId);
4560 return false;
4561 }
4562 if (isMmtelCapability) {
4563 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4564 return false;
4565 }
4566 } else {
4567 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4568 return false;
4569 }
4570 }
4571 return true;
4572 }
4573
4574 @Override
4575 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4576 boolean isProvisioned) {
4577 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4578
4579 final long identity = Binder.clearCallingIdentity();
4580 try {
4581 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4582 if (!isImsProvisioningRequired(subId, capability, false)) {
4583 return;
4584 }
4585
4586 // this capability requires provisioning, route to the correct API.
4587 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4588 switch (capability) {
4589 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4590 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4591 ims.setEabProvisioned(isProvisioned);
4592 break;
4593 default: {
4594 throw new IllegalArgumentException("Tried to set provisioning for "
4595 + "rcs capability '" + capability + "', which does not require "
4596 + "provisioning.");
4597 }
4598 }
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
4602
4603 }
4604
4605
4606 @Override
4607 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4608 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4612 if (!isImsProvisioningRequired(subId, capability, false)) {
4613 return true;
4614 }
4615
4616 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4617 switch (capability) {
4618 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4619 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4620 return ims.isEabProvisionedOnDevice();
4621
4622 default: {
4623 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4624 + "capability '" + capability + "', which does not require "
4625 + "provisioning.");
4626 }
4627 }
4628
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004634 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004635 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4636 boolean isProvisioned) {
4637 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004638 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4639 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4640 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4642 }
allenwtsu99c623b2020-01-03 18:24:23 +08004643 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
4646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004647 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 return;
4649 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004650 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4651 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4652 loge("setImsProvisioningStatusForCapability: called for technology that does "
4653 + "not support provisioning - " + tech);
4654 return;
4655 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656
4657 // this capability requires provisioning, route to the correct API.
4658 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4659 switch (capability) {
4660 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4661 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4662 ims.setVolteProvisioned(isProvisioned);
4663 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4664 ims.setWfcProvisioned(isProvisioned);
4665 }
4666 break;
4667 }
4668 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4669 // There is currently no difference in VT provisioning type.
4670 ims.setVtProvisioned(isProvisioned);
4671 break;
4672 }
4673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4674 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4675 // change the capability of the feature instead if needed.
4676 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4677 == isProvisioned) {
4678 // No change in provisioning.
4679 return;
4680 }
4681 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4682 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004683 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004684 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004685 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4686 + ", Exception" + e.getMessage());
4687 }
4688 break;
4689 }
4690 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004691 throw new IllegalArgumentException("Tried to set provisioning for "
4692 + "MmTel capability '" + capability + "', which does not require "
4693 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694 }
4695 }
4696
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
4702 @Override
4703 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4704 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004705 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4706 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4707 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4709 }
4710 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4711 final long identity = Binder.clearCallingIdentity();
4712 try {
4713 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004714 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004715 return true;
4716 }
4717
Brad Ebinger0d79c572021-04-17 15:20:49 -07004718 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4719 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4720 loge("getImsProvisioningStatusForCapability: called for technology that does "
4721 + "not support provisioning - " + tech);
4722 return true;
4723 }
4724
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4726 switch (capability) {
4727 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4728 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4729 return ims.isVolteProvisionedOnDevice();
4730 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4731 return ims.isWfcProvisionedOnDevice();
4732 }
4733 // This should never happen, since we are checking tech above to make sure it
4734 // is either LTE or IWLAN.
4735 throw new IllegalArgumentException("Invalid radio technology for voice "
4736 + "capability.");
4737 }
4738 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4739 // There is currently no difference in VT provisioning type.
4740 return ims.isVtProvisionedOnDevice();
4741 }
4742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4743 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4744 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4745 }
4746 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004747 throw new IllegalArgumentException(
4748 "Tried to get provisioning for MmTel capability '" + capability
4749 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750 }
4751 }
4752
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
4756 }
4757
4758 @Override
4759 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4760 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4761 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4762 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4763 }
4764 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4765 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4766 return (provisionedBits & capability) > 0;
4767 }
4768
4769 @Override
4770 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4771 boolean isProvisioned) {
4772 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4773 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4774 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4775 }
4776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4777 "setProvisioningStatusForCapability");
4778 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4779 // If the current provisioning status for capability already matches isProvisioned,
4780 // do nothing.
4781 if (((provisionedBits & capability) > 0) == isProvisioned) {
4782 return;
4783 }
4784 if (isProvisioned) {
4785 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4786 } else {
4787 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4788 }
4789 }
4790
4791 /**
4792 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4793 * technology. The bitfield should mirror the bitfield defined by
4794 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4795 */
4796 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4797 String key = getMmTelProvisioningKey(subId, tech);
4798 // Default is no capabilities are provisioned.
4799 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4800 }
4801
4802 /**
4803 * Sets the MmTel capability provisioning bitfield (defined by
4804 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4805 * technology specified.
4806 *
4807 * Note: This is a synchronous command and should not be called on UI thread.
4808 */
4809 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4810 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4811 String key = getMmTelProvisioningKey(subId, tech);
4812 editor.putInt(key, newField);
4813 editor.commit();
4814 }
4815
4816 private static String getMmTelProvisioningKey(int subId, int tech) {
4817 // resulting key is provision_ims_mmtel_{subId}_{tech}
4818 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4819 }
4820
4821 /**
4822 * Query CarrierConfig to see if the specified capability requires provisioning for the
4823 * carrier associated with the subscription id.
4824 */
4825 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4826 int capability) {
4827 CarrierConfigManager configManager = new CarrierConfigManager(context);
4828 PersistableBundle c = configManager.getConfigForSubId(subId);
4829 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004830 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4832 false);
4833 boolean requireVoiceVtProvisioning = c.getBoolean(
4834 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4835
4836 // First check to make sure that the capability requires provisioning.
4837 switch (capability) {
4838 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4839 // intentional fallthrough
4840 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4841 if (requireVoiceVtProvisioning) {
4842 // Voice and Video requires provisioning
4843 return true;
4844 }
4845 break;
4846 }
4847 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4848 if (requireUtProvisioning) {
4849 // UT requires provisioning
4850 return true;
4851 }
4852 break;
4853 }
4854 }
4855 return false;
4856 }
4857
allenwtsu99c623b2020-01-03 18:24:23 +08004858 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4859 int capability) {
4860 CarrierConfigManager configManager = new CarrierConfigManager(context);
4861 PersistableBundle c = configManager.getConfigForSubId(subId);
4862
4863 boolean requireRcsProvisioning = c.getBoolean(
4864 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4865
4866 // First check to make sure that the capability requires provisioning.
4867 switch (capability) {
4868 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4869 // intentional fallthrough
4870 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4871 if (requireRcsProvisioning) {
4872 // OPTION or PRESENCE requires provisioning
4873 return true;
4874 }
4875 break;
4876 }
4877 }
4878 return false;
4879 }
4880
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4884 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4885 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004886 enforceReadPrivilegedPermission("getImsProvisioningInt");
4887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 int slotId = getSlotIndex(subId);
4891 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4892 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4893 + subId + "' for key:" + key);
4894 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4895 }
calvinpanb5a34062021-02-08 19:59:36 +08004896 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004897 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4899 + subId + "' for key:" + key);
4900 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4909 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4910 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004911 enforceReadPrivilegedPermission("getImsProvisioningString");
4912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 int slotId = getSlotIndex(subId);
4916 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4917 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4918 + subId + "' for key:" + key);
4919 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4920 }
calvinpanb5a34062021-02-08 19:59:36 +08004921 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004922 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4924 + subId + "' for key:" + key);
4925 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
4929 }
4930
4931 @Override
4932 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4934 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4935 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4937 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 int slotId = getSlotIndex(subId);
4942 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4943 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4944 + subId + "' for key:" + key);
4945 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4946 }
calvinpanb5a34062021-02-08 19:59:36 +08004947 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4948 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004950 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
4955 }
4956
4957 @Override
4958 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4960 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4961 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4963 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 int slotId = getSlotIndex(subId);
4968 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4969 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4970 + subId + "' for key:" + key);
4971 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4972 }
calvinpanb5a34062021-02-08 19:59:36 +08004973 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4974 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004976 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
4981 }
4982
Brad Ebinger919631e2021-06-02 17:46:35 -07004983 /**
4984 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4985 * for the given slot ID or no ImsResolver instance has been created.
4986 * @param slotId The slot ID that the IMS service is created for.
4987 * @throws ImsException If there is no ImsService configured for this slot.
4988 */
4989 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4990 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4991 ImsFeature.FEATURE_MMTEL)) {
4992 throw new ImsException("This subscription does not support MMTEL over IMS",
4993 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4994 }
4995 }
4996
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 int slotId = SubscriptionManager.getSlotIndex(subId);
4999 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005000 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5001 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 }
5003 return slotId;
5004 }
5005
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005006 private int getSlotIndex(int subId) {
5007 int slotId = SubscriptionManager.getSlotIndex(subId);
5008 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5009 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5010 }
5011 return slotId;
5012 }
5013
Wink Saville36469e72014-06-11 15:17:00 -07005014 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005015 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005016 */
5017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005018 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5019 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005020 try {
5021 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5022 } catch (SecurityException se) {
5023 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5024 throw new SecurityException("Package " + callingPackage + " does not belong to "
5025 + Binder.getCallingUid());
5026 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005027 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005028 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005030 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005031 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005032 mApp, subId, callingPackage, callingFeatureId,
5033 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005034 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5035 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 final Phone phone = getPhone(subId);
5040 if (phone != null) {
5041 return phone.getServiceState().getDataNetworkType();
5042 } else {
5043 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5044 }
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005048 }
5049
5050 /**
5051 * Returns the data network type
5052 */
5053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005054 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005055 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5056 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005057 }
5058
5059 /**
5060 * Returns the data network type for a subId
5061 */
5062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005063 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5064 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005066 mApp, subId, callingPackage, callingFeatureId,
5067 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005068 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5069 }
5070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 final Phone phone = getPhone(subId);
5074 if (phone != null) {
5075 return phone.getServiceState().getDataNetworkType();
5076 } else {
5077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5078 }
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005082 }
5083
5084 /**
Wink Saville36469e72014-06-11 15:17:00 -07005085 * Returns the Voice network type for a subId
5086 */
5087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005088 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5089 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005091 mApp, subId, callingPackage, callingFeatureId,
5092 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005093 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5094 }
5095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 final Phone phone = getPhone(subId);
5099 if (phone != null) {
5100 return phone.getServiceState().getVoiceNetworkType();
5101 } else {
5102 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5103 }
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005107 }
5108
5109 /**
5110 * @return true if a ICC card is present
5111 */
5112 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005113 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005114 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5115 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005116 }
5117
5118 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005119 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005120 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005121 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005122 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 final long identity = Binder.clearCallingIdentity();
5124 try {
5125 final Phone phone = PhoneFactory.getPhone(slotIndex);
5126 if (phone != null) {
5127 return phone.getIccCard().hasIccCard();
5128 } else {
5129 return false;
5130 }
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005134 }
5135
5136 /**
5137 * Return if the current radio is LTE on CDMA. This
5138 * is a tri-state return value as for a period of time
5139 * the mode may be unknown.
5140 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005141 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005142 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005143 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005144 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005146 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5147 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5148 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005149 }
5150
Sanket Padawe356d7632015-06-22 14:03:32 -07005151 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005152 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5153 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005154 try {
5155 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5156 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005157 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5158 }
5159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 final long identity = Binder.clearCallingIdentity();
5161 try {
5162 final Phone phone = getPhone(subId);
5163 if (phone == null) {
5164 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5165 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005166 return TelephonyProperties.lte_on_cdma_device()
5167 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 }
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005171 }
Wink Saville36469e72014-06-11 15:17:00 -07005172 }
5173
Wink Saville36469e72014-06-11 15:17:00 -07005174 /**
5175 * {@hide}
5176 * Returns Default subId, 0 in the case of single standby.
5177 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005178 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005179 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005180 }
5181
Shishir Agrawala9f32182016-04-12 12:00:16 -07005182 private int getSlotForDefaultSubscription() {
5183 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5184 }
5185
Wink Savilleb564aae2014-10-23 10:18:09 -07005186 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005187 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005188 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005189
Pengquan Menge92a50d2018-09-21 15:54:48 -07005190 private boolean isActiveSubscription(int subId) {
5191 return mSubscriptionController.isActiveSubId(subId);
5192 }
5193
Ihab Awadf2177b72013-11-25 13:33:23 -08005194 /**
5195 * @see android.telephony.TelephonyManager.WifiCallingChoices
5196 */
5197 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 final long identity = Binder.clearCallingIdentity();
5199 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005200 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5202 getWhenToMakeWifiCallsDefaultPreference());
5203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005206 }
5207
5208 /**
5209 * @see android.telephony.TelephonyManager.WifiCallingChoices
5210 */
5211 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005215 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005220 }
5221
Sailesh Nepald1e68152013-12-12 19:08:02 -08005222 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005223 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005224 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005225 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005226
Jordan Liu4c733742019-02-28 12:03:40 -08005227 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5228 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5229 if (phoneId == -1) {
5230 throw new IllegalArgumentException("Given slot index: " + slotIndex
5231 + " does not correspond to an active phone");
5232 }
5233 return PhoneFactory.getPhone(phoneId);
5234 }
5235
Shishir Agrawal566b7612013-10-28 14:41:00 -07005236 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005237 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5238 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5240 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005242 if (DBG) {
5243 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5244 }
5245 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5246 p2);
5247 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005248
Jordan Liu4c733742019-02-28 12:03:40 -08005249
5250 @Override
5251 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5252 int slotIndex, String callingPackage, String aid, int p2) {
5253 enforceModifyPermission();
5254 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5255 if (DBG) {
5256 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5257 }
5258 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5259 callingPackage, aid, p2);
5260 }
5261
5262 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5263 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 final long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (TextUtils.equals(ISDR_AID, aid)) {
5267 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005268 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5269 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 if (bestComponent == null
5271 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5272 loge("The calling package is not allowed to access ISD-R.");
5273 throw new SecurityException(
5274 "The calling package is not allowed to access ISD-R.");
5275 }
Derek Tan740e1672017-06-27 14:56:27 -07005276 }
Derek Tan740e1672017-06-27 14:56:27 -07005277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005279 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5280 null /* workSource */);
5281 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 return response;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005286 }
5287
5288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005289 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5291 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005292 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5293 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5294 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295
Jordan Liu4c733742019-02-28 12:03:40 -08005296 @Override
5297 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5298 enforceModifyPermission();
5299 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5300 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5301 channel);
5302 }
5303
5304 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 final long identity = Binder.clearCallingIdentity();
5306 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 if (channel < 0) {
5308 return false;
5309 }
Jordan Liu4c733742019-02-28 12:03:40 -08005310 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5311 null /* workSource */);
5312 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 return success;
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005316 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005317 }
5318
5319 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005320 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005321 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5323 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005324 if (DBG) {
5325 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5326 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5327 + p3 + " data=" + data);
5328 }
5329 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5330 command, p1, p2, p3, data);
5331 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005332
Jordan Liu4c733742019-02-28 12:03:40 -08005333 @Override
5334 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5335 int command, int p1, int p2, int p3, String data) {
5336 enforceModifyPermission();
5337 if (DBG) {
5338 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5339 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5340 + p3 + " data=" + data);
5341 }
5342 return iccTransmitApduLogicalChannelWithPermission(
5343 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5344 data);
5345 }
5346
5347 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5348 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 final long identity = Binder.clearCallingIdentity();
5350 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005351 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 return "";
5353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005356 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5357 null /* workSource */);
5358 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 // Append the returned status code to the end of the response payload.
5361 String s = Integer.toHexString(
5362 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5363 if (response.payload != null) {
5364 s = IccUtils.bytesToHexString(response.payload) + s;
5365 }
5366 return s;
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005369 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005370 }
Jake Hambye994d462014-02-03 13:10:13 -08005371
Evan Charltonc66da362014-05-16 14:06:40 -07005372 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005373 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5374 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5376 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005378 if (DBG) {
5379 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5380 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5381 }
5382 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5383 cla, command, p1, p2, p3, data);
5384 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005385
Jordan Liu4c733742019-02-28 12:03:40 -08005386 @Override
5387 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5388 int command, int p1, int p2, int p3, String data) {
5389 enforceModifyPermission();
5390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5391 if (DBG) {
5392 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5393 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5394 + " data=" + data);
5395 }
5396
5397 return iccTransmitApduBasicChannelWithPermission(
5398 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5399 p2, p3, data);
5400 }
5401
5402 // open APDU basic channel assuming the caller has sufficient permissions
5403 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5404 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
5407 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5408 && TextUtils.equals(ISDR_AID, data)) {
5409 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005410 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5411 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 if (bestComponent == null
5413 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5414 loge("The calling package is not allowed to select ISD-R.");
5415 throw new SecurityException(
5416 "The calling package is not allowed to select ISD-R.");
5417 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005418 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005421 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5422 null /* workSource */);
5423 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 // Append the returned status code to the end of the response payload.
5426 String s = Integer.toHexString(
5427 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5428 if (response.payload != null) {
5429 s = IccUtils.bytesToHexString(response.payload) + s;
5430 }
5431 return s;
5432 } finally {
5433 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005434 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005435 }
5436
5437 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005438 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005439 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5441 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 if (DBG) {
5446 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5447 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5448 }
5449
5450 IccIoResult response =
5451 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5452 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5453 subId);
5454
5455 if (DBG) {
5456 log("Exchange SIM_IO [R]" + response);
5457 }
5458
5459 byte[] result = null;
5460 int length = 2;
5461 if (response.payload != null) {
5462 length = 2 + response.payload.length;
5463 result = new byte[length];
5464 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5465 } else {
5466 result = new byte[length];
5467 }
5468
5469 result[length - 1] = (byte) response.sw2;
5470 result[length - 2] = (byte) response.sw1;
5471 return result;
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005474 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005475 }
5476
Nathan Haroldb3014052017-01-25 15:57:32 -08005477 /**
5478 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5479 * on a particular subscription
5480 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005481 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5482 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005484 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005485 return null;
5486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
5490 if (appType != TelephonyManager.APPTYPE_USIM
5491 && appType != TelephonyManager.APPTYPE_SIM) {
5492 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5493 return null;
5494 }
5495 Object response = sendRequest(
5496 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5497 if (response instanceof String[]) {
5498 return (String[]) response;
5499 }
yincheng zhao2737e882019-09-06 17:06:54 -07005500 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005502 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 } finally {
5504 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005505 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005506 }
5507
yincheng zhao2737e882019-09-06 17:06:54 -07005508 /**
5509 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5510 * subscription.
5511 *
5512 * @param subId the id of the subscription.
5513 * @param appType the uicc app type, must be USIM or SIM.
5514 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5515 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005516 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005517 * @return number of fplmns that is successfully written to the SIM.
5518 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005519 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5520 String callingFeatureId) {
5521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5522 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005523 if (DBG) logv("no permissions for setForbiddenplmns");
5524 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5525 }
5526 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5527 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5528 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5529 }
5530 if (fplmns == null) {
5531 throw new IllegalArgumentException("Fplmn List provided is null");
5532 }
5533 for (String fplmn : fplmns) {
5534 if (!CellIdentity.isValidPlmn(fplmn)) {
5535 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5536 }
5537 }
5538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 Object response = sendRequest(
5541 CMD_SET_FORBIDDEN_PLMNS,
5542 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5543 subId);
5544 return (int) response;
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
5548 }
5549
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005550 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005551 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5558 if (response.payload == null) {
5559 return "";
5560 }
Evan Charltonc66da362014-05-16 14:06:40 -07005561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 // Append the returned status code to the end of the response payload.
5563 String s = Integer.toHexString(
5564 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5565 s = IccUtils.bytesToHexString(response.payload) + s;
5566 return s;
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Evan Charltonc66da362014-05-16 14:06:40 -07005570 }
5571
Jake Hambye994d462014-02-03 13:10:13 -08005572 /**
5573 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5574 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5575 *
5576 * @param itemID the ID of the item to read
5577 * @return the NV item as a String, or null on error.
5578 */
5579 @Override
5580 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5583 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584
5585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005588 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5590 return value;
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Jake Hambye994d462014-02-03 13:10:13 -08005594 }
5595
5596 /**
5597 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5598 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5599 *
5600 * @param itemID the ID of the item to read
5601 * @param itemValue the value to write, as a String
5602 * @return true on success; false on any failure
5603 */
5604 @Override
5605 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
5610 final long identity = Binder.clearCallingIdentity();
5611 try {
5612 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5613 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005614 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5616 return success;
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jake Hambye994d462014-02-03 13:10:13 -08005620 }
5621
5622 /**
5623 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5624 * Used for device configuration by some CDMA operators.
5625 *
5626 * @param preferredRoamingList byte array containing the new PRL
5627 * @return true on success; false on any failure
5628 */
5629 @Override
5630 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5637 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5638 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5639 return success;
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Jake Hambye994d462014-02-03 13:10:13 -08005643 }
5644
5645 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005646 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005647 * Used for device configuration by some CDMA operators.
5648 *
chen xu6dac5ab2018-10-26 17:39:23 -07005649 * @param slotIndex - device slot.
5650 *
Jake Hambye994d462014-02-03 13:10:13 -08005651 * @return true on success; false on any failure
5652 */
5653 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005654 public boolean resetModemConfig(int slotIndex) {
5655 Phone phone = PhoneFactory.getPhone(slotIndex);
5656 if (phone != null) {
5657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
chen xu6dac5ab2018-10-26 17:39:23 -07005660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5663 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5664 return success;
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 }
chen xu6dac5ab2018-10-26 17:39:23 -07005669 return false;
5670 }
5671
5672 /**
5673 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5674 *
5675 * @param slotIndex - device slot.
5676 *
5677 * @return true on success; false on any failure
5678 */
5679 @Override
5680 public boolean rebootModem(int slotIndex) {
5681 Phone phone = PhoneFactory.getPhone(slotIndex);
5682 if (phone != null) {
5683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5684 mApp, phone.getSubId(), "rebootModem");
5685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5689 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5690 return success;
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
5694 }
5695 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005696 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005697
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005698 public String[] getPcscfAddress(String apnType, String callingPackage,
5699 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005700 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5702 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005703 return new String[0];
5704 }
5705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 final long identity = Binder.clearCallingIdentity();
5707 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005708 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Wink Saville36469e72014-06-11 15:17:00 -07005712 }
5713
Brad Ebinger51f743a2017-01-23 13:50:20 -08005714 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005715 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5716 * {@link #disableIms(int)}.
5717 * @param slotIndex device slot.
5718 */
5719 public void resetIms(int slotIndex) {
5720 enforceModifyPermission();
5721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 if (mImsResolver == null) {
5725 // may happen if the does not support IMS.
5726 return;
5727 }
5728 mImsResolver.disableIms(slotIndex);
5729 mImsResolver.enableIms(slotIndex);
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
5733 }
5734
5735 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005736 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5737 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005738 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005745 // may happen if the device does not support IMS.
5746 return;
5747 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005752 }
5753
5754 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005755 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5756 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005757 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 public void disableIms(int slotId) {
5759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005763 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005764 // may happen if the device does not support IMS.
5765 return;
5766 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005771 }
5772
5773 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005774 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5775 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005778 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5785 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005786 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005787 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005791 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005792 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005793 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5794 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005795 @Override
5796 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005797 enforceModifyPermission();
5798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005802 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
5806 }
5807
5808 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005809 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005810 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005811 */
5812 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005818 // may happen if the device does not support IMS.
5819 return null;
5820 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005825 }
5826
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005827 /**
5828 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005829 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 */
5831 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005837 // may happen if the device does not support IMS.
5838 return null;
5839 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005844 }
5845
Brad Ebinger884c07b2018-02-15 16:17:40 -08005846 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005847 * Sets the ImsService Package Name that Telephony will bind to.
5848 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005849 * @param slotIndex the slot ID that the ImsService should bind for.
5850 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005851 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 * @param featureTypes An integer array of feature types associated with a packageName.
5853 * @param packageName The name of the package that the current configuration will be replaced
5854 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005855 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005856 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5858 int[] featureTypes, String packageName) {
5859 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5862 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005868 // may happen if the device does not support IMS.
5869 return false;
5870 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 Map<Integer, String> featureConfig = new HashMap<>();
5872 for (int featureType : featureTypes) {
5873 featureConfig.put(featureType, packageName);
5874 }
5875 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5876 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005880 }
5881
5882 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005883 * Clears any carrier ImsService overrides for the slot index specified that were previously
5884 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5885 *
5886 * This should only be used for testing.
5887 *
5888 * @param slotIndex the slot ID that the ImsService should bind for.
5889 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5890 */
5891 @Override
5892 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5893 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5895 "clearCarrierImsServiceOverride");
5896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5897 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5898 "clearCarrierImsServiceOverride");
5899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 if (mImsResolver == null) {
5903 // may happen if the device does not support IMS.
5904 return false;
5905 }
5906 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
5910 }
5911
5912 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005913 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005914 *
5915 * @param slotId The slot that the ImsService is associated with.
5916 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5917 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005919 * @return the package name of the ImsService configuration.
5920 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5922 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005923 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005925 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5927 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005932 // may happen if the device does not support IMS.
5933 return "";
5934 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005935 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5937 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 } finally {
5939 Binder.restoreCallingIdentity(identity);
5940 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005941 }
5942
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005943 /**
5944 * Get the MmTelFeature state associated with the requested subscription id.
5945 * @param subId The subscription that the MmTelFeature is associated with.
5946 * @param callback A callback with an integer containing the
5947 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5948 */
5949 @Override
5950 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5951 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5952 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5953 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5954 "IMS not available on device.");
5955 }
5956 final long token = Binder.clearCallingIdentity();
5957 try {
5958 int slotId = getSlotIndex(subId);
5959 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5960 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5961 + subId + "'");
5962 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5963 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005964 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005965 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5966 try {
5967 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5968 } catch (RemoteException e) {
5969 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5970 + "Ignore");
5971 }
5972 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005973 } catch (ImsException e) {
5974 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005975 } finally {
5976 Binder.restoreCallingIdentity(token);
5977 }
5978 }
5979
Daniel Brightbb5840b2021-01-12 15:48:18 -08005980 /**
5981 * Sets the ims registration state on all valid {@link Phone}s.
5982 */
5983 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985
5986 final long identity = Binder.clearCallingIdentity();
5987 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005988 // NOTE: Before S, this method only set the default phone.
5989 for (final Phone phone : PhoneFactory.getPhones()) {
5990 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5991 phone.setImsRegistrationState(registered);
5992 }
5993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Wink Saville36469e72014-06-11 15:17:00 -07005997 }
5998
5999 /**
Stuart Scott54788802015-03-30 13:18:01 -07006000 * Set the network selection mode to automatic.
6001 *
6002 */
6003 @Override
6004 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6006 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
shilufc958392020-01-20 11:36:01 -08006010 if (!isActiveSubscription(subId)) {
6011 return;
6012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006014 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6015 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Stuart Scott54788802015-03-30 13:18:01 -07006019 }
6020
Jack Yud10cdd42020-09-28 20:28:01 -07006021 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006022 * Ask the radio to connect to the input network and change selection mode to manual.
6023 *
6024 * @param subId the id of the subscription.
6025 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6026 * the operator to attach to.
6027 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6028 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6029 * normal network selection next time.
6030 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006031 */
6032 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006033 public boolean setNetworkSelectionModeManual(
6034 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6036 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006037
6038 if (!isActiveSubscription(subId)) {
6039 return false;
6040 }
6041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final long identity = Binder.clearCallingIdentity();
6043 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006044 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006046 if (DBG) {
6047 log("setNetworkSelectionModeManual: subId: " + subId
6048 + " operator: " + operatorInfo);
6049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006054 }
shilu84f6e8b2019-12-19 13:58:01 -08006055 /**
6056 * Get the manual network selection
6057 *
6058 * @param subId the id of the subscription.
6059 *
6060 * @return the previously saved user selected PLMN
6061 */
6062 @Override
6063 public String getManualNetworkSelectionPlmn(int subId) {
6064 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006065 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006066 mApp, subId, "getManualNetworkSelectionPlmn");
6067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006071 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006072 }
6073
6074 final Phone phone = getPhone(subId);
6075 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006076 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006077 }
6078 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6079 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6080 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
6084 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006085
6086 /**
6087 * Scans for available networks.
6088 */
6089 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006090 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6091 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6093 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006094 LocationAccessPolicy.LocationPermissionResult locationResult =
6095 LocationAccessPolicy.checkLocationPermission(mApp,
6096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6097 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006098 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006099 .setCallingPid(Binder.getCallingPid())
6100 .setCallingUid(Binder.getCallingUid())
6101 .setMethod("getCellNetworkScanResults")
6102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006103 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6104 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006105 .build());
6106 switch (locationResult) {
6107 case DENIED_HARD:
6108 throw new SecurityException("Not allowed to access scan results -- location");
6109 case DENIED_SOFT:
6110 return null;
6111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112
Pengquan Menga1bb6272018-09-06 09:59:22 -07006113 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 try {
6115 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006116 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006121 }
6122
6123 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006124 * Get the call forwarding info, given the call forwarding reason.
6125 */
6126 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006127 public void getCallForwarding(int subId, int callForwardingReason,
6128 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006129 enforceReadPrivilegedPermission("getCallForwarding");
6130 long identity = Binder.clearCallingIdentity();
6131 try {
6132 if (DBG) {
6133 log("getCallForwarding: subId " + subId
6134 + " callForwardingReason" + callForwardingReason);
6135 }
Hall Liu27d24262020-09-18 19:04:59 -07006136
6137 Phone phone = getPhone(subId);
6138 if (phone == null) {
6139 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006140 callback.onError(
6141 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006142 } catch (RemoteException e) {
6143 // ignore
6144 }
6145 return;
6146 }
6147
6148 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6149 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6150 @Override
6151 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6152 try {
6153 callback.onCallForwardingInfoAvailable(info);
6154 } catch (RemoteException e) {
6155 // ignore
6156 }
6157 }
6158
6159 @Override
6160 public void onError(int error) {
6161 try {
6162 callback.onError(error);
6163 } catch (RemoteException e) {
6164 // ignore
6165 }
6166 }
6167 });
6168 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
6174 /**
6175 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6176 * reason, the number to forward, and the timeout before the forwarding is attempted.
6177 */
6178 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006179 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6180 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006181 enforceModifyPermission();
6182 long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (DBG) {
6185 log("setCallForwarding: subId " + subId
6186 + " callForwardingInfo" + callForwardingInfo);
6187 }
Hall Liu27d24262020-09-18 19:04:59 -07006188
6189 Phone phone = getPhone(subId);
6190 if (phone == null) {
6191 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006192 callback.accept(
6193 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006194 } catch (RemoteException e) {
6195 // ignore
6196 }
6197 return;
6198 }
6199
6200 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6201 FunctionalUtils.ignoreRemoteException(callback::accept));
6202
6203 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
6208
6209 /**
Hall Liu27d24262020-09-18 19:04:59 -07006210 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006211 */
6212 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006213 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006214 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006215 long identity = Binder.clearCallingIdentity();
6216 try {
Hall Liu27d24262020-09-18 19:04:59 -07006217 Phone phone = getPhone(subId);
6218 if (phone == null) {
6219 try {
6220 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6221 } catch (RemoteException e) {
6222 // ignore
6223 }
6224 return;
6225 }
SongFerngWang0e767992021-03-31 22:08:45 +08006226 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6227 PersistableBundle c = configManager.getConfigForSubId(subId);
6228 boolean requireUssd = c.getBoolean(
6229 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006230
Shuo Qian4a594052020-01-23 11:59:30 -08006231 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006232 if (requireUssd) {
6233 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6234 getSubscriptionCarrierId(subId));
6235 String newUssdCommand = "";
6236 try {
6237 newUssdCommand = carrierXmlParser.getFeature(
6238 CarrierXmlParser.FEATURE_CALL_WAITING)
6239 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6240 } catch (NullPointerException e) {
6241 loge("Failed to generate USSD number" + e);
6242 }
6243 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6244 mMainThreadHandler, callback, carrierXmlParser,
6245 CarrierXmlParser.SsEntry.SSAction.QUERY);
6246 final String ussdCommand = newUssdCommand;
6247 Executors.newSingleThreadExecutor().execute(() -> {
6248 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6249 });
6250 } else {
6251 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6252 callback::accept);
6253 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6254 }
Shuo Qian4a594052020-01-23 11:59:30 -08006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
6258 }
6259
6260 /**
Hall Liu27d24262020-09-18 19:04:59 -07006261 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006262 */
6263 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006264 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006265 enforceModifyPermission();
6266 long identity = Binder.clearCallingIdentity();
6267 try {
Hall Liu27d24262020-09-18 19:04:59 -07006268 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6269
6270 Phone phone = getPhone(subId);
6271 if (phone == null) {
6272 try {
6273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6274 } catch (RemoteException e) {
6275 // ignore
6276 }
6277 return;
6278 }
6279
SongFerngWang0e767992021-03-31 22:08:45 +08006280 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6281 PersistableBundle c = configManager.getConfigForSubId(subId);
6282 boolean requireUssd = c.getBoolean(
6283 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006284
SongFerngWang0e767992021-03-31 22:08:45 +08006285 if (DBG) log("getCallWaitingStatus: subId " + subId);
6286 if (requireUssd) {
6287 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6288 getSubscriptionCarrierId(subId));
6289 CarrierXmlParser.SsEntry.SSAction ssAction =
6290 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6291 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6292 String newUssdCommand = "";
6293 try {
6294 newUssdCommand = carrierXmlParser.getFeature(
6295 CarrierXmlParser.FEATURE_CALL_WAITING)
6296 .makeCommand(ssAction, null);
6297 } catch (NullPointerException e) {
6298 loge("Failed to generate USSD number" + e);
6299 }
6300 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6301 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6302 final String ussdCommand = newUssdCommand;
6303 Executors.newSingleThreadExecutor().execute(() -> {
6304 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6305 });
6306 } else {
6307 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6308 FunctionalUtils.ignoreRemoteException(callback::accept));
6309
6310 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6311 }
Shuo Qian4a594052020-01-23 11:59:30 -08006312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
6315 }
6316
6317 /**
yinxub1bed742017-04-17 11:45:04 -07006318 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006319 *
yinxub1bed742017-04-17 11:45:04 -07006320 * @param subId id of the subscription
6321 * @param request contains the radio access networks with bands/channels to scan
6322 * @param messenger callback messenger for scan results or errors
6323 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006324 * @return the id of the requested scan which can be used to stop the scan.
6325 */
6326 @Override
6327 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006328 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6330 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006331 LocationAccessPolicy.LocationPermissionResult locationResult =
6332 LocationAccessPolicy.checkLocationPermission(mApp,
6333 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6334 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006335 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006336 .setCallingPid(Binder.getCallingPid())
6337 .setCallingUid(Binder.getCallingUid())
6338 .setMethod("requestNetworkScan")
6339 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006340 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6341 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006342 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006343 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006344 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6345 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006346 if (e != null) {
6347 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6348 throw e;
6349 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006350 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006351 return TelephonyScanManager.INVALID_SCAN_ID;
6352 }
6353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 }
Hall Liu912dfd32019-04-25 14:02:26 -07006355 int callingUid = Binder.getCallingUid();
6356 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 return mNetworkScanRequestTracker.startNetworkScan(
6360 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006361 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
yinxu504e1392017-04-12 16:03:22 -07006365 }
6366
Hall Liub2ac8ef2019-02-28 15:56:23 -08006367 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006368 NetworkScanRequest request, int subId, String callingPackage) {
6369 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006370 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6371 boolean hasNetworkScanPermission =
6372 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6373 == PERMISSION_GRANTED;
6374
6375 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6376 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6377 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006378 }
6379
6380 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6381 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006382 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6383 return new SecurityException("Specific channels must not be"
6384 + " scanned without location access.");
6385 }
6386 }
6387 }
6388
Hall Liub2ac8ef2019-02-28 15:56:23 -08006389 return null;
6390 }
6391
yinxu504e1392017-04-12 16:03:22 -07006392 /**
6393 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006394 *
6395 * @param subId id of the subscription
6396 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006397 */
6398 @Override
6399 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6401 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402
Hall Liu912dfd32019-04-25 14:02:26 -07006403 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 final long identity = Binder.clearCallingIdentity();
6405 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006406 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
yinxu504e1392017-04-12 16:03:22 -07006410 }
6411
6412 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006413 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006414 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006415 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006416 */
6417 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006418 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006419 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006420 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006421 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422
6423 final long identity = Binder.clearCallingIdentity();
6424 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 if (DBG) log("getAllowedNetworkTypesBitmask");
6426 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6427 int networkTypesBitmask = (result != null ? result[0] : -1);
6428 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6429 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006433 }
6434
6435 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006436 * Get the allowed network types for certain reason.
6437 *
6438 * @param subId the id of the subscription.
6439 * @param reason the reason the allowed network type change is taking place
6440 * @return the allowed network types.
6441 */
6442 @Override
6443 public long getAllowedNetworkTypesForReason(int subId,
6444 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006445 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006446 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006447 final long identity = Binder.clearCallingIdentity();
6448 try {
6449 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454
6455 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006456 * Enable/Disable E-UTRA-NR Dual Connectivity
6457 * @param subId subscription id of the sim card
6458 * @param nrDualConnectivityState expected NR dual connectivity state
6459 * This can be passed following states
6460 * <ol>
6461 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6462 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6463 * <li>Disable NR dual connectivity and force secondary cell to be released
6464 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6465 * </ol>
6466 * @return operation result.
6467 */
6468 @Override
6469 public int setNrDualConnectivityState(int subId,
6470 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6472 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006473 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006474 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6475 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6476 }
6477
Sooraj Sasindran37444802020-08-11 10:40:43 -07006478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6482 nrDualConnectivityState, subId,
6483 workSource);
6484 if (DBG) log("enableNRDualConnectivity result: " + result);
6485 return result;
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
6492 * Is E-UTRA-NR Dual Connectivity enabled
6493 * @return true if dual connectivity is enabled else false
6494 */
6495 @Override
6496 public boolean isNrDualConnectivityEnabled(int subId) {
6497 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006498 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006499 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006500 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006501 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6502 return false;
6503 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6508 null, subId, workSource);
6509 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6510 return isEnabled;
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
6514 }
6515
6516 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006517 * Set the allowed network types of the device and
6518 * provide the reason triggering the allowed network change.
6519 *
6520 * @param subId the id of the subscription.
6521 * @param reason the reason the allowed network type change is taking place
6522 * @param allowedNetworkTypes the allowed network types.
6523 * @return true on success; false on any failure.
6524 */
6525 @Override
6526 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006527 @TelephonyManager.AllowedNetworkTypesReason int reason,
6528 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6530 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006531 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006532 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6533 return false;
6534 }
6535 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6536 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 return false;
6538 }
6539
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006540 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6541 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6542
6543
6544 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6545 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6546 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006548
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006549 final long identity = Binder.clearCallingIdentity();
6550 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006551 Boolean success = (Boolean) sendRequest(
6552 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6553 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6554
6555 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6556 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
6560 }
6561
6562 /**
Miaoa84611c2019-03-15 09:21:10 +08006563 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006564 *
Miaoa84611c2019-03-15 09:21:10 +08006565 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006566 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006567 * @hide
6568 */
6569 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006570 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006573 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 try {
Miaoa84611c2019-03-15 09:21:10 +08006575 if (phone != null) {
6576 return phone.hasMatchedTetherApnSetting();
6577 } else {
6578 return false;
6579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006582 }
Junda Liu475951f2014-11-07 16:45:03 -08006583 }
6584
6585 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006586 * Enable or disable always reporting signal strength changes from radio.
6587 *
6588 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6589 */
6590 @Override
6591 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6592 enforceModifyPermission();
6593 enforceSystemCaller();
6594
6595 final long identity = Binder.clearCallingIdentity();
6596 final Phone phone = getPhone(subId);
6597 try {
6598 if (phone != null) {
6599 if (DBG) {
6600 log("setAlwaysReportSignalStrength: subId=" + subId
6601 + " isEnable=" + isEnable);
6602 }
6603 phone.setAlwaysReportSignalStrength(isEnable);
6604 } else {
6605 loge("setAlwaysReportSignalStrength: no phone found for subId="
6606 + subId);
6607 }
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006614 * Get the user enabled state of Mobile Data.
6615 *
6616 * TODO: remove and use isUserDataEnabled.
6617 * This can't be removed now because some vendor codes
6618 * calls through ITelephony directly while they should
6619 * use TelephonyManager.
6620 *
6621 * @return true on enabled
6622 */
6623 @Override
6624 public boolean getDataEnabled(int subId) {
6625 return isUserDataEnabled(subId);
6626 }
6627
6628 /**
6629 * Get whether mobile data is enabled per user setting.
6630 *
6631 * There are other factors deciding whether mobile data is actually enabled, but they are
6632 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006633 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006634 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006635 *
6636 * @return {@code true} if data is enabled else {@code false}
6637 */
6638 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006639 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006640 try {
6641 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6642 null);
6643 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6645 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647
6648 final long identity = Binder.clearCallingIdentity();
6649 try {
6650 int phoneId = mSubscriptionController.getPhoneId(subId);
6651 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6652 Phone phone = PhoneFactory.getPhone(phoneId);
6653 if (phone != null) {
6654 boolean retVal = phone.isUserDataEnabled();
6655 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6656 return retVal;
6657 } else {
6658 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6659 return false;
6660 }
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006663 }
6664 }
6665
6666 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006667 * Checks if the device is capable of mobile data by considering whether whether the
6668 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6669 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006670 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006671 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006672 */
6673 @Override
6674 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006675 try {
6676 try {
6677 mApp.enforceCallingOrSelfPermission(
6678 android.Manifest.permission.ACCESS_NETWORK_STATE,
6679 null);
6680 } catch (Exception e) {
6681 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6682 "isDataEnabled");
6683 }
6684 } catch (Exception e) {
6685 enforceReadPrivilegedPermission("isDataEnabled");
6686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 int phoneId = mSubscriptionController.getPhoneId(subId);
6691 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6692 Phone phone = PhoneFactory.getPhone(phoneId);
6693 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006694 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6696 return retVal;
6697 } else {
6698 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6699 return false;
6700 }
6701 } finally {
6702 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006703 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006704 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006705
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 /**
6707 * Check if data is enabled for a specific reason
6708 * @param subId Subscription index
6709 * @param reason the reason the data enable change is taking place
6710 * @return {@code true} if the overall data is enabled; {@code false} if not.
6711 */
6712 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006713 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006714 @TelephonyManager.DataEnabledReason int reason) {
6715 try {
6716 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6717 null);
6718 } catch (Exception e) {
6719 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006720 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 }
6722
6723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 int phoneId = mSubscriptionController.getPhoneId(subId);
6727 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006728 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006729 + " reason=" + reason);
6730 }
6731 Phone phone = PhoneFactory.getPhone(phoneId);
6732 if (phone != null) {
6733 boolean retVal;
6734 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6735 retVal = phone.isUserDataEnabled();
6736 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006739 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006740 return retVal;
6741 } else {
6742 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006743 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006744 + subId + " retVal=false");
6745 }
6746 return false;
6747 }
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
6751 }
6752
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006753 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006755 if (uid == Process.PHONE_UID) {
6756 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6757 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6759 }
6760
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006761 //load access rules from carrier configs, and check those as well: b/139133814
6762 SubscriptionController subController = SubscriptionController.getInstance();
6763 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6764 || subController == null) return privilegeFromSim;
6765
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006766 PackageManager pkgMgr = phone.getContext().getPackageManager();
6767 String[] packages = pkgMgr.getPackagesForUid(uid);
6768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006771 int subId = phone.getSubId();
6772 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6773 // A test override is in place for the privileges for this subId, so don't try to
6774 // read the subscription privileges.
6775 return privilegeFromSim;
6776 }
6777 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006778 SubscriptionManager subManager = (SubscriptionManager)
6779 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6780 for (String pkg : packages) {
6781 if (subManager.canManageSubscription(subInfo, pkg)) {
6782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6783 }
6784 }
6785 return privilegeFromSim;
6786 } finally {
6787 Binder.restoreCallingIdentity(identity);
6788 }
6789 }
6790
6791 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6792 String pkgName) {
6793 //load access rules from carrier configs, and check those as well: b/139133814
6794 SubscriptionController subController = SubscriptionController.getInstance();
6795 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6796 || subController == null) return privilegeFromSim;
6797
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006800 int subId = phone.getSubId();
6801 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6802 // A test override is in place for the privileges for this subId, so don't try to
6803 // read the subscription privileges.
6804 return privilegeFromSim;
6805 }
6806 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006807 SubscriptionManager subManager = (SubscriptionManager)
6808 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6809 return subManager.canManageSubscription(subInfo, pkgName)
6810 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813 }
6814 }
6815
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006816 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006817 public int getCarrierPrivilegeStatus(int subId) {
6818 final Phone phone = getPhone(subId);
6819 if (phone == null) {
6820 loge("getCarrierPrivilegeStatus: Invalid subId");
6821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6822 }
6823 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006824 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006825 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6827 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006828
6829 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6830 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006831 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006832 }
Junda Liu29340342014-07-10 15:23:27 -07006833
6834 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006836 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006837 final Phone phone = getPhone(subId);
6838 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006839 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6841 }
6842 UiccProfile profile =
6843 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6844 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006845 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6847 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006848 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006849 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006850 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006851 }
6852
6853 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006854 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006855 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006856 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006857 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006858 }
6859
6860 int phoneId = SubscriptionManager.getPhoneId(subId);
6861 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006862 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006863 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6865 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006866 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6867 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6868 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006869 }
6870
6871 @Override
6872 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006873 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006874 if (TextUtils.isEmpty(pkgName))
6875 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006876 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6877 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6878 UiccCard card = UiccController.getInstance().getUiccCard(i);
6879 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006880 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006881 continue;
6882 }
6883
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006884 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6885 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6886 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006887 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6888 break;
6889 }
6890 }
6891
6892 return result;
Junda Liu29340342014-07-10 15:23:27 -07006893 }
Derek Tan89e89d42014-07-08 17:00:10 -07006894
6895 @Override
Junda Liue64de782015-04-16 17:19:16 -07006896 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006897 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006898 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6899 loge("phoneId " + phoneId + " is not valid.");
6900 return null;
6901 }
6902 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006903 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006904 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006905 return null ;
6906 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006907 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006908 }
6909
Amith Yamasani6e118872016-02-19 12:53:51 -08006910 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006911 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006912 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006913 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006914 List<String> privilegedPackages = new ArrayList<>();
6915 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006916 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6917 // has UICC in that slot.
6918 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006919 if (card.hasCarrierPrivilegeRules()) {
6920 if (packages == null) {
6921 // Only check packages in user 0 for now
6922 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006923 PackageManager.MATCH_DISABLED_COMPONENTS
6924 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006925 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006926 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006927 }
6928 for (int p = packages.size() - 1; p >= 0; p--) {
6929 PackageInfo pkgInfo = packages.get(p);
6930 if (pkgInfo != null && pkgInfo.packageName != null
6931 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006932 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006933 privilegedPackages.add(pkgInfo.packageName);
6934 }
6935 }
6936 }
6937 }
6938 return privilegedPackages;
6939 }
6940
chen xuf7e9fe82019-05-09 19:31:02 -07006941 @Override
6942 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006943 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6944
6945 final long identity = Binder.clearCallingIdentity();
6946
chen xuf7e9fe82019-05-09 19:31:02 -07006947 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006948 try {
6949 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6950 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6951 }
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006954 }
6955 return privilegedPackages;
6956 }
6957
Wink Savilleb564aae2014-10-23 10:18:09 -07006958 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006959 final Phone phone = getPhone(subId);
6960 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006961 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006962 return null;
6963 }
6964 String iccId = card.getIccId();
6965 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006966 return null;
6967 }
6968 return iccId;
6969 }
6970
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006971 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006972 public void setCallComposerStatus(int subId, int status) {
6973 enforceModifyPermission();
6974
6975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 Phone phone = getPhone(subId);
6978 if (phone != null) {
6979 Phone defaultPhone = phone.getImsPhone();
6980 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6981 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6982 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006983 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6984 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006985 }
6986 }
Shuo Qian284ae752020-12-22 19:10:14 -08006987 } catch (ImsException e) {
6988 throw new ServiceSpecificException(e.getCode());
6989 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006990 Binder.restoreCallingIdentity(identity);
6991 }
6992 }
6993
6994 @Override
6995 public int getCallComposerStatus(int subId) {
6996 enforceReadPrivilegedPermission("getCallComposerStatus");
6997
6998 final long identity = Binder.clearCallingIdentity();
6999 try {
7000 Phone phone = getPhone(subId);
7001 if (phone != null) {
7002 Phone defaultPhone = phone.getImsPhone();
7003 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7004 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7005 return imsPhone.getCallComposerStatus();
7006 }
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7012 }
7013
7014 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007015 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7016 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007017 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007018 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 final String iccId = getIccId(subId);
7023 final Phone phone = getPhone(subId);
7024 if (phone == null) {
7025 return false;
7026 }
7027 final String subscriberId = phone.getSubscriberId();
7028
7029 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007030 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 + subscriberId + " to " + number);
7032 }
7033
7034 if (TextUtils.isEmpty(iccId)) {
7035 return false;
7036 }
7037
7038 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7039
7040 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7041 if (alphaTag == null) {
7042 editor.remove(alphaTagPrefKey);
7043 } else {
7044 editor.putString(alphaTagPrefKey, alphaTag);
7045 }
7046
7047 // Record both the line number and IMSI for this ICCID, since we need to
7048 // track all merged IMSIs based on line number
7049 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7050 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7051 if (number == null) {
7052 editor.remove(numberPrefKey);
7053 editor.remove(subscriberPrefKey);
7054 } else {
7055 editor.putString(numberPrefKey, number);
7056 editor.putString(subscriberPrefKey, subscriberId);
7057 }
7058
7059 editor.commit();
7060 return true;
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007063 }
Derek Tan7226c842014-07-02 17:42:23 -07007064 }
7065
7066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 public String getLine1NumberForDisplay(int subId, String callingPackage,
7068 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007069 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007071 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007072 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007073 return null;
7074 }
Derek Tan97ebb422014-09-05 16:55:38 -07007075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 final long identity = Binder.clearCallingIdentity();
7077 try {
7078 String iccId = getIccId(subId);
7079 if (iccId != null) {
7080 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7081 if (DBG_MERGE) {
7082 log("getLine1NumberForDisplay returning "
7083 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7084 }
7085 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7088 return null;
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007091 }
Derek Tan7226c842014-07-02 17:42:23 -07007092 }
7093
7094 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007095 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7096 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007098 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007099 return null;
7100 }
Derek Tan97ebb422014-09-05 16:55:38 -07007101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 String iccId = getIccId(subId);
7105 if (iccId != null) {
7106 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7107 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7108 }
7109 return null;
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007112 }
Derek Tan7226c842014-07-02 17:42:23 -07007113 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007114
7115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007116 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7117 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007118 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7119 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007121 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007122 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007123 return null;
7124 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007125
Jordan Liub49b04b2019-05-06 14:45:15 -07007126 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7127 // the process, where TelephonyManager was instantiated.
7128 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007129 final long identity = Binder.clearCallingIdentity();
7130 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007131 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 final TelephonyManager tele = TelephonyManager.from(context);
7133 final SubscriptionManager sub = SubscriptionManager.from(context);
7134
7135 // Figure out what subscribers are currently active
7136 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137
Jordan Liub49b04b2019-05-06 14:45:15 -07007138 // Only consider subs which match the current subId
7139 // This logic can be simplified. See b/131189269 for progress.
7140 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007141 activeSubscriberIds.add(tele.getSubscriberId(subId));
7142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143
7144 // First pass, find a number override for an active subscriber
7145 String mergeNumber = null;
7146 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7147 for (String key : prefs.keySet()) {
7148 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7149 final String subscriberId = (String) prefs.get(key);
7150 if (activeSubscriberIds.contains(subscriberId)) {
7151 final String iccId = key.substring(
7152 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7153 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7154 mergeNumber = (String) prefs.get(numberKey);
7155 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007156 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 + " for active subscriber " + subscriberId);
7158 }
7159 if (!TextUtils.isEmpty(mergeNumber)) {
7160 break;
7161 }
7162 }
7163 }
7164 }
7165
7166 // Shortcut when no active merged subscribers
7167 if (TextUtils.isEmpty(mergeNumber)) {
7168 return null;
7169 }
7170
7171 // Second pass, find all subscribers under that line override
7172 final ArraySet<String> result = new ArraySet<>();
7173 for (String key : prefs.keySet()) {
7174 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7175 final String number = (String) prefs.get(key);
7176 if (mergeNumber.equals(number)) {
7177 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7178 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7179 final String subscriberId = (String) prefs.get(subscriberKey);
7180 if (!TextUtils.isEmpty(subscriberId)) {
7181 result.add(subscriberId);
7182 }
7183 }
7184 }
7185 }
7186
7187 final String[] resultArray = result.toArray(new String[result.size()]);
7188 Arrays.sort(resultArray);
7189 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007190 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7192 }
7193 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007194 } finally {
7195 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007196 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007197 }
7198
7199 @Override
zoey chen38003472019-12-13 17:16:31 +08007200 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7201 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007202
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 final TelephonyManager telephonyManager = mApp.getSystemService(
7206 TelephonyManager.class);
7207 String subscriberId = telephonyManager.getSubscriberId(subId);
7208 if (subscriberId == null) {
7209 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007210 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007211 + subId);
7212 }
7213 return null;
7214 }
7215
7216 final SubscriptionInfo info = SubscriptionController.getInstance()
7217 .getSubscriptionInfo(subId);
7218 final ParcelUuid groupUuid = info.getGroupUuid();
7219 // If it doesn't belong to any group, return just subscriberId of itself.
7220 if (groupUuid == null) {
7221 return new String[]{subscriberId};
7222 }
7223
7224 // Get all subscriberIds from the group.
7225 final List<String> mergedSubscriberIds = new ArrayList<>();
7226 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007227 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007228 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007229 for (SubscriptionInfo subInfo : groupInfos) {
7230 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7231 if (subscriberId != null) {
7232 mergedSubscriberIds.add(subscriberId);
7233 }
7234 }
7235
7236 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7237 } finally {
7238 Binder.restoreCallingIdentity(identity);
7239
7240 }
7241 }
7242
7243 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007244 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007245 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007246 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 final Phone phone = getPhone(subId);
7251 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7252 } finally {
7253 Binder.restoreCallingIdentity(identity);
7254 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007255 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007256
7257 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007258 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007259 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7260 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007261 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7262 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263
7264 final long identity = Binder.clearCallingIdentity();
7265 try {
7266 final Phone phone = getPhone(subId);
7267 if (phone == null) {
7268 return false;
7269 }
7270 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7271 cdmaNonRoamingList);
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007274 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007275 }
7276
7277 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007278 @Deprecated
7279 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7280 enforceModifyPermission();
7281
7282 int returnValue = 0;
7283 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007284 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007285 if(result.exception == null) {
7286 if (result.result != null) {
7287 byte[] responseData = (byte[])(result.result);
7288 if(responseData.length > oemResp.length) {
7289 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7290 responseData.length + "bytes. Buffer Size is " +
7291 oemResp.length + "bytes.");
7292 }
7293 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7294 returnValue = responseData.length;
7295 }
7296 } else {
7297 CommandException ex = (CommandException) result.exception;
7298 returnValue = ex.getCommandError().ordinal();
7299 if(returnValue > 0) returnValue *= -1;
7300 }
7301 } catch (RuntimeException e) {
7302 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7303 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7304 if(returnValue > 0) returnValue *= -1;
7305 }
7306
7307 return returnValue;
7308 }
7309
7310 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007311 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007312 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007313 try {
7314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007316 mApp, phone.getSubId(), "getRadioAccessFamily");
7317 } catch (SecurityException e) {
7318 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7319 throw e;
7320 }
chen xub97461a2018-10-26 14:17:57 -07007321 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007322 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007323 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 final long identity = Binder.clearCallingIdentity();
7326 try {
chen xub97461a2018-10-26 14:17:57 -07007327 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007328 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007329 mApp, phone.getSubId(), "getRadioAccessFamily");
7330 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333 }
chen xub97461a2018-10-26 14:17:57 -07007334 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007335 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007336
7337 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007338 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007339 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007340 try {
7341 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7342 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007343 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007344 }
7345 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007346 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007347 }
7348 RoleManager rm = mApp.getSystemService(RoleManager.class);
7349 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7350 if (!dialerRoleHolders.contains(callingPackage)) {
7351 throw new SecurityException("App must be the dialer role holder to"
7352 + " upload a call composer pic");
7353 }
7354
7355 Executors.newSingleThreadExecutor().execute(() -> {
7356 ByteArrayOutputStream output = new ByteArrayOutputStream(
7357 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7358 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7359 boolean readUntilEnd = false;
7360 int totalBytesRead = 0;
7361 byte[] buffer = new byte[16 * 1024];
7362 while (true) {
7363 int numRead;
7364 try {
7365 numRead = input.read(buffer);
7366 } catch (IOException e) {
7367 try {
7368 fd.checkError();
7369 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7370 null);
7371 } catch (IOException e1) {
7372 // This means that the other side closed explicitly with an error. If this
7373 // happens, log and ignore.
7374 loge("Remote end of call composer picture pipe closed: " + e1);
7375 }
7376 break;
7377 }
7378 if (numRead == -1) {
7379 readUntilEnd = true;
7380 break;
7381 }
7382 totalBytesRead += numRead;
7383 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7384 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7385 try {
7386 input.close();
7387 } catch (IOException e) {
7388 // ignore
7389 }
7390 break;
7391 }
7392 output.write(buffer, 0, numRead);
7393 }
7394 // Generally, the remote end will close the file descriptors. The only case where we
7395 // close is above, where the picture size is too big.
7396
7397 try {
7398 fd.checkError();
7399 } catch (IOException e) {
7400 loge("Remote end for call composer closed with an error: " + e);
7401 return;
7402 }
7403
Hall Liuaa4211e2021-01-20 15:43:39 -08007404 if (!readUntilEnd) {
7405 loge("Did not finish reading entire image; aborting");
7406 return;
7407 }
Hall Liu82694d52020-12-11 18:22:04 -08007408
Hall Liuaa4211e2021-01-20 15:43:39 -08007409 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7410 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7411 new CallComposerPictureTransfer.Factory() {},
7412 imageData,
7413 (result) -> {
7414 if (result.first != null) {
7415 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7416 Bundle outputResult = new Bundle();
7417 outputResult.putParcelable(
7418 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7419 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7420 outputResult);
7421 } else {
7422 callback.send(result.second, null);
7423 }
7424 }
7425 );
Hall Liu82694d52020-12-11 18:22:04 -08007426 });
7427 }
7428
7429 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007430 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433
7434 final long identity = Binder.clearCallingIdentity();
7435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007436 ImsManager.getInstance(defaultPhone.getContext(),
7437 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007441 }
7442
7443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007444 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7447 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007448 return false;
7449 }
Svet Ganovb320e182015-04-16 12:30:10 -07007450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
7453 // Check the user preference and the system-level IMS setting. Even if the user has
7454 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7455 // In the long run, we may instead need to check if there exists a connection service
7456 // which can support video calling.
7457 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 return imsManager.isVtEnabledByPlatform()
7460 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7461 && imsManager.isVtEnabledByUser();
7462 } finally {
7463 Binder.restoreCallingIdentity(identity);
7464 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007465 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007466
Andrew Leea1239f22015-03-02 17:44:07 -08007467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007468 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7469 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 mApp, subId, callingPackage, callingFeatureId,
7472 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 return false;
7474 }
7475
7476 final long identity = Binder.clearCallingIdentity();
7477 try {
7478 CarrierConfigManager configManager =
7479 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007480 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
7484 }
Andrew Leea1239f22015-03-02 17:44:07 -08007485 }
7486
7487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007488 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007490 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 return false;
7492 }
7493
7494 final long identity = Binder.clearCallingIdentity();
7495 try {
7496 CarrierConfigManager configManager =
7497 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007498 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502 }
Andrew Leea1239f22015-03-02 17:44:07 -08007503 }
7504
Andrew Lee9431b832015-03-09 18:46:45 -07007505 @Override
7506 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007507 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007508 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007509 }
7510
7511 @Override
7512 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007515 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 } finally {
7517 Binder.restoreCallingIdentity(identity);
7518 }
Andrew Lee9431b832015-03-09 18:46:45 -07007519 }
7520
Hall Liuf6668912018-10-31 17:05:23 -07007521 /**
7522 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7523 * support for the feature and device firmware support.
7524 *
7525 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7526 */
7527 @Override
7528 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007530 final Phone phone = getPhone(subscriptionId);
7531 if (phone == null) {
7532 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7533 return false;
7534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007536 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7538 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 return isCarrierSupported && isDeviceSupported;
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Hall Liu98187582018-01-22 19:15:32 -08007544 }
7545
Hall Liuf6668912018-10-31 17:05:23 -07007546 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007547 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7548 * RTT setting, will return true if the device and carrier both support RTT.
7549 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007550 */
7551 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 final long identity = Binder.clearCallingIdentity();
7553 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007554 boolean isRttSupported = isRttSupported(subscriptionId);
7555 boolean isUserRttSettingOn = Settings.Secure.getInt(
7556 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7557 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7558 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7559 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 } finally {
7561 Binder.restoreCallingIdentity(identity);
7562 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007563 }
7564
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007565 @Deprecated
7566 @Override
7567 public String getDeviceId(String callingPackage) {
7568 return getDeviceIdWithFeature(callingPackage, null);
7569 }
7570
Sanket Padawe7310cc72015-01-14 09:53:20 -08007571 /**
7572 * Returns the unique device ID of phone, for example, the IMEI for
7573 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7574 *
7575 * <p>Requires Permission:
7576 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7577 */
7578 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007579 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007580 try {
7581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7582 } catch (SecurityException se) {
7583 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7584 throw new SecurityException("Package " + callingPackage + " does not belong to "
7585 + Binder.getCallingUid());
7586 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007587 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007588 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007589 return null;
7590 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007591 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007592 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007593 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007594 return null;
7595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596
7597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 return phone.getDeviceId();
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007603 }
7604
Ping Sunc67b7c22016-03-02 19:16:45 +08007605 /**
7606 * {@hide}
7607 * Returns the IMS Registration Status on a particular subid
7608 *
7609 * @param subId
7610 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007612 Phone phone = getPhone(subId);
7613 if (phone != null) {
7614 return phone.isImsRegistered();
7615 } else {
7616 return false;
7617 }
7618 }
7619
Santos Cordon7a1885b2015-02-03 11:15:19 -08007620 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007621 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007622 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007624 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007625 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7626 }
7627 final long identity = Binder.clearCallingIdentity();
7628 try {
7629 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
7633 }
7634
7635 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007636 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007637 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007638 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007639 mApp,
7640 subscriptionId,
7641 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007642 final long identity = Binder.clearCallingIdentity();
7643 try {
7644 Phone phone = getPhone(subscriptionId);
7645 if (phone == null) {
7646 return null;
7647 }
7648 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
7653
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007654 /**
7655 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007656 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007657 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 final long identity = Binder.clearCallingIdentity();
7659 try {
7660 Phone phone = getPhone(subId);
7661 if (phone != null) {
7662 return phone.isWifiCallingEnabled();
7663 } else {
7664 return false;
7665 }
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007668 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007669 }
7670
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007672 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007673 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007674 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 Phone phone = getPhone(subId);
7678 if (phone != null) {
7679 return phone.isVideoEnabled();
7680 } else {
7681 return false;
7682 }
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007685 }
7686 }
7687
7688 /**
7689 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7690 * defined in {@link ImsRegistrationImplBase}.
7691 */
7692 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subId);
7696 if (phone != null) {
7697 return phone.getImsRegistrationTech();
7698 } else {
7699 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7700 }
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007703 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007704 }
7705
Stuart Scott8eef64f2015-04-08 15:13:54 -07007706 @Override
7707 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007708 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007709 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7710 return;
7711 }
Kai Shif70f46f2021-03-03 13:59:46 -08007712 Phone defaultPhone = getDefaultPhone();
7713 if (defaultPhone != null) {
7714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7715 mApp, getDefaultPhone().getSubId(), "factoryReset");
7716 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007717 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718
Svet Ganovcc087f82015-05-12 20:35:54 -07007719 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007720 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7721 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007722 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007723 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007724 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007725 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007726 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007728 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007729 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007730 // There has been issues when Sms raw table somehow stores orphan
7731 // fragments. They lead to garbled message when new fragments come
7732 // in and combined with those stale ones. In case this happens again,
7733 // user can reset all network settings which will clean up this table.
7734 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007735 // Clean up IMS settings as well here.
7736 int slotId = getSlotIndex(subId);
7737 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7738 ImsManager.getInstance(mApp, slotId).factoryReset();
7739 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007740
Kai Shif70f46f2021-03-03 13:59:46 -08007741 if (defaultPhone == null) {
7742 return;
7743 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007744 // Erase modem config if erase modem on network setting is enabled.
7745 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7746 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7747 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007748 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007749 }
Kai Shif70f46f2021-03-03 13:59:46 -08007750
7751 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007752 } finally {
7753 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007754 }
7755 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007756
SongFerngWangfd89b102021-05-27 22:44:54 +08007757 @VisibleForTesting
7758 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7759 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7760 return;
7761 }
7762 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7763 RILConstants.PREFERRED_NETWORK_MODE);
7764 SubscriptionManager.setSubscriptionProperty(subId,
7765 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7766 "user=" + defaultNetworkType);
7767 phone.loadAllowedNetworksFromSubscriptionDatabase();
7768 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7769 defaultNetworkType, null);
7770 }
7771
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007772 private void cleanUpSmsRawTable(Context context) {
7773 ContentResolver resolver = context.getContentResolver();
7774 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7775 resolver.delete(uri, null, null);
7776 }
7777
Narayan Kamath1c496c22015-04-16 14:40:19 +01007778 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007779 public String getSimLocaleForSubscriber(int subId) {
7780 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7781 final Phone phone = getPhone(subId);
7782 if (phone == null) {
7783 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007784 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 final long identity = Binder.clearCallingIdentity();
7787 try {
chen xu5d3637b2019-01-21 23:31:38 -08007788 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007789 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007790 if (info == null) {
7791 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7792 return null;
7793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 // Try and fetch the locale from the carrier properties or from the SIM language
7795 // preferences (EF-PL and EF-LI)...
7796 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007798 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7799 if (localeFromDefaultSim != null) {
7800 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7801 if (DBG) log("Using locale from subId: " + subId + " locale: "
7802 + localeFromDefaultSim);
7803 return localeFromDefaultSim.toLanguageTag();
7804 } else {
7805 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 }
7807 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 // The SIM language preferences only store a language (e.g. fr = French), not an
7810 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7811 // the SIM and carrier preferences does not include a country we add the country
7812 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007813 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007815 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 return mccLocale.toLanguageTag();
7817 }
7818
7819 if (DBG) log("No locale found - returning null");
7820 return null;
7821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007824 }
7825
7826 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007827 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007828 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007829 }
7830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007831 /**
7832 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7833 */
7834 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007835 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007836 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007837 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007838
Chenjie Yu1ba97252018-01-11 18:16:20 -08007839 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007840 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007841
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007842 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007843 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7844 * representing the state of the modem.
7845 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007846 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7847 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007848 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007849 */
7850 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007851 public void requestModemActivityInfo(ResultReceiver result) {
7852 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007853 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854
7855 final long identity = Binder.clearCallingIdentity();
7856 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007857 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 } finally {
7859 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007861 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007862
Siddharth Rayb8114062018-06-17 15:02:38 -07007863 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7864 // less than total activity duration.
7865 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7866 if (info == null) {
7867 return false;
7868 }
7869 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007870 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7871 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7872
Siddharth Rayb8114062018-06-17 15:02:38 -07007873 return (info.isValid()
7874 && (info.getSleepTimeMillis() <= activityDurationMs)
7875 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007876 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007877 && (totalTxTimeMs <= activityDurationMs));
7878 }
7879
Jack Yu85bd38a2015-11-09 11:34:32 -08007880 /**
7881 * {@hide}
7882 * Returns the service state information on specified subscription.
7883 */
7884 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007885 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7886 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007888 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007889 return null;
7890 }
7891
Hall Liuf19c44f2018-11-27 14:38:17 -08007892 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7893 LocationAccessPolicy.checkLocationPermission(mApp,
7894 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7895 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007896 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007897 .setCallingPid(Binder.getCallingPid())
7898 .setCallingUid(Binder.getCallingUid())
7899 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007900 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007901 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007902 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7903 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007904 .build());
7905
7906 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7907 LocationAccessPolicy.checkLocationPermission(mApp,
7908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7909 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007910 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007911 .setCallingPid(Binder.getCallingPid())
7912 .setCallingUid(Binder.getCallingUid())
7913 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007914 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007915 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007916 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7917 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007918 .build());
7919 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7920 boolean hasFinePermission =
7921 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7922 boolean hasCoarsePermission =
7923 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7924
Jack Yu479f40e2020-10-27 21:29:25 -07007925 final Phone phone = getPhone(subId);
7926 if (phone == null) {
7927 return null;
7928 }
7929
Jordan Liu0f2bc442020-11-18 16:47:37 -08007930 final long identity = Binder.clearCallingIdentity();
7931
Jack Yu479f40e2020-10-27 21:29:25 -07007932 boolean isCallingPackageDataService = phone.getDataServicePackages()
7933 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007935 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7936 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7937 Rlog.d(LOG_TAG,
7938 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7939 return null;
7940 }
7941
Hall Liuf19c44f2018-11-27 14:38:17 -08007942 ServiceState ss = phone.getServiceState();
7943
7944 // Scrub out the location info in ServiceState depending on what level of access
7945 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007946 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007947 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7948 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949 } finally {
7950 Binder.restoreCallingIdentity(identity);
7951 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007952 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007953
7954 /**
7955 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7956 *
7957 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7958 * voicemail ringtone.
7959 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7960 * PhoneAccount.
7961 */
7962 @Override
7963 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 final long identity = Binder.clearCallingIdentity();
7965 try {
7966 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7967 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007968 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7972 } finally {
7973 Binder.restoreCallingIdentity(identity);
7974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007975 }
7976
7977 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007978 * Sets the per-account voicemail ringtone.
7979 *
7980 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7981 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7982 *
7983 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7984 * voicemail ringtone.
7985 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7986 * PhoneAccount.
7987 */
7988 @Override
7989 public void setVoicemailRingtoneUri(String callingPackage,
7990 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007993 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7994 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7996 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7997 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999
8000 final long identity = Binder.clearCallingIdentity();
8001 try {
8002 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8003 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008004 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 }
8006 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8007 } finally {
8008 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008010 }
8011
8012 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008013 * Returns whether vibration is set for voicemail notification in Phone settings.
8014 *
8015 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8016 * voicemail vibration setting.
8017 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8018 */
8019 @Override
8020 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 final long identity = Binder.clearCallingIdentity();
8022 try {
8023 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8024 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008025 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
8031 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008032 }
8033
Youhan Wange64578a2016-05-02 15:32:42 -07008034 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008035 * Sets the per-account voicemail vibration.
8036 *
8037 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8038 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8039 *
8040 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8041 * voicemail vibration setting.
8042 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8043 * specific PhoneAccount.
8044 */
8045 @Override
8046 public void setVoicemailVibrationEnabled(String callingPackage,
8047 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008048 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008050 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8051 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8053 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8054 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008055 }
8056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 final long identity = Binder.clearCallingIdentity();
8058 try {
8059 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8060 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008061 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062 }
8063 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008066 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008067 }
8068
8069 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008070 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8071 *
8072 * @throws SecurityException if the caller does not have the required permission
8073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008074 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008075 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008076 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008077 }
8078
8079 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008080 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8081 * permission.
8082 *
8083 * @throws SecurityException if the caller does not have the required permission
8084 */
8085 private void enforceSendSmsPermission() {
8086 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8087 }
8088
8089 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008090 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008091 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008092 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008093 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008094 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008098 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 if (componentName == null) {
8100 throw new SecurityException(
8101 "Caller not current active visual voicemail package[null]");
8102 }
8103 String vvmPackage = componentName.getPackageName();
8104 if (!callingPackage.equals(vvmPackage)) {
8105 throw new SecurityException("Caller not current active visual voicemail package["
8106 + vvmPackage + "]");
8107 }
8108 } finally {
8109 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008110 }
8111 }
8112
8113 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008114 * Return the application ID for the app type.
8115 *
8116 * @param subId the subscription ID that this request applies to.
8117 * @param appType the uicc app type.
8118 * @return Application ID for specificied app type, or null if no uicc.
8119 */
8120 @Override
8121 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008122 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008123 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124
8125 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008126 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 if (phone == null) {
8128 return null;
8129 }
8130 String aid = null;
8131 try {
8132 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8133 .getApplicationByType(appType).getAid();
8134 } catch (Exception e) {
8135 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8136 }
8137 return aid;
8138 } finally {
8139 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008140 }
Youhan Wange64578a2016-05-02 15:32:42 -07008141 }
8142
Youhan Wang4001d252016-05-11 10:29:41 -07008143 /**
8144 * Return the Electronic Serial Number.
8145 *
8146 * @param subId the subscription ID that this request applies to.
8147 * @return ESN or null if error.
8148 */
8149 @Override
8150 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008151 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008152 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153
8154 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008155 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156 if (phone == null) {
8157 return null;
8158 }
8159 String esn = null;
8160 try {
8161 esn = phone.getEsn();
8162 } catch (Exception e) {
8163 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8164 }
8165 return esn;
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008168 }
Youhan Wang4001d252016-05-11 10:29:41 -07008169 }
8170
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008171 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008172 * Return the Preferred Roaming List Version.
8173 *
8174 * @param subId the subscription ID that this request applies to.
8175 * @return PRLVersion or null if error.
8176 */
8177 @Override
8178 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008179 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181
8182 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008183 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 if (phone == null) {
8185 return null;
8186 }
8187 String cdmaPrlVersion = null;
8188 try {
8189 cdmaPrlVersion = phone.getCdmaPrlVersion();
8190 } catch (Exception e) {
8191 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8192 }
8193 return cdmaPrlVersion;
8194 } finally {
8195 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008196 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008197 }
8198
8199 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008200 * Get snapshot of Telephony histograms
8201 * @return List of Telephony histograms
8202 * @hide
8203 */
8204 @Override
8205 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8207 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208
8209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 return RIL.getTelephonyRILTimingHistograms();
8212 } finally {
8213 Binder.restoreCallingIdentity(identity);
8214 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008215 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008216
8217 /**
8218 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008219 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8220 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008221 * Require system privileges. In the future we may add this to carrier APIs.
8222 *
Michele Berionne482f8202018-11-27 18:57:59 -08008223 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008224 */
8225 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008226 @TelephonyManager.SetCarrierRestrictionResult
8227 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008228 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008230
Michele Berionne482f8202018-11-27 18:57:59 -08008231 if (carrierRestrictionRules == null) {
8232 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008233 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 final long identity = Binder.clearCallingIdentity();
8236 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008237 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008238 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008239 } finally {
8240 Binder.restoreCallingIdentity(identity);
8241 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008242 }
8243
8244 /**
8245 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008246 * Get the allowed carrier list and the excluded carrier list, including the priority between
8247 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008248 * Require system privileges. In the future we may add this to carrier APIs.
8249 *
Michele Berionne482f8202018-11-27 18:57:59 -08008250 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008251 */
8252 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008253 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008254 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008255 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256
8257 final long identity = Binder.clearCallingIdentity();
8258 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008259 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8260 if (response instanceof CarrierRestrictionRules) {
8261 return (CarrierRestrictionRules) response;
8262 }
8263 // Response is an Exception of some kind,
8264 // which is signalled to the user as a NULL retval
8265 return null;
8266 } catch (Exception e) {
8267 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8268 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008272 }
8273
fionaxu59545b42016-05-25 15:53:37 -07008274 /**
fionaxu59545b42016-05-25 15:53:37 -07008275 * Action set from carrier signalling broadcast receivers to enable/disable radio
8276 * @param subId the subscription ID that this action applies to.
8277 * @param enabled control enable or disable radio.
8278 * {@hide}
8279 */
8280 @Override
8281 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8282 enforceModifyPermission();
8283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284
8285 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008286 if (phone == null) {
8287 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8288 return;
8289 }
8290 try {
8291 phone.carrierActionSetRadioEnabled(enabled);
8292 } catch (Exception e) {
8293 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 } finally {
8295 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008296 }
8297 }
8298
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008299 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008300 * Enable or disable Voice over NR (VoNR)
8301 * @param subId the subscription ID that this action applies to.
8302 * @param enabled enable or disable VoNR.
8303 * @return operation result.
8304 */
8305 @Override
8306 public int setVoNrEnabled(int subId, boolean enabled) {
8307 enforceModifyPermission();
8308 final Phone phone = getPhone(subId);
8309
8310 final long identity = Binder.clearCallingIdentity();
8311 if (phone == null) {
8312 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8313 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8314 }
8315
8316 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8317 try {
8318 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8319 workSource);
8320 if (DBG) log("setVoNrEnabled result: " + result);
8321 return result;
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
8324 }
8325 }
8326
8327 /**
8328 * Is voice over NR enabled
8329 * @return true if VoNR is enabled else false
8330 */
8331 @Override
8332 public boolean isVoNrEnabled(int subId) {
8333 enforceReadPrivilegedPermission("isVoNrEnabled");
8334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8335 final long identity = Binder.clearCallingIdentity();
8336 try {
8337 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8338 null, subId, workSource);
8339 if (DBG) log("isVoNrEnabled: " + isEnabled);
8340 return isEnabled;
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 }
8345
8346 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008347 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8348 * network status based on which carrier apps could apply actions accordingly,
8349 * enable/disable default url handler for example.
8350 *
8351 * @param subId the subscription ID that this action applies to.
8352 * @param report control start/stop reporting the default network status.
8353 * {@hide}
8354 */
8355 @Override
8356 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8357 enforceModifyPermission();
8358 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359
8360 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008361 if (phone == null) {
8362 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8363 return;
8364 }
8365 try {
8366 phone.carrierActionReportDefaultNetworkStatus(report);
8367 } catch (Exception e) {
8368 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 } finally {
8370 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008371 }
8372 }
8373
8374 /**
fionaxud9622282017-07-17 17:51:30 -07008375 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8376 * @param subId the subscription ID that this action applies to.
8377 * {@hide}
8378 */
8379 @Override
8380 public void carrierActionResetAll(int subId) {
8381 enforceModifyPermission();
8382 final Phone phone = getPhone(subId);
8383 if (phone == null) {
8384 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8385 return;
8386 }
8387 try {
8388 phone.carrierActionResetAll();
8389 } catch (Exception e) {
8390 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8391 }
8392 }
8393
8394 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008395 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8396 * bug report is being generated.
8397 */
8398 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008399 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008400 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8401 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008402 writer.println("Permission Denial: can't dump Phone from pid="
8403 + Binder.getCallingPid()
8404 + ", uid=" + Binder.getCallingUid()
8405 + "without permission "
8406 + android.Manifest.permission.DUMP);
8407 return;
8408 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008409 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008410 }
Jack Yueb89b242016-06-22 13:27:47 -07008411
Brad Ebingerdac2f002018-04-03 15:17:52 -07008412 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008413 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8414 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8415 @NonNull String[] args) {
8416 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8417 this, in.getFileDescriptor(), out.getFileDescriptor(),
8418 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008419 }
8420
Jack Yueb89b242016-06-22 13:27:47 -07008421 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008422 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008423 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008424 * @param reason the reason the data enable change is taking place
8425 * @param enabled True if enabling the data, otherwise disabling.
8426 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008427 */
8428 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008429 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008430 boolean enabled) {
8431 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8432 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8433 try {
8434 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008435 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008436 } catch (SecurityException se) {
8437 enforceModifyPermission();
8438 }
8439 } else {
8440 enforceModifyPermission();
8441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442
8443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 Phone phone = getPhone(subId);
8446 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008447 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8448 phone.carrierActionSetMeteredApnsEnabled(enabled);
8449 } else {
8450 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452 }
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008455 }
8456 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008457
8458 /**
8459 * Get Client request stats
8460 * @return List of Client Request Stats
8461 * @hide
8462 */
8463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008464 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8465 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 return null;
8469 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008470 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 if (phone != null) {
8475 return phone.getClientRequestStats();
8476 }
8477
8478 return null;
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
8481 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008482 }
8483
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008484 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008485 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008486 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008487 }
Jack Yueb4124c2017-02-16 15:32:43 -08008488
8489 /**
Grace Chen70990072017-03-24 17:21:30 -07008490 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008491 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008492 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008493 * @param state State of SIM (power down, power up, pass through)
8494 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8495 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8496 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008497 *
8498 **/
8499 @Override
Grace Chen70990072017-03-24 17:21:30 -07008500 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008501 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008502 Phone phone = PhoneFactory.getPhone(slotIndex);
8503
vagdeviaf9a5b92018-08-15 16:01:53 -07008504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008509 phone.setSimPowerState(state, null, workSource);
8510 }
8511 } finally {
8512 Binder.restoreCallingIdentity(identity);
8513 }
8514 }
8515
8516 /**
8517 * Set SIM card power state.
8518 *
8519 * @param slotIndex SIM slot id.
8520 * @param state State of SIM (power down, power up, pass through)
8521 * @param callback callback to trigger after success or failure
8522 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8523 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8524 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8525 *
8526 **/
8527 @Override
8528 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8529 IIntegerConsumer callback) {
8530 enforceModifyPermission();
8531 Phone phone = PhoneFactory.getPhone(slotIndex);
8532
8533 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8534
8535 final long identity = Binder.clearCallingIdentity();
8536 try {
8537 if (phone != null) {
8538 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8539 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540 }
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008543 }
8544 }
Shuo Qiandd210312017-04-12 22:11:33 +00008545
Tyler Gunn65d45c22017-06-05 11:22:26 -07008546 private boolean isUssdApiAllowed(int subId) {
8547 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008548 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008549 if (configManager == null) {
8550 return false;
8551 }
8552 PersistableBundle pb = configManager.getConfigForSubId(subId);
8553 if (pb == null) {
8554 return false;
8555 }
8556 return pb.getBoolean(
8557 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8558 }
8559
Shuo Qiandd210312017-04-12 22:11:33 +00008560 /**
8561 * Check if phone is in emergency callback mode
8562 * @return true if phone is in emergency callback mode
8563 * @param subId sub id
8564 */
goneil9c5f4872017-12-05 14:07:56 -08008565 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008566 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008567 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008568 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 if (phone != null) {
8573 return phone.isInEcm();
8574 } else {
8575 return false;
8576 }
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008579 }
8580 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008581
8582 /**
8583 * Get the current signal strength information for the given subscription.
8584 * Because this information is not updated when the device is in a low power state
8585 * it should not be relied-upon to be current.
8586 * @param subId Subscription index
8587 * @return the most recent cached signal strength info from the modem
8588 */
8589 @Override
8590 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 Phone p = getPhone(subId);
8594 if (p == null) {
8595 return null;
8596 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 return p.getSignalStrength();
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008602 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008603
Pengquan Meng77b7f132018-08-22 14:49:57 -07008604 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008605 * Get the current modem radio state for the given slot.
8606 * @param slotIndex slot index.
8607 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008608 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008609 * @return the current radio power state from the modem
8610 */
8611 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008612 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008613 Phone phone = PhoneFactory.getPhone(slotIndex);
8614 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8616 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008617 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8618 }
8619
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 return phone.getRadioPowerState();
8623 } finally {
8624 Binder.restoreCallingIdentity(identity);
8625 }
8626 }
8627 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8628 }
8629
8630 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008631 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8632 *
8633 * <p>Requires one of the following permissions:
8634 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8635 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8636 * privileges.
8637 *
8638 * @param subId subscription id
8639 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8640 * {@code false}.
8641 */
8642 @Override
8643 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008644 try {
8645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8646 null);
8647 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008648 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008649 mApp, subId, "isDataRoamingEnabled");
8650 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008651
Pengquan Menga1bb6272018-09-06 09:59:22 -07008652 boolean isEnabled = false;
8653 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008654 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008655 Phone phone = getPhone(subId);
8656 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008657 } finally {
8658 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008660 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008661 }
8662
8663
8664 /**
8665 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8666 *
8667 * <p> Requires permission:
8668 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8669 * privileges.
8670 *
8671 * @param subId subscription id
8672 * @param isEnabled {@code true} means enable, {@code false} means disable.
8673 */
8674 @Override
8675 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8677 mApp, subId, "setDataRoamingEnabled");
8678
Pengquan Menga1bb6272018-09-06 09:59:22 -07008679 final long identity = Binder.clearCallingIdentity();
8680 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008681 Phone phone = getPhone(subId);
8682 if (phone != null) {
8683 phone.setDataRoamingEnabled(isEnabled);
8684 }
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008687 }
8688 }
8689
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008690 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008691 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008692 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008693 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008694 mApp, subId, "isManualNetworkSelectionAllowed");
8695
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008696 boolean isAllowed = true;
8697 final long identity = Binder.clearCallingIdentity();
8698 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008699 Phone phone = getPhone(subId);
8700 if (phone != null) {
8701 isAllowed = phone.isCspPlmnEnabled();
8702 }
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 return isAllowed;
8707 }
8708
8709 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008710 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008711 // Verify that tha callingPackage belongs to the calling UID
8712 mApp.getSystemService(AppOpsManager.class)
8713 .checkPackage(Binder.getCallingUid(), callingPackage);
8714
Jordan Liu1e142fc2019-04-22 15:10:43 -07008715 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008716 try {
8717 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008719 } catch (SecurityException e) {
8720 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8721 // has carrier privileges on an active UICC
8722 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8723 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008724 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008725 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008726 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008727
8728 final long identity = Binder.clearCallingIdentity();
8729 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008730 UiccController uiccController = UiccController.getInstance();
8731 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008732 if (hasReadPermission) {
8733 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008734 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008735
8736 // Remove private info if the caller doesn't have access
8737 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8738 for (UiccCardInfo cardInfo : cardInfos) {
8739 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8740 // is available
8741 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8742 if (card == null || card.getUiccProfile() == null) {
8743 // assume no access if the card or profile is unavailable
8744 filteredInfos.add(cardInfo.getUnprivileged());
8745 continue;
8746 }
8747 UiccProfile profile = card.getUiccProfile();
8748 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8749 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8750 filteredInfos.add(cardInfo);
8751 } else {
8752 filteredInfos.add(cardInfo.getUnprivileged());
8753 }
8754 }
8755 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008756 } finally {
8757 Binder.restoreCallingIdentity(identity);
8758 }
8759 }
8760
8761 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008762 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008763 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008765 final long identity = Binder.clearCallingIdentity();
8766 try {
8767 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8768 if (slots == null) {
8769 Rlog.i(LOG_TAG, "slots is null.");
8770 return null;
8771 }
8772
8773 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8774 for (int i = 0; i < slots.length; i++) {
8775 UiccSlot slot = slots[i];
8776 if (slot == null) {
8777 continue;
8778 }
8779
Jordan Liu7be7e652019-05-06 18:55:02 +00008780 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008781 UiccCard card = slot.getUiccCard();
8782 if (card != null) {
8783 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008784 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008785 cardId = slot.getEid();
8786 if (TextUtils.isEmpty(cardId)) {
8787 cardId = slot.getIccId();
8788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008789 }
8790
Jordan Liu857451f2019-05-09 16:35:35 -07008791 if (cardId != null) {
8792 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8793 // if cardId is an EID, it's all digits so this is fine
8794 cardId = IccUtils.stripTrailingFs(cardId);
8795 }
8796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008797 int cardState = 0;
8798 switch (slot.getCardState()) {
8799 case CARDSTATE_ABSENT:
8800 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8801 break;
8802 case CARDSTATE_PRESENT:
8803 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8804 break;
8805 case CARDSTATE_ERROR:
8806 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8807 break;
8808 case CARDSTATE_RESTRICTED:
8809 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8810 break;
8811 default:
8812 break;
8813
8814 }
8815
8816 infos[i] = new UiccSlotInfo(
8817 slot.isActive(),
8818 slot.isEuicc(),
8819 cardId,
8820 cardState,
8821 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008822 slot.isExtendedApduSupported(),
8823 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008824 }
8825 return infos;
8826 } finally {
8827 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008828 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008829 }
8830
8831 @Override
8832 public boolean switchSlots(int[] physicalSlots) {
8833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008834
8835 final long identity = Binder.clearCallingIdentity();
8836 try {
8837 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008841 }
Jack Yu4c988042018-02-27 15:30:01 -08008842
8843 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008844 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008845 final long identity = Binder.clearCallingIdentity();
8846 try {
8847 return UiccController.getInstance().getCardIdForDefaultEuicc();
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
8851 }
8852
Pengquan Meng85728fb2018-03-12 16:31:21 -07008853 /**
goneil47ffb6e2018-04-06 15:40:58 -07008854 * A test API to reload the UICC profile.
8855 *
8856 * <p>Requires that the calling app has permission
8857 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8858 * @hide
8859 */
8860 @Override
8861 public void refreshUiccProfile(int subId) {
8862 enforceModifyPermission();
8863
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 Phone phone = getPhone(subId);
8867 if (phone == null) {
8868 return;
8869 }
8870 UiccCard uiccCard = phone.getUiccCard();
8871 if (uiccCard == null) {
8872 return;
8873 }
8874 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8875 if (uiccProfile == null) {
8876 return;
8877 }
8878 uiccProfile.refresh();
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
8883
8884 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008885 * Returns false if the mobile data is disabled by default, otherwise return true.
8886 */
8887 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008888 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008889 }
8890
8891 /**
8892 * Returns true if the data roaming is enabled by default, i.e the system property
8893 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8894 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8895 */
8896 private boolean getDefaultDataRoamingEnabled(int subId) {
8897 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008898 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008899 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008900 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8901 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8902 return isDataRoamingEnabled;
8903 }
8904
8905 /**
8906 * Returns the default network type for the given {@code subId}, if the default network type is
8907 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8908 */
8909 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008910 List<Integer> list = TelephonyProperties.default_network();
8911 int phoneId = mSubscriptionController.getPhoneId(subId);
8912 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8913 return list.get(phoneId);
8914 }
8915 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008916 }
fionaxua13278b2018-03-21 00:08:13 -07008917
8918 @Override
8919 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008920 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008921 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 final Phone phone = getPhone(subId);
8926 if (phone == null) {
8927 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8928 return;
8929 }
chen xueaba88a2019-03-15 13:15:10 -07008930 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8931 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008932 if (carrierPrivilegeRules == null) {
8933 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8934 } else {
8935 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 } finally {
8938 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008939 }
fionaxua13278b2018-03-21 00:08:13 -07008940 }
8941
8942 @Override
8943 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008944 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945
8946 final long identity = Binder.clearCallingIdentity();
8947 try {
8948 final Phone phone = getPhone(subId);
8949 if (phone == null) {
8950 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8951 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8952 }
8953 return phone.getCarrierIdListVersion();
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008956 }
fionaxua13278b2018-03-21 00:08:13 -07008957 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008958
8959 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008960 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8961 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008963 mApp, subId, callingPackage, callingFeatureId,
8964 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008965 return -1;
8966 }
8967
8968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8971 } finally {
8972 Binder.restoreCallingIdentity(identity);
8973 }
8974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008975
8976 @Override
8977 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008978 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008979 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008980 mApp, subId, "getCdmaRoamingMode");
8981
8982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
8988 }
8989
8990 @Override
8991 public boolean setCdmaRoamingMode(int subId, int mode) {
8992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8993 mApp, subId, "setCdmaRoamingMode");
8994
8995 final long identity = Binder.clearCallingIdentity();
8996 try {
8997 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8998 } finally {
8999 Binder.restoreCallingIdentity(identity);
9000 }
9001 }
9002
9003 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009004 public int getCdmaSubscriptionMode(int subId) {
9005 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009006 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009007 mApp, subId, "getCdmaSubscriptionMode");
9008
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016
9017 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009018 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9020 mApp, subId, "setCdmaSubscriptionMode");
9021
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9025 } finally {
9026 Binder.restoreCallingIdentity(identity);
9027 }
9028 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009029
sqianc5eccab2018-10-19 18:46:41 -07009030 @Override
sqian8c685422019-02-22 15:55:18 -08009031 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009032 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009034 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9035 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009036 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9037 }
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
sqian854d44b2018-12-12 16:48:18 -08009040 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9041 for (Phone phone: PhoneFactory.getPhones()) {
9042 if (phone.getEmergencyNumberTracker() != null
9043 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9044 emergencyNumberListInternal.put(
9045 phone.getSubId(),
9046 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9047 }
sqian11b7a0e2018-12-05 18:48:28 -08009048 }
sqian854d44b2018-12-12 16:48:18 -08009049 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
sqianc5eccab2018-10-19 18:46:41 -07009053 }
9054
9055 @Override
sqian8c685422019-02-22 15:55:18 -08009056 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009057 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009058 if (!exactMatch) {
9059 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009060 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009061 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009062 }
9063 final long identity = Binder.clearCallingIdentity();
9064 try {
sqian854d44b2018-12-12 16:48:18 -08009065 for (Phone phone: PhoneFactory.getPhones()) {
9066 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009067 && phone.getEmergencyNumberTracker()
9068 .isEmergencyNumber(number, exactMatch)) {
9069 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009070 }
sqian11b7a0e2018-12-05 18:48:28 -08009071 }
9072 return false;
9073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
9076 }
9077
sqianf4ca7ed2019-01-15 18:32:07 -08009078 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009079 * Start emergency callback mode for GsmCdmaPhone for testing.
9080 */
9081 @Override
9082 public void startEmergencyCallbackMode() {
9083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9084 "startEmergencyCallbackMode");
9085 enforceModifyPermission();
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 for (Phone phone : PhoneFactory.getPhones()) {
9089 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9090 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9091 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9092 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9093 gsmCdmaPhone.obtainMessage(
9094 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9095 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9096 }
9097 }
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
9100 }
9101 }
9102
9103 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009104 * Update emergency number list for test mode.
9105 */
9106 @Override
9107 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9109 "updateEmergencyNumberListTestMode");
9110
9111 final long identity = Binder.clearCallingIdentity();
9112 try {
9113 for (Phone phone: PhoneFactory.getPhones()) {
9114 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9115 if (tracker != null) {
9116 tracker.executeEmergencyNumberTestModeCommand(action, num);
9117 }
9118 }
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
9121 }
9122 }
9123
9124 /**
9125 * Get the full emergency number list for test mode.
9126 */
9127 @Override
9128 public List<String> getEmergencyNumberListTestMode() {
9129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9130 "getEmergencyNumberListTestMode");
9131
9132 final long identity = Binder.clearCallingIdentity();
9133 try {
9134 Set<String> emergencyNumbers = new HashSet<>();
9135 for (Phone phone: PhoneFactory.getPhones()) {
9136 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9137 if (tracker != null) {
9138 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9139 emergencyNumbers.add(num.getNumber());
9140 }
9141 }
9142 }
9143 return new ArrayList<>(emergencyNumbers);
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
9146 }
9147 }
9148
chen xud6b45bd2018-10-30 22:27:10 -07009149 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009150 public int getEmergencyNumberDbVersion(int subId) {
9151 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9152
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 final Phone phone = getPhone(subId);
9156 if (phone == null) {
9157 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9158 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9159 }
9160 return phone.getEmergencyNumberDbVersion();
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
9166 @Override
9167 public void notifyOtaEmergencyNumberDbInstalled() {
9168 enforceModifyPermission();
9169
9170 final long identity = Binder.clearCallingIdentity();
9171 try {
9172 for (Phone phone: PhoneFactory.getPhones()) {
9173 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9174 if (tracker != null) {
9175 tracker.updateOtaEmergencyNumberDatabase();
9176 }
9177 }
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 }
9182
9183 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009184 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009185 enforceActiveEmergencySessionPermission();
9186
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
9189 for (Phone phone: PhoneFactory.getPhones()) {
9190 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9191 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009192 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9193 }
9194 }
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
9200 @Override
9201 public void resetOtaEmergencyNumberDbFilePath() {
9202 enforceActiveEmergencySessionPermission();
9203
9204 final long identity = Binder.clearCallingIdentity();
9205 try {
9206 for (Phone phone: PhoneFactory.getPhones()) {
9207 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9208 if (tracker != null) {
9209 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009210 }
9211 }
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
9217 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009218 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9219 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9220 Phone phone = getPhone(subId);
9221 if (phone == null) {
9222 return null;
9223 }
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
9226 UiccProfile profile = UiccController.getInstance()
9227 .getUiccProfileForPhone(phone.getPhoneId());
9228 if (profile != null) {
9229 return profile.getCertsFromCarrierPrivilegeAccessRules();
9230 }
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 return null;
9235 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009236
9237 /**
9238 * Enable or disable a modem stack.
9239 */
9240 @Override
9241 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9242 enforceModifyPermission();
9243
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 Phone phone = PhoneFactory.getPhone(slotIndex);
9247 if (phone == null) {
9248 return false;
9249 } else {
9250 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9251 }
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
Michelecea4cf22018-12-21 15:00:11 -08009256
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009257 /**
9258 * Whether a modem stack is enabled or not.
9259 */
9260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009261 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9262 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009263 Phone phone = PhoneFactory.getPhone(slotIndex);
9264 if (phone == null) return false;
9265
9266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009267 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9268 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009269 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9270 }
9271
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009274 try {
9275 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9276 } catch (NoSuchElementException ex) {
9277 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9278 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
9283
Michelecea4cf22018-12-21 15:00:11 -08009284 @Override
Michele0ea7d782019-03-19 14:58:42 -07009285 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009286 enforceModifyPermission();
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009291 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009292 .commit();
9293 } finally {
9294 Binder.restoreCallingIdentity(identity);
9295 }
9296 }
9297
9298 @Override
Michele0ea7d782019-03-19 14:58:42 -07009299 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009300 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009302 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9303 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009304 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009305 }
Michelecea4cf22018-12-21 15:00:11 -08009306
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
Michele0ea7d782019-03-19 14:58:42 -07009309 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009314
Michele0ea7d782019-03-19 14:58:42 -07009315 @TelephonyManager.IsMultiSimSupportedResult
9316 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009317 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9318 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9319 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009320 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9321 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009322 }
9323 // Check if the hardware supports multisim functionality. If usage of multisim is not
9324 // supported by the modem, indicate that it is restricted.
9325 PhoneCapability staticCapability =
9326 mPhoneConfigurationManager.getStaticPhoneCapability();
9327 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009328 loge("isMultiSimSupportedInternal: no static configuration available");
9329 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009330 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009331 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009332 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9333 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009334 }
9335 // Check if support of multiple SIMs is restricted by carrier
9336 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009337 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009338 }
9339
Michele0ea7d782019-03-19 14:58:42 -07009340 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009341 }
9342
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009343 /**
9344 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009345 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9346 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9347 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009348 * @param numOfSims number of active sims we want to switch to
9349 */
9350 @Override
9351 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009352 if (numOfSims == 1) {
9353 enforceModifyPermission();
9354 } else {
9355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9356 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9357 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009358 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009359
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009360 try {
Michele30b57b22019-03-01 12:01:14 -08009361 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009362 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009363 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9364 return;
9365 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009366 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 }
9371
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009372 @Override
9373 public boolean isApplicationOnUicc(int subId, int appType) {
9374 enforceReadPrivilegedPermission("isApplicationOnUicc");
9375 Phone phone = getPhone(subId);
9376 if (phone == null) {
9377 return false;
9378 }
9379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 UiccCard uiccCard = phone.getUiccCard();
9382 if (uiccCard == null) {
9383 return false;
9384 }
9385 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9386 if (uiccProfile == null) {
9387 return false;
9388 }
9389 if (TelephonyManager.APPTYPE_SIM <= appType
9390 && appType <= TelephonyManager.APPTYPE_ISIM) {
9391 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9392 }
9393 return false;
9394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
9397 }
9398
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009399 /**
chen xub4baa772019-04-03 10:23:41 -07009400 * Get whether making changes to modem configurations will trigger reboot.
9401 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009402 */
9403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009404 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9405 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009407 mApp, subId, callingPackage, callingFeatureId,
9408 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009409 return false;
9410 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009411 final long identity = Binder.clearCallingIdentity();
9412 try {
9413 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9414 } finally {
9415 Binder.restoreCallingIdentity(identity);
9416 }
9417 }
9418
Nathan Harold29f5f052019-02-15 13:41:57 -08009419 private void updateModemStateMetrics() {
9420 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9421 // TODO: check the state for each modem if the api is ready.
9422 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9423 }
9424
Pengquan Meng3889a572019-01-23 11:16:29 -08009425 @Override
9426 public int[] getSlotsMapping() {
9427 enforceReadPrivilegedPermission("getSlotsMapping");
9428
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
9431 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9432 // All logical slots should have a mapping to a physical slot.
9433 int[] logicalSlotsMapping = new int[phoneCount];
9434 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9435 for (int i = 0; i < slotInfos.length; i++) {
9436 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9437 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9438 }
9439 }
9440 return logicalSlotsMapping;
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009445
9446 /**
9447 * Get the IRadio HAL Version
9448 */
9449 @Override
9450 public int getRadioHalVersion() {
9451 Phone phone = getDefaultPhone();
9452 if (phone == null) return -1;
9453 HalVersion hv = phone.getHalVersion();
9454 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9455 return hv.major * 100 + hv.minor;
9456 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009457
9458 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009459 * Get the current calling package name.
9460 * @return the current calling package name
9461 */
9462 @Override
9463 public String getCurrentPackageName() {
9464 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9465 }
9466
9467 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009468 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9469 * corresponding network requests on a subId.
9470 *
9471 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009472 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009473 * 2) APN is un-metered for this subscription, or
9474 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009475 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009476 *
9477 * @return whether data is allowed for a apn type.
9478 *
9479 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009480 */
9481 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009482 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009483 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9484 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009485
9486 // Now that all security checks passes, perform the operation as ourselves.
9487 final long identity = Binder.clearCallingIdentity();
9488 try {
9489 Phone phone = getPhone(subId);
9490 if (phone == null) return false;
9491
Jack Yu41407ee2019-05-13 16:54:09 -07009492 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009493 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9494 } finally {
9495 Binder.restoreCallingIdentity(identity);
9496 }
9497 }
9498
9499 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009500 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009501 enforceReadPrivilegedPermission("isApnMetered");
9502
9503 // Now that all security checks passes, perform the operation as ourselves.
9504 final long identity = Binder.clearCallingIdentity();
9505 try {
9506 Phone phone = getPhone(subId);
9507 if (phone == null) return true; // By default return true.
9508
Jack Yu41407ee2019-05-13 16:54:09 -07009509 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009514
9515 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009516 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9517 int subscriptionId, IBooleanConsumer resultCallback) {
9518 enforceModifyPermission();
9519 long token = Binder.clearCallingIdentity();
9520 try {
9521 Phone phone = getPhone(subscriptionId);
9522 if (phone == null) {
9523 try {
9524 if (resultCallback != null) {
9525 resultCallback.accept(false);
9526 }
9527 } catch (RemoteException e) {
9528 // ignore
9529 }
9530 return;
9531 }
9532 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9533 Pair.create(specifiers, (x) -> {
9534 try {
9535 if (resultCallback != null) {
9536 resultCallback.accept(x);
9537 }
9538 } catch (RemoteException e) {
9539 // ignore
9540 }
9541 });
9542 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9543 } finally {
9544 Binder.restoreCallingIdentity(token);
9545 }
9546 }
9547
9548 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009549 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9550 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009551 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009552 mApp, subId, "getSystemSelectionChannels");
9553 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9554 final long identity = Binder.clearCallingIdentity();
9555 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009556 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9557 if (result instanceof IllegalStateException) {
9558 throw (IllegalStateException) result;
9559 }
9560 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009561 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9562 return specifiers;
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
9568 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009569 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009570 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009571 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9572 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9573 if (iccRecords == null) {
9574 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9575 return false;
9576 }
9577 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9578 }
9579
9580 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009581 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9582 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009583 if (callingPackage == null) {
9584 callingPackage = getCurrentPackageName();
9585 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009586 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9587 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009588 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9589 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009590 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9591 }
9592 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9593 Intent intent = new Intent();
9594 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9595 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9596 // Bring up choose default SMS subscription dialog right now
9597 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9598 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9599 mApp.startActivity(intent);
9600 }
chen xud5ca2d52019-05-28 15:20:57 -07009601
9602 @Override
9603 public String getMmsUAProfUrl(int subId) {
9604 //TODO investigate if this API should require proper permission check in R b/133791609
9605 final long identity = Binder.clearCallingIdentity();
9606 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009607 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9608 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9609 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9610 return carrierUAProfUrl;
9611 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009612 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9613 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 @Override
9620 public String getMmsUserAgent(int subId) {
9621 //TODO investigate if this API should require proper permission check in R b/133791609
9622 final long identity = Binder.clearCallingIdentity();
9623 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009624 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9625 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9626 if (!TextUtils.isEmpty(carrierUserAgent)) {
9627 return carrierUserAgent;
9628 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009629 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9630 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009631 } finally {
9632 Binder.restoreCallingIdentity(identity);
9633 }
9634 }
Jack Yub07d4972019-05-28 16:12:25 -07009635
9636 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009637 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9638 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009639
Jack Yub07d4972019-05-28 16:12:25 -07009640 final long identity = Binder.clearCallingIdentity();
9641 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009642 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009643 if (phone == null) return false;
9644
Hall Liua62f5da2020-09-25 10:42:19 -07009645 switch (policy) {
9646 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9647 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9648 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9649 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9650 default:
9651 throw new IllegalArgumentException(policy + " is not a valid policy");
9652 }
Jack Yub07d4972019-05-28 16:12:25 -07009653 } finally {
9654 Binder.restoreCallingIdentity(identity);
9655 }
9656 }
9657
9658 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009659 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009660 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009661 enforceModifyPermission();
9662
changbettyd5c246e2019-12-24 15:40:37 +08009663 final long identity = Binder.clearCallingIdentity();
9664 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009665 Phone phone = getPhone(subscriptionId);
9666 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009667
Hall Liua62f5da2020-09-25 10:42:19 -07009668 switch (policy) {
9669 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9670 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9671 break;
9672 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9673 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9674 break;
9675 default:
9676 throw new IllegalArgumentException(policy + " is not a valid policy");
9677 }
changbettyd5c246e2019-12-24 15:40:37 +08009678 } finally {
9679 Binder.restoreCallingIdentity(identity);
9680 }
9681 }
9682
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009683 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009684 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009685 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9686 * otherwise.
9687 */
9688 @Override
9689 public void setCepEnabled(boolean isCepEnabled) {
9690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9691
9692 final long identity = Binder.clearCallingIdentity();
9693 try {
9694 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9695 for (Phone phone : PhoneFactory.getPhones()) {
9696 Phone defaultPhone = phone.getImsPhone();
9697 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9698 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9699 ImsPhoneCallTracker imsPhoneCallTracker =
9700 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9701 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9702 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9703 + imsPhone.getMsisdn());
9704 }
9705 }
9706 } finally {
9707 Binder.restoreCallingIdentity(identity);
9708 }
9709 }
allenwtsu46dcc572020-01-08 18:24:03 +08009710
9711 /**
9712 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9713 *
9714 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9715 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9716 * before being read.
9717 */
9718 @Override
9719 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9720 isCompressed) {
9721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9722 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9725 }
9726 if (!isImsAvailableOnDevice()) {
9727 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9728 "IMS not available on device.");
9729 }
9730
9731 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009732 try {
Hui Wang761a6682020-10-31 05:12:53 +00009733 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9734 } finally {
9735 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009736 }
9737 }
zoey chene02881a2019-12-30 16:11:23 +08009738
9739 @Override
9740 public boolean isIccLockEnabled(int subId) {
9741 enforceReadPrivilegedPermission("isIccLockEnabled");
9742
9743 // Now that all security checks passes, perform the operation as ourselves.
9744 final long identity = Binder.clearCallingIdentity();
9745 try {
9746 Phone phone = getPhone(subId);
9747 if (phone != null && phone.getIccCard() != null) {
9748 return phone.getIccCard().getIccLockEnabled();
9749 } else {
9750 return false;
9751 }
9752 } finally {
9753 Binder.restoreCallingIdentity(identity);
9754 }
9755 }
9756
9757 /**
9758 * Set the ICC pin lock enabled or disabled.
9759 *
9760 * @return an integer representing the status of IccLock enabled or disabled in the following
9761 * three cases:
9762 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9763 * successfully.
9764 * - Positive number and zero for remaining password attempts.
9765 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9766 *
9767 */
9768 @Override
9769 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9770 enforceModifyPermission();
9771
9772 Phone phone = getPhone(subId);
9773 if (phone == null) {
9774 return 0;
9775 }
9776 // Now that all security checks passes, perform the operation as ourselves.
9777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9780 new Pair<Boolean, String>(enabled, password), phone, null);
9781 return attemptsRemaining;
9782
9783 } catch (Exception e) {
9784 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9785 } finally {
9786 Binder.restoreCallingIdentity(identity);
9787 }
9788 return 0;
9789 }
9790
9791 /**
9792 * Change the ICC password used in ICC pin lock.
9793 *
9794 * @return an integer representing the status of IccLock changed in the following three cases:
9795 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9796 * - Positive number and zero for remaining password attempts.
9797 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9798 *
9799 */
9800 @Override
9801 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9802 enforceModifyPermission();
9803
9804 Phone phone = getPhone(subId);
9805 if (phone == null) {
9806 return 0;
9807 }
9808 // Now that all security checks passes, perform the operation as ourselves.
9809 final long identity = Binder.clearCallingIdentity();
9810 try {
9811 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9812 new Pair<String, String>(oldPassword, newPassword), phone, null);
9813 return attemptsRemaining;
9814
9815 } catch (Exception e) {
9816 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9817 } finally {
9818 Binder.restoreCallingIdentity(identity);
9819 }
9820 return 0;
9821 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009822
9823 /**
9824 * Request for receiving user activity notification
9825 */
9826 @Override
9827 public void requestUserActivityNotification() {
9828 if (!mNotifyUserActivity.get()
9829 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9830 mNotifyUserActivity.set(true);
9831 }
9832 }
9833
9834 /**
9835 * Called when userActivity is signalled in the power manager.
9836 * This is safe to call from any thread, with any window manager locks held or not.
9837 */
9838 @Override
9839 public void userActivity() {
9840 // ***************************************
9841 // * Inherited from PhoneWindowManager *
9842 // ***************************************
9843 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9844 // WITH ITS LOCKS HELD.
9845 //
9846 // This code must be VERY careful about the locks
9847 // it acquires.
9848 // In fact, the current code acquires way too many,
9849 // and probably has lurking deadlocks.
9850
9851 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9852 throw new SecurityException("Only the OS may call notifyUserActivity()");
9853 }
9854
9855 if (mNotifyUserActivity.getAndSet(false)) {
9856 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9857 USER_ACTIVITY_NOTIFICATION_DELAY);
9858 }
9859 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009860
9861 @Override
9862 public boolean canConnectTo5GInDsdsMode() {
9863 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9864 }
Jack Yud10cdd42020-09-28 20:28:01 -07009865
9866 @Override
9867 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9868 String callingFeatureId) {
9869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9870 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9871 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9872 }
9873
9874 Phone phone = getPhone(subId);
9875 if (phone == null) {
9876 throw new RuntimeException("phone is not available");
9877 }
9878 // Now that all security checks passes, perform the operation as ourselves.
9879 final long identity = Binder.clearCallingIdentity();
9880 try {
9881 return phone.getEquivalentHomePlmns();
9882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
Daniel Bright59e67312020-11-13 11:49:37 -08009886
9887 @Override
9888 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009889 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9890 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009891 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009892 if (radioInterfaceCapabilities == null) {
9893 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009894 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009895 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009896 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009897
Hui Wang641e81c2020-10-12 12:14:23 -07009898 @Override
9899 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9900 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009901 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9902 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9903 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9904 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9905 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009906 if (DBG) {
9907 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9908 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9909 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9910 }
9911
9912 if (!SubscriptionManager.isValidSubscriptionId(subId)
9913 || appType < TelephonyManager.APPTYPE_UNKNOWN
9914 || appType > TelephonyManager.APPTYPE_ISIM
9915 || nafUrl == null || securityProtocol == null || callback == null) {
9916 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9917 if (callback != null) {
9918 try {
9919 callback.onAuthenticationFailure(
9920 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9921 } catch (RemoteException exception) {
9922 log("Fail to notify onAuthenticationFailure due to " + exception);
9923 }
9924 return;
9925 }
9926 }
9927
9928 final long token = Binder.clearCallingIdentity();
9929 try {
9930 getGbaManager(subId).bootstrapAuthenticationRequest(
9931 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9932 forceBootStrapping, callback));
9933 } finally {
9934 Binder.restoreCallingIdentity(token);
9935 }
9936 }
9937
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009938 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009939 * Attempts to set the radio power state for all phones for thermal reason.
9940 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009941 * requested radio power state will actually be set. See {@link
9942 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9943 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009944 * @param enable {@code true} if trying to turn radio on.
9945 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9946 * false}.
9947 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009948 private boolean setRadioPowerForThermal(boolean enable) {
9949 boolean isPhoneAvailable = false;
9950 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9951 Phone phone = PhoneFactory.getPhone(i);
9952 if (phone != null) {
9953 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9954 isPhoneAvailable = true;
9955 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009956 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009957
9958 // return true if successfully informed the phone object about the thermal radio power
9959 // request.
9960 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009961 }
9962
9963 private int handleDataThrottlingRequest(int subId,
9964 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009965 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9966 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9967 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9968 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9969 throw new IllegalArgumentException("modem does not support data throttling");
9970 }
9971
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009972 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9973 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009974 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009975 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9976 }
9977
9978 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9979
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009980 if (isDataThrottlingSupported) {
9981 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009982 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009983 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9984 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9985 } else if (thermalMitigationResult
9986 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009987 log("Modem likely does not support data throttling on secondary carrier. Data " +
9988 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9989 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009990 }
9991 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009992 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009993
9994 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009995 }
9996
Jack Nudelman644b91a2021-03-12 14:09:48 -08009997 private static List<String> getThermalMitigationAllowlist(Context context) {
9998 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9999 for (String pckg : context.getResources()
10000 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10001 sThermalMitigationAllowlistedPackages.add(pckg);
10002 }
10003 }
10004
10005 return sThermalMitigationAllowlistedPackages;
10006 }
10007
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010008 private boolean isAnyPhoneInEmergencyState() {
10009 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10010 if (tm.isInEmergencyCall()) {
10011 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10012 return true;
10013 }
10014 for (Phone phone : PhoneFactory.getPhones()) {
10015 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10016 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10017 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10018 + phone.isInEcm());
10019 return true;
10020 }
10021 }
10022
10023 return false;
10024 }
10025
Jack Nudelman644b91a2021-03-12 14:09:48 -080010026 /**
10027 * Used by shell commands to add an authorized package name for thermal mitigation.
10028 * @param packageName name of package to be allowlisted
10029 * @param context
10030 */
10031 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10032 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10033 sThermalMitigationAllowlistedPackages.add(packageName);
10034 }
10035
10036 /**
10037 * Used by shell commands to remove an authorized package name for thermal mitigation.
10038 * @param packageName name of package to remove from allowlist
10039 * @param context
10040 */
10041 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10042 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10043 sThermalMitigationAllowlistedPackages.remove(packageName);
10044 }
10045
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010046 /**
10047 * Thermal mitigation request to control functionalities at modem.
10048 *
10049 * @param subId the id of the subscription.
10050 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010051 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010052 *
10053 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10054 */
10055 @Override
10056 @ThermalMitigationResult
10057 public int sendThermalMitigationRequest(
10058 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010059 ThermalMitigationRequest thermalMitigationRequest,
10060 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010061 enforceModifyPermission();
10062
Jack Nudelman644b91a2021-03-12 14:09:48 -080010063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10064 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10065 .contains(callingPackage)) {
10066 throw new SecurityException("Calling package must be configured in the device config. "
10067 + "calling package: " + callingPackage);
10068 }
10069
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010070 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10071 final long identity = Binder.clearCallingIdentity();
10072
10073 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10074 try {
10075 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10076 switch (thermalMitigationAction) {
10077 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10078 thermalMitigationResult =
10079 handleDataThrottlingRequest(subId,
10080 thermalMitigationRequest.getDataThrottlingRequest());
10081 break;
10082 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10083 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10084 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10085 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10086 }
10087
10088 // Ensure that radio is on. If not able to power on due to phone being
10089 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010090 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010091 thermalMitigationResult =
10092 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10093 break;
10094 }
10095
10096 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10097 false);
10098 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10099 break;
10100 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10101 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10102 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10103 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10104 }
10105
10106 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10107 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010108 Phone phone = getPhone(subId);
10109 if (phone == null) {
10110 thermalMitigationResult =
10111 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10112 break;
10113 }
10114
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010115 TelephonyConnectionService service =
10116 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010117 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010118 Log.e(LOG_TAG, "An emergency call is pending");
10119 thermalMitigationResult =
10120 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10121 break;
10122 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010123 thermalMitigationResult =
10124 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10125 break;
10126 }
10127 } else {
10128 thermalMitigationResult =
10129 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10130 break;
10131 }
10132
10133 // Turn radio off. If not able to power off due to phone being unavailable,
10134 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010135 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010136 thermalMitigationResult =
10137 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10138 break;
10139 }
10140 thermalMitigationResult =
10141 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10142 break;
10143 default:
10144 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10145 + "not exist. Requested action: " + thermalMitigationAction);
10146 }
10147 } catch (IllegalArgumentException e) {
10148 throw e;
10149 } catch (Exception e) {
10150 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10151 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10152 } finally {
10153 Binder.restoreCallingIdentity(identity);
10154 }
10155
10156 if (DBG) {
10157 log("thermalMitigationRequest returning with thermalMitigationResult: "
10158 + thermalMitigationResult);
10159 }
10160
10161 return thermalMitigationResult;
10162 }
Hui Wang641e81c2020-10-12 12:14:23 -070010163
10164 /**
10165 * Set the GbaService Package Name that Telephony will bind to.
10166 *
10167 * @param subId The sim that the GbaService is associated with.
10168 * @param packageName The name of the package to be replaced with.
10169 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10170 */
10171 @Override
10172 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10173 enforceModifyPermission();
10174
10175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 return getGbaManager(subId).overrideServicePackage(packageName);
10178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
10182
10183 /**
10184 * Return the package name of the currently bound GbaService.
10185 *
10186 * @param subId The sim that the GbaService is associated with.
10187 * @return the package name of the GbaService configuration, null if GBA is not supported.
10188 */
10189 @Override
10190 public String getBoundGbaService(int subId) {
10191 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10192
10193 final long identity = Binder.clearCallingIdentity();
10194 try {
10195 return getGbaManager(subId).getServicePackage();
10196 } finally {
10197 Binder.restoreCallingIdentity(identity);
10198 }
10199 }
10200
10201 /**
10202 * Set the release time for telephony to unbind GbaService.
10203 *
10204 * @param subId The sim that the GbaService is associated with.
10205 * @param interval The release time to unbind GbaService by millisecond.
10206 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10207 */
10208 @Override
10209 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10210 enforceModifyPermission();
10211
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
10214 return getGbaManager(subId).overrideReleaseTime(interval);
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
10219
10220 /**
10221 * Return the release time for telephony to unbind GbaService.
10222 *
10223 * @param subId The sim that the GbaService is associated with.
10224 * @return The release time to unbind GbaService by millisecond.
10225 */
10226 @Override
10227 public int getGbaReleaseTime(int subId) {
10228 enforceReadPrivilegedPermission("getGbaReleaseTime");
10229
10230 final long identity = Binder.clearCallingIdentity();
10231 try {
10232 return getGbaManager(subId).getReleaseTime();
10233 } finally {
10234 Binder.restoreCallingIdentity(identity);
10235 }
10236 }
10237
10238 private GbaManager getGbaManager(int subId) {
10239 GbaManager instance = GbaManager.getInstance(subId);
10240 if (instance == null) {
10241 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10242 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10243 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10244 }
10245 return instance;
10246 }
Hui Wang761a6682020-10-31 05:12:53 +000010247
10248 /**
10249 * indicate whether the device and the carrier can support
10250 * RCS VoLTE single registration.
10251 */
10252 @Override
10253 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010254 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10255 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10256 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10257 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010258
10259 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10260 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10261 }
10262
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10266 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010267 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10268 if (isCapable != null) {
10269 return isCapable;
10270 }
Hui Wang761a6682020-10-31 05:12:53 +000010271 }
Hui Wang67af90e2021-06-04 16:57:15 -070010272 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10273 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010274 } finally {
10275 Binder.restoreCallingIdentity(identity);
10276 }
10277 }
10278
10279 /**
10280 * Register RCS provisioning callback.
10281 */
10282 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010283 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010284 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010285 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010286 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010287 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10288 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010289
10290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10291 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10292 }
10293 if (!isImsAvailableOnDevice()) {
10294 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10295 "IMS not available on device.");
10296 }
10297
10298 final long identity = Binder.clearCallingIdentity();
10299 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010300 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010301 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010302 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10303 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010304 }
Hui Wang761a6682020-10-31 05:12:53 +000010305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
10308 }
10309
10310 /**
10311 * Unregister RCS provisioning callback.
10312 */
10313 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010314 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010315 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010316 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010317 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010318 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10319 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010320
10321 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10322 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10323 }
10324 if (!isImsAvailableOnDevice()) {
10325 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10326 "IMS not available on device.");
10327 }
10328
10329 final long identity = Binder.clearCallingIdentity();
10330 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010331 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010332 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010333 } finally {
10334 Binder.restoreCallingIdentity(identity);
10335 }
10336 }
10337
10338 /**
10339 * trigger RCS reconfiguration.
10340 */
10341 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010342 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10343 "triggerRcsReconfiguration",
10344 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010345
10346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10348 }
10349 if (!isImsAvailableOnDevice()) {
10350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10351 "IMS not available on device.");
10352 }
10353
10354 final long identity = Binder.clearCallingIdentity();
10355 try {
10356 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10357 } finally {
10358 Binder.restoreCallingIdentity(identity);
10359 }
10360 }
10361
10362 /**
10363 * Provide the client configuration parameters of the RCS application.
10364 */
10365 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010366 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10367 "setRcsClientConfiguration",
10368 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010369
10370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10371 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10372 }
10373 if (!isImsAvailableOnDevice()) {
10374 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10375 "IMS not available on device.");
10376 }
10377
10378 final long identity = Binder.clearCallingIdentity();
10379
10380 try {
10381 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10382 if (configBinder == null) {
10383 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010384 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10385 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010386 } else {
10387 configBinder.setRcsClientConfiguration(rcc);
10388 }
joonhunshin3e154242021-09-17 06:33:39 +000010389
10390 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10391 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010392 } catch (RemoteException e) {
10393 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010394 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10395 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010396 } finally {
10397 Binder.restoreCallingIdentity(identity);
10398 }
10399 }
10400
10401 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010402 * Enables or disables the test mode for RCS VoLTE single registration.
10403 */
10404 @Override
10405 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10406 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10407 "setRcsSingleRegistrationTestModeEnabled");
10408
10409 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10410 }
10411
10412 /**
10413 * Gets the test mode for RCS VoLTE single registration.
10414 */
10415 @Override
10416 public boolean getRcsSingleRegistrationTestModeEnabled() {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "getRcsSingleRegistrationTestModeEnabled");
10419
10420 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10421 }
10422
10423 /**
Hui Wang761a6682020-10-31 05:12:53 +000010424 * Overrides the config of RCS VoLTE single registration enabled for the device.
10425 */
10426 @Override
10427 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "setDeviceSingleRegistrationEnabledOverride");
10430 enforceModifyPermission();
10431
10432 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10433 : Boolean.parseBoolean(enabledStr);
10434 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010435 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010436 }
10437
10438 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010439 * Sends a device to device communication message. Only usable via shell.
10440 * @param message message to send.
10441 * @param value message value.
10442 */
10443 @Override
10444 public void sendDeviceToDeviceMessage(int message, int value) {
10445 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010446 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010447 enforceModifyPermission();
10448
10449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 TelephonyConnectionService service =
10452 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10453 if (service == null) {
10454 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10455 return;
10456 }
10457 service.sendTestDeviceToDeviceMessage(message, value);
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
Tyler Gunnbabbda02021-02-10 11:05:02 -080010463 /**
10464 * Sets the specified device to device transport active.
10465 * @param transport The transport to set active.
10466 */
10467 @Override
10468 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10469 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10470 "setActiveDeviceToDeviceTransport");
10471 enforceModifyPermission();
10472
10473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 TelephonyConnectionService service =
10476 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10477 if (service == null) {
10478 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10479 return;
10480 }
10481 service.setActiveDeviceToDeviceTransport(transport);
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
Tyler Gunn92479152021-01-20 16:30:10 -080010486
Tyler Gunnd4339262021-05-03 14:46:49 -070010487 @Override
10488 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10490 "setDeviceToDeviceForceEnabled");
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 Arrays.stream(PhoneFactory.getPhones()).forEach(
10495 p -> {
10496 Phone thePhone = p.getImsPhone();
10497 if (thePhone != null && thePhone instanceof ImsPhone) {
10498 ImsPhone imsPhone = (ImsPhone) thePhone;
10499 CallTracker tracker = imsPhone.getCallTracker();
10500 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10501 ImsPhoneCallTracker imsPhoneCallTracker =
10502 (ImsPhoneCallTracker) tracker;
10503 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10504 }
10505 }
10506 }
10507 );
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
Tyler Gunn92479152021-01-20 16:30:10 -080010513 /**
Hui Wang761a6682020-10-31 05:12:53 +000010514 * Gets the config of RCS VoLTE single registration enabled for the device.
10515 */
10516 @Override
10517 public boolean getDeviceSingleRegistrationEnabled() {
10518 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10519 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10520 }
10521
10522 /**
10523 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10524 */
10525 @Override
10526 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10527 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10528 "setCarrierSingleRegistrationEnabledOverride");
10529 enforceModifyPermission();
10530
10531 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10532 : Boolean.parseBoolean(enabledStr);
10533 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10534 subId, enabled);
10535 }
10536
10537 /**
10538 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10539 */
10540 @Override
10541 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10542 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10543 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10544 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010545
10546 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010547 * Overrides the ims feature validation result
10548 */
10549 @Override
10550 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10552 "setImsFeatureValidationOverride");
10553
10554 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10555 : Boolean.parseBoolean(enabledStr);
10556 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10557 subId, enabled);
10558 }
10559
10560 /**
10561 * Gets the ims feature validation override value
10562 */
10563 @Override
10564 public boolean getImsFeatureValidationOverride(int subId) {
10565 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10566 "getImsFeatureValidationOverride");
10567 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10568 }
10569
10570 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010571 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10572 * their mobile plan.
10573 */
10574 @Override
10575 public String getMobileProvisioningUrl() {
10576 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10577 final long identity = Binder.clearCallingIdentity();
10578 try {
10579 return getDefaultPhone().getMobileProvisioningUrl();
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010584
James.cf Linbcdf8b32021-01-14 16:44:13 +080010585 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010586 * Get the EAB contact from the EAB database.
10587 */
10588 @Override
10589 public String getContactFromEab(String contact) {
10590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10591 enforceModifyPermission();
10592 final long identity = Binder.clearCallingIdentity();
10593 try {
10594 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 /**
Calvin Pana1434322021-07-01 19:27:01 +080010601 * Get the EAB capability from the EAB database.
10602 */
10603 @Override
10604 public String getCapabilityFromEab(String contact) {
10605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10606 enforceModifyPermission();
10607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
10614
10615 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010616 * Remove the EAB contacts from the EAB database.
10617 */
10618 @Override
10619 public int removeContactFromEab(int subId, String contacts) {
10620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10621 enforceModifyPermission();
10622 final long identity = Binder.clearCallingIdentity();
10623 try {
10624 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10625 } finally {
10626 Binder.restoreCallingIdentity(identity);
10627 }
10628 }
10629
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010630 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010631 public boolean getDeviceUceEnabled() {
10632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 return mApp.getDeviceUceEnabled();
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
10641 @Override
10642 public void setDeviceUceEnabled(boolean isEnabled) {
10643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 mApp.setDeviceUceEnabled(isEnabled);
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
10651
Brad Ebinger14d467f2021-02-12 06:18:28 +000010652 /**
10653 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10654 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10655 */
10656 // Used for SHELL command only right now.
10657 @Override
10658 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10659 List<String> featureTags) {
10660 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10661 "addUceRegistrationOverrideShell");
10662 final long identity = Binder.clearCallingIdentity();
10663 try {
10664 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10665 new ArraySet<>(featureTags));
10666 } catch (ImsException e) {
10667 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10668 } finally {
10669 Binder.restoreCallingIdentity(identity);
10670 }
10671 }
10672
10673 /**
10674 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10675 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10676 */
10677 // Used for SHELL command only right now.
10678 @Override
10679 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10680 List<String> featureTags) {
10681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10682 "removeUceRegistrationOverrideShell");
10683 final long identity = Binder.clearCallingIdentity();
10684 try {
10685 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10686 new ArraySet<>(featureTags));
10687 } catch (ImsException e) {
10688 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
10694 /**
10695 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10696 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10697 */
10698 // Used for SHELL command only right now.
10699 @Override
10700 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10702 "clearUceRegistrationOverrideShell");
10703 final long identity = Binder.clearCallingIdentity();
10704 try {
10705 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10706 } catch (ImsException e) {
10707 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
10713 /**
10714 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10715 */
10716 // Used for SHELL command only right now.
10717 @Override
10718 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10719 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10720 "getLatestRcsContactUceCapabilityShell");
10721 final long identity = Binder.clearCallingIdentity();
10722 try {
10723 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10724 } catch (ImsException e) {
10725 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10726 } finally {
10727 Binder.restoreCallingIdentity(identity);
10728 }
10729 }
10730
10731 /**
10732 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10733 * device does not have an active PUBLISH.
10734 */
10735 // Used for SHELL command only right now.
10736 @Override
10737 public String getLastUcePidfXmlShell(int subId) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10739 final long identity = Binder.clearCallingIdentity();
10740 try {
10741 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10742 } catch (ImsException e) {
10743 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
10748
James.cf Line8713a42021-04-29 16:04:26 +080010749 /**
10750 * Remove UCE requests cannot be sent to the network status.
10751 */
10752 // Used for SHELL command only right now.
10753 @Override
10754 public boolean removeUceRequestDisallowedStatus(int subId) {
10755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10756 final long identity = Binder.clearCallingIdentity();
10757 try {
10758 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10759 } catch (ImsException e) {
10760 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
James.cf Lin18bb9002021-05-25 01:37:38 +080010766 /**
10767 * Remove UCE requests cannot be sent to the network status.
10768 */
10769 // Used for SHELL command only.
10770 @Override
10771 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10773 final long identity = Binder.clearCallingIdentity();
10774 try {
10775 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10776 } catch (ImsException e) {
10777 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010782
James.cf Lin4b784aa2021-01-31 03:25:15 +080010783 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010784 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10785 String callingPackage) {
10786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10787 mApp, subId, "setSignalStrengthUpdateRequest");
10788
10789 final int callingUid = Binder.getCallingUid();
10790 // Verify that tha callingPackage belongs to the calling UID
10791 mApp.getSystemService(AppOpsManager.class)
10792 .checkPackage(callingUid, callingPackage);
10793
10794 validateSignalStrengthUpdateRequest(request, callingUid);
10795
10796 final long identity = Binder.clearCallingIdentity();
10797 try {
10798 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10799 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10800
10801 if (result instanceof IllegalStateException) {
10802 throw (IllegalStateException) result;
10803 }
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 @Override
10810 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10811 String callingPackage) {
10812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10813 mApp, subId, "clearSignalStrengthUpdateRequest");
10814
10815 final int callingUid = Binder.getCallingUid();
10816 // Verify that tha callingPackage belongs to the calling UID
10817 mApp.getSystemService(AppOpsManager.class)
10818 .checkPackage(callingUid, callingPackage);
10819
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10823 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10824
10825 if (result instanceof IllegalStateException) {
10826 throw (IllegalStateException) result;
10827 }
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10834 int callingUid) {
10835 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10836 // phone/system process do not have further restriction on request
10837 return;
10838 }
10839
10840 // Applications has restrictions on how to use the request:
10841 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10842 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10843 // This is not system caller which has been checked above
10844 throw new IllegalArgumentException(
10845 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10846 }
10847
10848 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10849 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10850 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10851 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10852 || info.isEnabled()) {
10853 throw new IllegalArgumentException(
10854 "Only system can set hide fields in SignalThresholdInfo");
10855 }
10856
10857 // Thresholds length for each RAN need in range. This has been validated in
10858 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10859 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10860 final int[] thresholds = info.getThresholds();
10861 Objects.requireNonNull(thresholds);
10862 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10863 || thresholds.length
10864 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10865 throw new IllegalArgumentException(
10866 "thresholds length is out of range: " + thresholds.length);
10867 }
10868 }
10869 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010870
10871 /**
10872 * Gets the current phone capability.
10873 *
10874 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10875 * @return the PhoneCapability which describes the data connection capability of modem.
10876 * It's used to evaluate possible phone config change, for example from single
10877 * SIM device to multi-SIM device.
10878 */
10879 @Override
10880 public PhoneCapability getPhoneCapability() {
10881 enforceReadPrivilegedPermission("getPhoneCapability");
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
Michele Berionne5e411512020-11-13 02:36:59 +000010889
10890 /**
10891 * Prepare TelephonyManager for an unattended reboot. The reboot is
10892 * required to be done shortly after the API is invoked.
10893 */
10894 @Override
10895 @TelephonyManager.PrepareUnattendedRebootResult
10896 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010898 enforceRebootPermission();
10899
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010902 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010907
10908 /**
10909 * Request to get the current slicing configuration including URSP rules and
10910 * NSSAIs (configured, allowed and rejected).
10911 *
10912 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10913 */
10914 @Override
10915 public void getSlicingConfig(ResultReceiver callback) {
10916 enforceReadPrivilegedPermission("getSlicingConfig");
10917
10918 final long identity = Binder.clearCallingIdentity();
10919 try {
10920 Phone phone = getDefaultPhone();
10921 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010926}